Trait BlockChainClient

Source
pub trait BlockChainClient:
    Send
    + Sync
    + Clone {
    // Required methods
    fn get_latest_block_number<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_blocks<'life0, 'async_trait>(
        &'life0 self,
        start_block: u64,
        end_block: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<BlockType>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn get_contract_spec<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _contract_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<ContractSpec, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn get_blocks_for_addresses<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _addresses: &'life1 [String],
        start_block: u64,
        end_block: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<BlockType>, Error>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Defines the core interface for blockchain clients

This trait must be implemented by all blockchain-specific clients to provide standardized access to blockchain data and operations.

Required Methods§

Source

fn get_latest_block_number<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves the latest block number from the blockchain

§Returns
  • Result<u64, anyhow::Error> - The latest block number or an error
Source

fn get_blocks<'life0, 'async_trait>( &'life0 self, start_block: u64, end_block: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<Vec<BlockType>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves a range of blocks from the blockchain

§Arguments
  • start_block - The starting block number
  • end_block - Optional ending block number. If None, only fetches start_block
§Returns
  • Result<Vec<BlockType>, anyhow::Error> - Vector of blocks or an error
§Note

The implementation should handle cases where end_block is None by returning only the start_block data.

Provided Methods§

Source

fn get_contract_spec<'life0, 'life1, 'async_trait>( &'life0 self, _contract_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<ContractSpec, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves the contract spec for a given contract ID

§Arguments
  • contract_id - The ID of the contract to retrieve the spec for
§Returns
  • Result<ContractSpec, anyhow::Error> - The contract spec or an error
Source

fn get_blocks_for_addresses<'life0, 'life1, 'async_trait>( &'life0 self, _addresses: &'life1 [String], start_block: u64, end_block: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<Vec<BlockType>, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieves blocks containing only transactions relevant to the specified addresses

This is an optimized method for chains that support address-based querying (like Solana). For chains that don’t support this optimization, the default implementation falls back to get_blocks which fetches all transactions.

§Arguments
  • addresses - The addresses to filter transactions by (e.g., program IDs for Solana)
  • start_block - The starting block number
  • end_block - Optional ending block number
§Returns
  • Result<Vec<BlockType>, anyhow::Error> - Vector of blocks containing relevant transactions

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§