transaction.rs

Overview

This file defines the data structures and methods to query and manage blockchain transaction records stored in a SQLite database. It provides functionality to retrieve transactions based on various filters such as account address, pagination parameters, transaction status, balance changes, and blockchain-specific attributes. The file primarily interacts with the database layer using SQL queries built dynamically with the sqlx crate and supports asynchronous operations.

The core components include:

Structs and Methods

AccountTransactionsQueryArgs

A struct encapsulating filters and pagination arguments for querying account transactions.

pub struct AccountTransactionsQueryArgs {
    allow_latest_inconsistent_data: Option<bool>,
    block_seq_no_range: Option<BlockchainMasterSeqNoFilter>,
    aborted: Option<bool>,
    min_balance_delta: Option<String>,
    max_balance_delta: Option<String>,
    pub pagination: PaginationArgs,
}

Fields

Methods

Transaction

Represents a blockchain transaction with detailed fields describing its execution, status, and metadata.

#[derive(Clone, FromRow, Debug)]
pub struct Transaction {
    pub rowid: i64,
    pub id: String,
    pub aborted: bool,
    pub account_addr: String,
    pub action_success: bool,
    pub action_valid: bool,
    pub action_no_funds: bool,
    pub action_status_change: u8,
    pub action_result_code: i32,
    pub action_tot_actions: i16,
    pub action_spec_actions: i16,
    pub action_skipped_actions: i16,
    pub action_msgs_created: i16,
    pub action_list_hash: String,
    pub action_tot_msg_size_cells: f64,
    pub action_tot_msg_size_bits: f64,
    pub balance_delta: String,
    pub block_id: String,
    pub boc: Vec<u8>,
    pub chain_order: String,
    pub credit: Option<String>,
    pub credit_first: bool,
    pub compute_account_activated: bool,
    pub compute_exit_code: i32,
    pub compute_gas_fees: String,
    pub compute_gas_used: f64,
    pub compute_gas_limit: f64,
    pub compute_mode: i8,
    pub compute_msg_state_used: bool,
    pub compute_success: bool,
    pub compute_type: u8,
    pub compute_vm_final_state_hash: String,
    pub compute_vm_init_state_hash: String,
    pub compute_vm_steps: u64,
    pub destroyed: bool,
    pub end_status: u8,
    pub in_msg: String,
    pub lt: String,
    pub new_hash: String,
    pub now: u64,
    pub old_hash: String,
    pub orig_status: u8,
    pub out_msgs: String,
    pub outmsg_cnt: u16,
    pub prev_trans_hash: String,
    pub prev_trans_lt: String,
    pub proof: Option<Vec<u8>>,
    pub status: u8,
    pub storage_fees_collected: Option<String>,
    pub storage_status_change: Option<u8>,
    pub total_fees: String,
    pub tr_type: u8,
    pub workchain_id: i32,
}

Fields Description

Each field corresponds to a column in the transactions database table and captures aspects such as:

Methods

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

Fetches a list of transactions matching a raw SQL filter and order clause, optionally limited by count.

blockchain_transactions
pub async fn blockchain_transactions(
    pool: &SqlitePool,
    args: &BlockchainTransactionsQueryArgs,
) -> anyhow::Result<Vec<Transaction>>

Fetches blockchain transactions matching complex filters encapsulated in BlockchainTransactionsQueryArgs, supporting pagination.

account_transactions
pub async fn account_transactions(
    pool: &SqlitePool,
    account: String,
    args: &AccountTransactionsQueryArgs,
) -> anyhow::Result<Vec<Self>>

Fetches transactions related to a specific account address, filtered by the provided AccountTransactionsQueryArgs.

by_in_message
pub async fn by_in_message(
    pool: &SqlitePool,
    msg_id: &str,
    _fields: Option<Vec<String>>,
) -> anyhow::Result<Option<Transaction>>

Fetches a single transaction identified by its input message ID.

Implementation Details and Algorithms

Interactions with Other System Components

Mermaid Diagram: Class Diagram for Transaction and QueryArgs

classDiagram
class AccountTransactionsQueryArgs {
-allow_latest_inconsistent_data: Option<bool>
-block_seq_no_range: Option<BlockchainMasterSeqNoFilter>
-aborted: Option<bool>
-min_balance_delta: Option<String>
-max_balance_delta: Option<String>
+pagination: PaginationArgs
+new()
}
class Transaction {
+rowid: i64
+id: String
+aborted: bool
+account_addr: String
+action_success: bool
+action_valid: bool
+action_no_funds: bool
+action_status_change: u8
+action_result_code: i32
+action_tot_actions: i16
+action_spec_actions: i16
+action_skipped_actions: i16
+action_msgs_created: i16
+action_list_hash: String
+action_tot_msg_size_cells: f64
+action_tot_msg_size_bits: f64
+balance_delta: String
+block_id: String
+boc: Vec<u8>
+chain_order: String
+credit: Option<String>
+credit_first: bool
+compute_account_activated: bool
+compute_exit_code: i32
+compute_gas_fees: String
+compute_gas_used: f64
+compute_gas_limit: f64
+compute_mode: i8
+compute_msg_state_used: bool
+compute_success: bool
+compute_type: u8
+compute_vm_final_state_hash: String
+compute_vm_init_state_hash: String
+compute_vm_steps: u64
+destroyed: bool
+end_status: u8
+in_msg: String
+lt: String
+new_hash: String
+now: u64
+old_hash: String
+orig_status: u8
+out_msgs: String
+outmsg_cnt: u16
+prev_trans_hash: String
+prev_trans_lt: String
+proof: Option<Vec<u8>>
+status: u8
+storage_fees_collected: Option<String>
+storage_status_change: Option<u8>
+total_fees: String
+tr_type: u8
+workchain_id: i32
+list()
+blockchain_transactions()
+account_transactions()
+by_in_message()
}

This diagram shows the Transaction struct with its properties and methods, as well as the AccountTransactionsQueryArgs struct with its fields and constructor method. The diagram emphasizes the data-centric nature of these classes and their primary asynchronous query methods.