filter.rs
Overview
This file defines the TransactionFilter struct, which serves as a filter input object for querying transaction data. It is designed to be used in GraphQL queries to specify filtering criteria based on various transaction fields such as transaction ID, account address, block ID, and status codes. The filter supports nested logical "or" conditions through recursive composition.
Struct: TransactionFilter
Purpose
TransactionFilter encapsulates optional filtering criteria for transaction-related queries, allowing fine-grained selection of transactions that match specific attributes or sets of attributes.
Derivations and Traits
InputObject: EnablesTransactionFilterto be used as an input type in GraphQL queries via theasync_graphqlcrate.Debug: Implements the Debug trait to allow formatting the struct for debugging purposes.
Serialize: Allows the struct to be serialized, typically for JSON or other serialization formats.
Implements the
WhereOptrait (from crate::schema::graphql_shared::filter::WhereOp), which likely provides functionality to convert filter criteria into query operations or predicates.
Field Descriptions
Field Name | Type | Description |
|---|---|---|
|
| Optional filter on the transaction's unique identifier. |
|
| Optional filter on the account address associated with the transaction. |
|
| Optional filter on the block identifier containing the transaction. |
|
| Optional filter on the transaction's ending status code. |
|
| Optional filter on the transaction's original status code. |
|
| Optional nested |
Usage Example
use crate::filter::TransactionFilter;
use crate::schema::graphql_shared::filter::{OptStringFilter, OptIntFilter};
// Filter for transactions with a specific account address or a certain end status
let filter = TransactionFilter {
id: OptStringFilter::default(),
account_addr: OptStringFilter::from_exact("0xabc123"),
block_id: OptStringFilter::default(),
end_status: OptIntFilter::from_eq(1),
orig_status: OptIntFilter::default(),
or: Some(Box::new(TransactionFilter {
id: OptStringFilter::default(),
account_addr: OptStringFilter::default(),
block_id: OptStringFilter::default(),
end_status: OptIntFilter::from_eq(2),
orig_status: OptIntFilter::default(),
or: None,
})),
};
This example constructs a filter targeting transactions either with a specific account address and an end status of 1, or an end status of 2.
Implementation Details
The use of
OptStringFilterandOptIntFilterindicates that filtering on string and integer fields supports a range of operations (e.g., equals, contains) rather than simple equality checks. These types are imported from the sharedfiltermodule and likely provide methods and traits to specify these operations.The recursive
orfield allows the construction of complex logical OR chains by nesting multipleTransactionFilterinstances. This design supports queries that require alternative filtering criteria.Implementing the
WhereOptrait suggests thatTransactionFiltercan be converted into a database query predicate or a similar construct used internally for filtering data.
Interactions with Other Components
OptStringFilterandOptIntFilter: These filter types are imported fromcrate::schema::graphql_shared::filterand define the possible filtering operations for string and integer fields, respectively.WhereOpTrait: By implementing this trait,TransactionFilterintegrates with the system's query-building or filtering mechanism, allowing it to be transformed into executable query operations.GraphQL Layer: The
InputObjectderive macro and the#[graphql(rename_fields = "snake_case")]attribute make this struct compatible as an input type in GraphQL schemas, enabling clients to specify transaction filters in GraphQL requests.
Visual Diagram
classDiagram
class TransactionFilter {
-id: OptStringFilter
-account_addr: OptStringFilter
-block_id: OptStringFilter
-end_status: OptIntFilter
-orig_status: OptIntFilter
-or: Option<Box<TransactionFilter>>
}
TransactionFilter ..> OptStringFilter : uses
TransactionFilter ..> OptIntFilter : uses
TransactionFilter --|> WhereOp