transaction.rs

Overview

This file defines the data structures and serialization logic for representing blockchain transactions at varying levels of detail. It provides both a rich archival model (ArchTransaction) with nested phases of a transaction and a flattened, simplified structure (FlatTransaction) suitable for database storage or external consumption.

The file consolidates transaction phases such as credit, storage, compute, action, and bounce into serializable structs. It also implements conversion logic to transform a detailed transaction serialization set into the archival form and further into a flat representation.

The primary goal of this module is to facilitate the structured extraction, transformation, and storage of transaction data from low-level protocol representations (TransactionSerializationSet and TransactionDescr) into application-level models.


Data Structures

TransactionCredit

Represents the credit phase of a transaction.

TransactionStorage

Represents the storage phase of a transaction.

TransactionCompute

Represents the compute phase of a transaction.

TransactionAction

Represents the action phase of a transaction.

TransactionBounce

Represents the bounce phase of a transaction.

ArchTransaction (Public)

The archival representation of a transaction, containing detailed nested phases.

FlatTransaction (Public)

A flattened version of ArchTransaction, used for easier serialization and database storage.


Implementations and Functions

Conversion: From<ArchTransaction> for FlatTransaction

Transforms a nested ArchTransaction into a flattened FlatTransaction.

Conversion: From<TransactionSerializationSet> for ArchTransaction

Transforms a low-level serialized transaction (TransactionSerializationSet) into the archival model (ArchTransaction).

Helper Functions for Phase Serialization

Each helper function converts optional protocol-specific phase data into corresponding transaction phase structs.

These functions extract relevant fields, convert numeric types to strings where appropriate, and map enum variants to numeric codes for serialization.


Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Visual Diagram: Class Diagram of Transaction Data Structures and Conversions

classDiagram
class TransactionCredit {
+credit: Option<String>
+due_fees_collected: Option<String>
}
class TransactionStorage {
+storage_fees_collected: Option<String>
+storage_fees_due: Option<String>
+status_change: Option<u8>
}
class TransactionCompute {
+success: Option<bool>
+msg_state_used: Option<bool>
+account_activated: Option<bool>
+gas_credit: Option<u32>
+gas_fees: Option<String>
+gas_used: Option<f64>
+gas_limit: Option<f64>
+mode: Option<i8>
+exit_arg: Option<i32>
+exit_code: Option<i32>
+vm_steps: Option<u32>
+vm_init_state_hash: Option<String>
+vm_final_state_hash: Option<String>
+compute_type: u8
+skipped_reason: Option<u8>
}
class TransactionAction {
+success: Option<bool>
+valid: Option<bool>
+no_funds: Option<bool>
+status_change: Option<u8>
+result_arg: Option<i32>
+result_code: Option<i32>
+tot_actions: Option<i16>
+spec_actions: Option<i16>
+skipped_actions: Option<i16>
+msgs_created: Option<i16>
+action_list_hash: Option<String>
+tot_msg_size_cells: Option<f64>
+tot_msg_size_bits: Option<f64>
+total_action_fees: Option<String>
+total_fwd_fees: Option<String>
}
class TransactionBounce {
+bounce_type: Option<i32>
+fwd_fees: Option<String>
+msg_fees: Option<String>
+msg_size_bits: Option<f64>
+msg_size_cells: Option<f64>
+req_fwd_fees: Option<String>
}
class ArchTransaction {
-id: String
-block_id: String
-boc: Vec<u8>
-bounce: Option<TransactionBounce>
-status: u8
-credit: Option<TransactionCredit>
-storage: Option<TransactionStorage>
-compute: Option<TransactionCompute>
-action: Option<TransactionAction>
-credit_first: bool
-ext_in_msg_fee: Option<String>
-aborted: bool
-destroyed: bool
-tr_type: u8
-lt: String
-prev_trans_hash: String
-prev_trans_lt: String
-proof: Option<Vec<u8>>
-now: u32
-outmsg_cnt: u16
-orig_status: u8
-end_status: u8
-in_msg: String
-out_msgs: Vec<String>
-account_addr: String
-workchain_id: i32
-total_fees: String
-balance_delta: String
-old_hash: String
-new_hash: String
-chain_order: String
}
class FlatTransaction {
+id: String
+block_id: String
+boc: Vec<u8>
+status: u8
+credit: Option<String>
+storage_fees_collected: Option<String>
+storage_status_change: Option<u8>
+compute_success: Option<bool>
+compute_msg_state_used: Option<bool>
+compute_account_activated: Option<bool>
+compute_gas_fees: Option<String>
+compute_gas_used: Option<f64>
+compute_gas_limit: Option<f64>
+compute_mode: Option<i8>
+compute_exit_code: Option<i32>
+compute_skipped_reason: Option<u8>
+compute_vm_steps: Option<u32>
+compute_vm_init_state_hash: Option<String>
+compute_vm_final_state_hash: Option<String>
+compute_type: u8
+action_success: Option<bool>
+action_valid: Option<bool>
+action_no_funds: Option<bool>
+action_status_change: Option<u8>
+action_result_code: Option<i32>
+action_tot_actions: Option<i16>
+action_spec_actions: Option<i16>
+action_skipped_actions: Option<i16>
+action_msgs_created: Option<i16>
+action_list_hash: Option<String>
+action_tot_msg_size_cells: Option<f64>
+action_tot_msg_size_bits: Option<f64>
+credit_first: bool
+aborted: bool
+destroyed: bool
+tr_type: u8
+lt: String
+prev_trans_hash: String
+prev_trans_lt: String
+now: u32
+outmsg_cnt: u16
+orig_status: u8
+end_status: u8
+in_msg: String
+out_msgs: String
+account_addr: String
+workchain_id: i32
+total_fees: String
+balance_delta: String
+old_hash: String
+new_hash: String
+chain_order: String
}
ArchTransaction --> TransactionCredit
ArchTransaction --> TransactionStorage
ArchTransaction --> TransactionCompute
ArchTransaction --> TransactionAction
ArchTransaction --> TransactionBounce
FlatTransaction ..|> ArchTransaction : "from ArchTransaction"

Usage Examples

Creating ArchTransaction from Raw Serialization Set

use crate::transaction::ArchTransaction;
use crate::serialization::TransactionSerializationSet;

// Assume trx_set is a deserialized TransactionSerializationSet from blockchain data
let trx_set: TransactionSerializationSet = get_trx_serialization_set();
let arch_trx: ArchTransaction = trx_set.into();

Flattening ArchTransaction for Storage or API

use crate::transaction::{ArchTransaction, FlatTransaction};

let arch_trx: ArchTransaction = ...; // obtained from conversion above
let flat_trx: FlatTransaction = arch_trx.into();

// flat_trx can now be serialized to JSON or stored in DB

Notes on Field Semantics


This file plays a crucial role in bridging the gap between low-level blockchain transaction data and application-level transaction models tailored for persistence, querying, and analysis. It encapsulates domain-specific logic for interpreting transaction phases, computing fees, and managing message data.