rest_api_routes.rs

Overview

This source file defines the REST API routing and corresponding handlers for key endpoints related to account data retrieval, message processing, and service readiness checks. It leverages asynchronous handlers within the Salvo web framework to manage incoming HTTP requests, interact with internal application state (AppState), and produce appropriate HTTP responses. The file primarily serves as the interface layer between external clients and the internal business logic encapsulated by the message router and blockchain data fetcher.


Public Functions and Handlers

rest_api_router

pub fn rest_api_router(app_state: Arc<AppState>) -> Router

route_message Handler

#[handler]
async fn route_message(req: &mut Request, depot: &mut Depot, res: &mut Response)

boc_by_address Handler

#[handler]
async fn boc_by_address(req: &mut Request, depot: &mut Depot, res: &mut Response)

readiness Handler

#[handler]
async fn readiness(_req: &mut Request, depot: &mut Depot, res: &mut Response)

render_error Utility Function

fn render_error(res: &mut Response, status_code: StatusCode, text: &str)

Important Implementation Details


Interaction with Other System Components

This file acts as the API layer connecting external HTTP clients to internal blockchain logic and message processing services.


Diagram: REST API Router and Handler Workflow

flowchart TD
REST_API_ROUTER["rest_api_router"]
ROUTE_MESSAGE["route_message\n(POST /v2/messages)"]
BOC_BY_ADDRESS["boc_by_address\n(GET /v2/account)"]
READINESS["readiness\n(GET /v2/readiness)"]
APP_STATE["AppState\n(shared state)"]
MESSAGE_ROUTER["message_router"]
BLOCKCHAIN_PROXY["default_bp\n(blockchain proxy)"]
PROCESS_EXT_MSG["process_ext_messages::run"]
BUILD_BOC_REQ["build_fetch_boc_request"]
REST_API_ROUTER --> ROUTE_MESSAGE
REST_API_ROUTER --> BOC_BY_ADDRESS
REST_API_ROUTER --> READINESS
ROUTE_MESSAGE --> APP_STATE
ROUTE_MESSAGE --> MESSAGE_ROUTER
ROUTE_MESSAGE --> PROCESS_EXT_MSG
BOC_BY_ADDRESS --> APP_STATE
BOC_BY_ADDRESS --> BUILD_BOC_REQ
BUILD_BOC_REQ --> BLOCKCHAIN_PROXY
READINESS --> APP_STATE