boc_by_address.rs

Overview

This file defines the BocByAddressHandler struct and its implementation as an HTTP request handler within an asynchronous web server framework. The handler processes incoming HTTP requests that query for a Bag of Cells (BOC) data structure associated with a specified blockchain address. It extracts the address parameter from the query string, invokes a backend resolver function to obtain the BOC and optional dapp identifier, and responds with a JSON payload or an error message. The handler also records metrics related to response time and HTTP status.

The file leverages generic type parameters to enable flexible integration with different message types, conversion functions, blockchain state resolvers, BOC retrieval functions, and sequence number getters. It is designed for use within the asynchronous web framework salvo and interacts closely with a shared WebServer state object.


Structs

BocByAddressHandler

pub struct BocByAddressHandler<
    TMesssage,
    TMsgConverter,
    TBPResolver,
    TBocByAddrGetter,
    TSeqnoGetter,
>(PhantomData<TMesssage>, PhantomData<TMsgConverter>, PhantomData<TBPResolver>, PhantomData<TBocByAddrGetter>, PhantomData<TSeqnoGetter>);

Trait Implementations

Handler trait for BocByAddressHandler

#[async_trait]
impl<TMessage, TMsgConverter, TBPResolver, TBocByAddrGetter, TSeqnoGetter> Handler
    for BocByAddressHandler<TMessage, TMsgConverter, TBPResolver, TBocByAddrGetter, TSeqnoGetter>
where
    TMessage: Clone + Send + Sync + 'static + std::fmt::Debug,
    TMsgConverter: Clone + Send + Sync + 'static + Fn(tvm_block::Message, [u8; 34]) -> anyhow::Result<TMessage>,
    TBPResolver: Clone + Send + Sync + 'static + FnMut([u8; 34]) -> ResolvingResult,
    TBocByAddrGetter: Clone + Send + Sync + 'static + Fn(String) -> anyhow::Result<(String, Option<String>)>,
    TSeqnoGetter: Clone + Send + Sync + 'static + Fn() -> anyhow::Result<u32>,
{
    async fn handle(&self, req: &mut Request, depot: &mut Depot, res: &mut Response, _ctrl: &mut FlowCtrl);
}

Important Implementation Details


Interactions with Other System Components


Visual Diagram

classDiagram
class BocByAddressHandler {
+new()
+handle()
}
BocByAddressHandler ..> TMessage : generic
BocByAddressHandler ..> TMsgConverter : generic
BocByAddressHandler ..> TBPResolver : generic
BocByAddressHandler ..> TBocByAddrGetter : generic
BocByAddressHandler ..> TSeqnoGetter : generic
class WebServer {
+get_boc_by_addr()
+metrics
}
BocByAddressHandler --> WebServer : obtains from Depot
WebServer --> "1" TBocByAddrGetter : uses
WebServer --> "1" Metrics : reports to