node_db.rs

Overview

This file implements the NodeDb structure, which provides read-only access to a node database stored in an SQLite file. It primarily facilitates querying account data and extracting sets of blockchain-related entities such as accounts and wallets. The database interactions are encapsulated in safe methods that handle opening connections, executing SQL queries, and deserializing blockchain data structures into usable Rust objects.

NodeDb also implements two key traits: AccountProvider and BkSetProvider, enabling it to serve as a source for account information and a "bk set" (a set of wallet addresses derived from epochs) within the broader blockchain resolver system.

Structures and Traits

NodeDb

pub struct NodeDb {
    path: PathBuf,
}

Description

Encapsulates the path to the node database file and provides methods to open the database and query blockchain account data.

Fields

Methods

Constants and Helper Functions

Trait Implementations

BkSetProvider for NodeDb

fn get_bk_set(&self) -> Vec<UInt256> {
    self.with_connection(Self::get_bk_set).unwrap_or_default()
}

AccountProvider for NodeDb

fn get_account(&self, id: &UInt256) -> Option<Account> {
    self.with_connection(|conn| Self::get_account(conn, id))
}

Important Implementation Details and Algorithms

File Interaction with Other System Components

Visual Diagram

classDiagram
class NodeDb {
-path: PathBuf
+new()
-open_conn()
-get_account()
-get_account_ids_by_code_hash()
-get_bk_set()
-with_connection()
}
NodeDb ..|> AccountProvider
NodeDb ..|> BkSetProvider
class AccountProvider {
<<trait>>
+get_account()
}
class BkSetProvider {
<<trait>>
+get_bk_set()
}

This class diagram shows NodeDb as the central data access struct with private methods for database operations and public trait implementations for providing account and blockchain wallet set data. The diagram highlights the encapsulation of database path and internal helper functions.