Indexer

Trait Indexer 

Source
pub trait Indexer {
    type Context: Send + Sync;
    type Data: Send + Sync;

    // Required methods
    fn on_connect<'a, 'life0, 'async_trait>(
        &'life0 mut self,
        endpoint: Endpoint,
        client: &'a mut Client,
    ) -> Pin<Box<dyn Future<Output = QueryResult<Self::Context>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait;
    fn on_finalized<'a, 'life0, 'async_trait>(
        &'life0 self,
        client: Client,
        ctx: &'a Self::Context,
        fbi: FinalizedBlockInfo,
    ) -> Pin<Box<dyn Future<Output = OnFinalizationResult<Self::Data>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'a: 'async_trait,
             'life0: 'async_trait;
    fn on_failure<'life0, 'async_trait>(
        &'life0 mut self,
        endpoint: Endpoint,
        successive_failures: u64,
        err: TraverseError,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A trait intended to be implemented by indexers that traverse the chain and extract information of interest to store for efficient retrieval.

The main method of this trait is on_finalized which will be called by the traverse method for each finalized block. The other two methods are meant for signalling and bookkeeping.

Note that this trait has async methods, which is why the type signatures are daunting. The intended way of implementing it is to use the async_trait macro like so

use concordium_rust_sdk::indexer::async_trait;
#[async_trait]
impl Indexer for MyIndexer {
    type Context = ();
    type Data = ();

    async fn on_connect<'a>(
        &mut self,
        endpoint: v2::Endpoint,
        client: &'a mut v2::Client,
    ) -> QueryResult<Self::Context> {
        unimplemented!("Implement me.")
    }

    async fn on_finalized<'a>(
        &self,
        client: v2::Client,
        ctx: &'a Self::Context,
        fbi: FinalizedBlockInfo,
    ) -> OnFinalizationResult<Self::Data> {
        unimplemented!("Implement me.")
    }

    async fn on_failure(
        &mut self,
        ep: v2::Endpoint,
        successive_failures: u64,
        err: TraverseError,
    ) -> bool {
        unimplemented!("Implement me.")
    }
}

Required Associated Types§

Source

type Context: Send + Sync

The data that is retrieved upon connecting to the endpoint and supplied to each call of on_finalized.

Source

type Data: Send + Sync

The data returned by the on_finalized call.

Required Methods§

Source

fn on_connect<'a, 'life0, 'async_trait>( &'life0 mut self, endpoint: Endpoint, client: &'a mut Client, ) -> Pin<Box<dyn Future<Output = QueryResult<Self::Context>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Called when a new connection is established to the given endpoint. The return value from this method is passed to each call of on_finalized.

Source

fn on_finalized<'a, 'life0, 'async_trait>( &'life0 self, client: Client, ctx: &'a Self::Context, fbi: FinalizedBlockInfo, ) -> Pin<Box<dyn Future<Output = OnFinalizationResult<Self::Data>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

The main method of this trait. It is called for each finalized block that the indexer discovers. Note that the indexer might call this concurrently for multiple blocks at the same time to speed up indexing.

This method is meant to return errors that are unexpected, and if it does return an error the indexer will attempt to reconnect to the next endpoint.

Source

fn on_failure<'life0, 'async_trait>( &'life0 mut self, endpoint: Endpoint, successive_failures: u64, err: TraverseError, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Called when either connecting to the node or querying the node fails. The number of successive failures without progress is passed to the method which should return whether to stop indexing (true) or not (false).

Implementors§