blocks.rs
Overview
This file defines core types and structures used for querying and paginating blockchain block data within the system. It provides query argument structures, type aliases, and GraphQL connection and edge types that facilitate efficient and paginated retrieval of blockchain blocks. The module leverages traits from the async_graphql crate to implement the GraphQL connection pattern, enabling standardized pagination support for blockchain block queries.
Detailed Explanation of Components
Type Alias
pub(crate) type BlockchainBlock = Block;
Purpose: Creates an alias
BlockchainBlockfor theBlocktype defined elsewhere in the project (ingraphql_ext::Block). This alias improves readability and semantic clarity when dealing with blockchain-specific blocks.Usage Example:
let block: BlockchainBlock = get_block_by_seq_no(seq_no);
Struct: BlockchainBlocksQueryArgs
#[derive(Clone)]
pub struct BlockchainBlocksQueryArgs {
pub block_seq_no_range: Option<BlockchainMasterSeqNoFilter>,
pub min_tr_count: Option<i32>,
pub max_tr_count: Option<i32>,
pub pagination: PaginationArgs,
}
Purpose: Encapsulates the argument set for querying blockchain blocks.
Fields:
block_seq_no_range: Option<BlockchainMasterSeqNoFilter>
Filters blocks by a range of blockchain master sequence numbers.
SeeBlockchainMasterSeqNoFilterfor filtering options.min_tr_count: Option<i32>
Minimum transaction count filter: blocks must have at least this number of transactions.max_tr_count: Option<i32>
Maximum transaction count filter: blocks must have no more than this number of transactions.pagination: PaginationArgs
Pagination parameters (e.g., first, after, last, before) to control result sets.
SeePaginationArgsfor details on pagination options.
Usage Example:
let query_args = BlockchainBlocksQueryArgs { block_seq_no_range: Some(BlockchainMasterSeqNoFilter::new(1000, 2000)), min_tr_count: Some(5), max_tr_count: None, pagination: PaginationArgs { first: Some(10), after: None, last: None, before: None }, };
Struct: BlockchainBlocksEdge
pub(crate) struct BlockchainBlocksEdge;
Purpose: Represents an edge in a GraphQL connection for blockchain blocks, conforming to the GraphQL Relay pagination specification.
Trait Implementation:
ImplementsEdgeNameTypefromasync_graphql, which requires defining a GraphQL type name.Method:
fn type_name<T: OutputType>() -> String { "BlockchainBlocksEdge".to_string() }Usage: Used internally by the GraphQL server when constructing paginated responses of blockchain blocks.
Struct: BlockchainBlocksConnection
pub(crate) struct BlockchainBlocksConnection;
Purpose: Represents a connection object for paginated blockchain blocks in GraphQL.
Trait Implementation:
ImplementsConnectionNameTypefromasync_graphql, which defines the GraphQL connection type name.Method:
fn type_name<T: OutputType>() -> String { "BlockchainBlocksConnection".to_string() }Usage: Used to wrap paginated lists of blockchain blocks according to GraphQL Relay standards.
Implementation Details and Algorithms
The file uses traits
EdgeNameTypeandConnectionNameTypefrom theasync_graphqlcrate to define type names for edges and connections. This is essential for the Relay-compliant GraphQL schema, enabling clients to perform cursor-based pagination efficiently.No complex algorithms are present; the file primarily defines data structures and type aliases to integrate blockchain block data querying with GraphQL pagination.
Interaction with Other System Parts
BlockType: The aliasBlockchainBlockrefers to theBlocktype defined ingraphql_ext::Block, representing the blockchain block entity used throughout the system.BlockchainMasterSeqNoFilter: Used for filtering block sequence numbers within query arguments, imported from theaccountmodule.PaginationArgs: Provides pagination parameters; imported from the GraphQL query schema module.The structures defined here are used in GraphQL resolver implementations to fetch, filter, and paginate blockchain block data as part of the query schema.
Mermaid Class Diagram
classDiagram
class BlockchainBlocksQueryArgs {
+block_seq_no_range: Option<BlockchainMasterSeqNoFilter>
+min_tr_count: Option<i32>
+max_tr_count: Option<i32>
+pagination: PaginationArgs
}
class BlockchainBlocksEdge {
+type_name() : String
}
class BlockchainBlocksConnection {
+type_name() : String
}
BlockchainBlocksEdge ..|> EdgeNameType
BlockchainBlocksConnection ..|> ConnectionNameType
This diagram illustrates the main data structures and their relationships, highlighting the inheritance of traits for GraphQL connection types and the fields used for querying blockchain blocks.