mod.rs

Overview

This file defines GraphQL schema objects and data conversion logic related to blockchain blocks within the application. It provides data structures representing blocks, their constituent parts, and associated metadata. The file facilitates the conversion between database models (db::Block) and GraphQL-friendly types used in the schema, enabling querying and manipulation of block data via GraphQL API. Key domain concepts such as block status, block references, value flows, and account transactions within blocks are modeled here.

The file also includes utility implementations for formatting large integer fields and enumerations describing block processing states. It offers asynchronous GraphQL resolvers for complex fields that require formatting or additional computation. This module interacts closely with other parts of the schema, particularly block filtering and resolution modules (filter and resolver submodules), message handling (InMsg, OutMsg), and currency formatting.


Modules and Re-exports


Type Aliases

These aliases simplify readability and maintain consistency within the GraphQL schema definitions.


Enum: BlockProcessingStatusEnum

Description

Represents the processing status of a block with four possible states:

Implementation Details

Usage Example

let status_code: Option<i64> = Some(2);
let status_enum = BlockProcessingStatusEnum::from(status_code);
// status_enum == BlockProcessingStatusEnum::Finalized

Structs and Detailed Descriptions

ExtBlkRef

GraphQL object representing an external block reference with optional fields:

Methods


BlockMasterShardHashesDescr

Represents metadata about master shard hashes:


BlockMasterShardHashes

Represents shard hash data for a master block:


BlockMaster

Represents a master block containing shard hash information:


Directives

Contains specific directives related to the block:


BlockValueFlow

Describes the flow of values (currencies/tokens) related to the block:

Methods

Each base currency field has an async method that formats it for GraphQL queries using format_big_int.


BlockAccountBlocksTransactions

Represents a transaction within an account block:

Methods

Async methods provide formatted versions of lt and total_fees fields.


BlockAccountBlocks

Represents an account block inside a block:


Block

The main GraphQL object representing a blockchain block:

Conversion Implementation

Complex Object Resolvers

Public Methods


Implementation Details and Algorithms


Interaction with Other System Components


GraphQL Schema Highlights


Visual Diagram

classDiagram
class Block {
+id: String
+hash: Option<String>
+seq_no: i64
+shard: Option<String>
+workchain_id: Option<i64>
+status: u8
+status_name: BlockProcessingStatusEnum
+gen_utime_string: String
+boc: Option<String>
+aggregated_signature: Vec<u8>
+set_in_msg_descr()
}
class ExtBlkRef {
+end_lt: Option<String>
+file_hash: Option<String>
+root_hash: Option<String>
+seq_no: Option<f64>
}
class BlockProcessingStatusEnum {
<<enumeration>>
Unknown
Proposed
Finalized
Refused
}
class BlockValueFlow {
+created: Option<String>
+exported: Option<String>
+fees_collected: Option<String>
+fees_imported: Option<String>
+from_prev_blk: Option<String>
+imported: Option<String>
+minted: Option<String>
+to_next_blk: Option<String>
}
class BlockAccountBlocks {
+account_addr: Option<String>
+new_hash: Option<String>
+old_hash: Option<String>
+tr_count: Option<i32>
}
class BlockAccountBlocksTransactions {
+lt: Option<String>
+total_fees: Option<String>
+transaction_id: Option<String>
}
class Directives {
+share_state_resource_address: Option<String>
}
Block "1" o-- "*" BlockAccountBlocks : contains
BlockAccountBlocks "1" o-- "*" BlockAccountBlocksTransactions : contains
Block "1" o-- "1" Directives : has
Block "1" o-- "1" BlockValueFlow : has
Block "1" o-- "0..1" ExtBlkRef : prev_ref, prev_alt_ref, etc.
Block --> BlockProcessingStatusEnum : status_name

Usage Examples

Conversion from Database Block

let db_block: db::Block = fetch_block_from_db();
let gql_block = Block::from(db_block);

Setting Inbound Message Descriptions

let mut block = gql_block;
let in_msgs: Vec<InBlockMessage> = fetch_inbound_messages();
block.set_in_msg_descr(in_msgs);

Querying Formatted Logical Time in GraphQL

GraphQL query example to get the formatted start_lt field with a specific format:

query {
  block(id: "block_id") {
    start_lt(format: DECIMAL)
  }
}

References to Related Topics