account.rs

Overview

This file defines the Account data structure and related asynchronous functions to manage blockchain account data stored in a SQLite database and fetched from an external blockchain client. It provides mechanisms to query accounts with pagination and filtering, retrieve a single account by its blockchain address, and convert blockchain account data into a local model suitable for persistence and further processing.

The functionality centers around interaction with a blockchain client (tvm_client) and a SQLite connection pool (sqlx::SqlitePool), enabling synchronization and querying of account states from the blockchain and local cache.

Structs and Their Details

Account

Represents a blockchain account with fields mapped to a SQL table accounts. It derives Clone and FromRow for easy cloning and database row conversion.

BlockchainAccountsQueryArgs

Encapsulates arguments used to query multiple blockchain accounts with optional filtering and pagination.

Impl Account - Methods

list

pub async fn list(
    pool: &SqlitePool,
    where_clause: String,
    order_by: String,
    limit: Option<i32>,
) -> anyhow::Result<Vec<Account>>

Fetches a list of accounts from the database with a customizable SQL WHERE clause, ordering, and limit.


by_address

pub async fn by_address(
    _pool: &SqlitePool,
    client: &Arc<ClientContext>,
    address: Option<String>,
) -> anyhow::Result<Option<Account>>

Retrieves a single account by its blockchain address by querying the blockchain client, then converts and deserializes the blockchain account data into the local Account structure.


blockchain_accounts

pub(crate) async fn blockchain_accounts(
    pool: &SqlitePool,
    args: &BlockchainAccountsQueryArgs,
) -> anyhow::Result<Vec<Account>>

Retrieves a list of accounts from the local database filtered by optional code_hash and paginated using cursor-based pagination.

Helper Functions

serialize_account_status

fn serialize_account_status(status: &AccountStatus) -> u8

Converts a blockchain AccountStatus enum into a compact u8 representation for storage in the database.

Important Implementation Details and Algorithms

Interaction with Other Parts of the Application

The file acts as a bridge between the blockchain client data and the local database representation, enabling querying and synchronization workflows.


Diagram: Structure of account.rs

classDiagram
class Account {
+rowid: i64
+id: String
+acc_type: u8
+balance: String
+balance_other: Option<Vec<u8>>
+bits: String
+boc: Option<Vec<u8>>
+cells: String
+code: Option<Vec<u8>>
+code_hash: String
+data: Option<Vec<u8>>
+data_hash: String
+dapp_id: Option<String>
+due_payment: Option<String>
+init_code_hash: String
+last_paid: u64
+last_trans_chain_order: String
+last_trans_lt: String
+last_trans_hash: String
+prev_code_hash: Option<String>
+proof: Option<Vec<u8>>
+public_cells: String
+split_depth: Option<i64>
+state_hash: Option<String>
+workchain_id: i32
+list()
+by_address()
+blockchain_accounts()
}
class BlockchainAccountsQueryArgs {
+code_hash: Option<String>
+pagination: PaginationArgs
}
Account ..> BlockchainAccountsQueryArgs : uses
Account ..> ClientContext : calls
Account ..> SqlitePool : queries

This diagram illustrates the primary struct Account with its fields and asynchronous methods, its interaction with the BlockchainAccountsQueryArgs struct for query inputs, and dependencies on ClientContext and SqlitePool for blockchain and database interactions respectively.