transactions.rs
Overview
This file defines types and structures used to query and paginate blockchain transactions within the system. It primarily focuses on GraphQL connection and edge types that facilitate efficient retrieval and navigation of transaction data, supporting filtering by specific criteria such as balance deltas and code hashes. The file integrates with the GraphQL schema and extends existing message and transaction definitions to represent blockchain-specific entities.
Types and Structures
Type Aliases
BlockchainMessage
Alias for theMessagetype from the GraphQL extensions. Represents a message entity within blockchain transactions.pub(crate) type BlockchainMessage = Message;BlockchainTransaction
Alias for theTransactiontype from the GraphQL extensions. Represents a blockchain transaction entity.pub(crate) type BlockchainTransaction = Transaction;
BlockchainTransactionsQueryArgs Struct
This struct encapsulates the arguments used to query blockchain transactions, including optional filters and pagination parameters.
#[derive(Clone)]
pub struct BlockchainTransactionsQueryArgs {
pub min_balance_delta: Option<String>,
pub max_balance_delta: Option<String>,
pub code_hash: Option<String>,
pub pagination: PaginationArgs,
}
Fields:
min_balance_delta: Option<String>
Optional filter specifying the minimum balance change (delta) for transactions to be retrieved.max_balance_delta: Option<String>
Optional filter specifying the maximum balance change (delta).code_hash: Option<String>
Optional filter on the transaction's code hash, allowing selection of transactions related to specific contract code.pagination: PaginationArgs
Provides pagination settings such as limits and cursors to control the size and position of the returned transaction list.
Usage Example:
let query_args = BlockchainTransactionsQueryArgs {
min_balance_delta: Some("1000".to_string()),
max_balance_delta: None,
code_hash: Some("abc123...".to_string()),
pagination: PaginationArgs { /* ... */ },
};
This struct is passed to query functions to retrieve filtered and paginated blockchain transactions.
BlockchainTransactionsEdge Struct
Represents an edge in the GraphQL connection pattern for blockchain transactions. Used to encapsulate a single transaction node with its cursor for pagination.
pub(crate) struct BlockchainTransactionsEdge;
Implements the
EdgeNameTypetrait fromasync_graphql::connectionto specify the GraphQL edge type name.Trait Implementation:
impl EdgeNameType for BlockchainTransactionsEdge {
fn type_name<T: OutputType>() -> String {
"BlockchainTransactionsEdge".to_string()
}
}
This associates the edge with the GraphQL type name
"BlockchainTransactionsEdge"for schema generation and query resolution.
BlockchainTransactionsConnection Struct
Represents the connection type in the GraphQL pagination pattern for blockchain transactions. It provides the container for edges and pagination info.
pub(crate) struct BlockchainTransactionsConnection;
Implements the
ConnectionNameTypetrait to define the GraphQL connection type name.Trait Implementation:
impl ConnectionNameType for BlockchainTransactionsConnection {
fn type_name<T: OutputType>() -> String {
"BlockchainTransactionsConnection".to_string()
}
}
This allows GraphQL to recognize the connection type as
"BlockchainTransactionsConnection".
Implementation Details
The file leverages the
async_graphqlcrate's connection model to implement Relay-compliant pagination patterns.The
EdgeNameTypeandConnectionNameTypetraits provide type names used during schema introspection and query execution.The use of
Option<String>for filters enables flexible querying without mandatory filter parameters.Pagination is handled by the imported
PaginationArgsstruct, which is assumed to include cursor and limit parameters, supporting forward or backward pagination.
Interactions with Other System Components
Imports
MessageandTransactiontypes from thegraphql_extmodule, extending general message and transaction concepts into blockchain-specific contexts.Uses
PaginationArgsfrom the GraphQL query module to handle pagination concerns.These types are intended to be used by GraphQL query resolvers or services that fetch and filter blockchain transaction data from underlying data stores or blockchain nodes.
The connection and edge structures integrate into the broader GraphQL schema to enable client applications to query blockchain transaction data efficiently with filters and pagination.
Visual Diagram: Structure of transactions.rs
classDiagram
class BlockchainTransactionsQueryArgs {
+min_balance_delta: Option<String>
+max_balance_delta: Option<String>
+code_hash: Option<String>
+pagination: PaginationArgs
}
class BlockchainTransactionsEdge {
<<EdgeNameType>>
+type_name()
}
class BlockchainTransactionsConnection {
<<ConnectionNameType>>
+type_name()
}
BlockchainTransactionsEdge ..|> EdgeNameType
BlockchainTransactionsConnection ..|> ConnectionNameType
This diagram illustrates the main structs defined in the file along with their roles and implemented traits. The QueryArgs struct holds query parameters, while Edge and Connection structs implement GraphQL pagination interfaces.