bm_contract_root.rs

Overview

This file provides functionality for interacting with a blockchain smart contract referred to as the Block Manager Contract Root. It primarily focuses on retrieving blockchain object codes (BOCs) and querying the owner wallet address of a Block Manager node based on a provided public key. The file leverages HTTP requests to an API server, contract ABI execution through a TVM client, and asynchronous Rust features for network communication.

Key responsibilities include:


Constants and Static Variables

BM_CONTRACT_ROOT_ADDR: &str

BM_CONTRACT_ROOT_ABI: &str

BK_API_TOKEN: LazyLock<String>


Structs

AddressResponse

#[derive(Deserialize, Debug)]
struct AddressResponse {
    boc: String,
}

WalletAddress

#[derive(Deserialize)]
struct WalletAddress {
    wallet: Option<String>,
}

Functions

build_fetch_boc_request

pub fn build_fetch_boc_request(host: SocketAddr, address: &str) -> RequestBuilder

fetch_boc

pub async fn fetch_boc(host: SocketAddr, address: &str) -> Result<String, Error>

get_bm_owner_wallet_addr

pub async fn get_bm_owner_wallet_addr(
    api_host: SocketAddr,
    wallet_pubkey: &String,
) -> anyhow::Result<Option<String>>

Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram: Structure of bm_contract_root.rs

classDiagram
class bm_contract_root {
<<module>>
+BM_CONTRACT_ROOT_ADDR: &str
+BM_CONTRACT_ROOT_ABI: &str
+BK_API_TOKEN: LazyLock<String>
+build_fetch_boc_request(host: SocketAddr, address: &str): RequestBuilder
+fetch_boc(host: SocketAddr, address: &str): Result<String, Error>
+get_bm_owner_wallet_addr(api_host: SocketAddr, wallet_pubkey: &String): anyhow::Result<Option<String>>
}
class AddressResponse {
-boc: String
}
class WalletAddress {
-wallet: Option<String>
}
bm_contract_root --> AddressResponse : uses for deserialization
bm_contract_root --> WalletAddress : uses for deserialization

This diagram illustrates the module bm_contract_root encapsulating three main public functions and two internal data structures used for JSON deserialization during blockchain API interaction and contract method invocation. The constants and static variables provide configuration and authentication support.