accounts.rs

Overview

This file defines abstractions and utilities for interacting with specific blockchain accounts related to the BlockKeeper system. It provides typed wrappers around raw Account instances, enabling convenient invocation of contract methods through statically initialized TVM contracts. These wrappers facilitate querying critical information such as epoch code hashes, proxy lists, and ownership details from deployed smart contracts.

Key features include:

This file plays a crucial role in the interaction layer between the application and deployed smart contracts managing block keeper nodes, epochs, and proxy lists.


Detailed Components

Helper Functions

get_u256(v: &Value, name: &str) -> anyhow::Result<UInt256>

get_optional_u256(v: &Value, name: &str) -> anyhow::Result<Option<UInt256>>

get_map<K, V: DeserializeOwned>(v: &Value, name: &str) -> anyhow::Result<HashMap<K, V>>


Contract Wrappers

Each contract wrapper holds an Account and provides typed methods to query contract state via run_get.

Static LazyLock TVM Contracts


Root Struct


Bk Struct


Epoch Struct


ProxyList Struct


Function: collect_bk_set

pub fn collect_bk_set<PeerId>(
    accounts: &impl AccountProvider,
    bk: &Bk,
    nodes: &mut HashMap<PeerId, (Option<SocketAddr>, HashSet<SocketAddr>)>,
) -> anyhow::Result<()>
where
    PeerId: Eq + Hash + From<UInt256>,

Important Implementation Details


Interaction with Other Components


Visual Diagram: Class Structure and Relationships

classDiagram
class Root {
+Account
+get_epoch_code_hash()
}
class Bk {
+Account
+get_proxy_list_addr()
}
class Epoch {
+Account
+get_owner_address()
}
class ProxyList {
+Account
+get_proxy_list()
}
Root o-- Account
Bk o-- Account
Epoch o-- Account
ProxyList o-- Account

This diagram illustrates the four main contract wrapper structs, each encapsulating an Account and providing specific contract query methods.


Usage Examples

// Assume `account` is an Account instance for the root contract
let root = Root(account);
let epoch_code_hash = root.get_epoch_code_hash()?;

// Assume `bk_account` is an Account instance for a BK contract
let bk = Bk(bk_account);
let proxy_list_addr = bk.get_proxy_list_addr()?;

// For an Epoch contract instance
let epoch = Epoch(epoch_account);
let owner_addr = epoch.get_owner_address()?;

// For a ProxyList contract instance
let proxy_list = ProxyList(proxy_list_account);
let (node_addr, proxies) = proxy_list.get_proxy_list()?;

// Collecting BK proxy sets
let mut nodes_map = HashMap::new();
collect_bk_set(&accounts_provider, &bk, &mut nodes_map)?;

Refer to Account Management and Contract Interaction for broader context on account handling and contract call semantics.