Solana indexer

This crate provides a transaction indexing framework for smart contracts. In order to be able to use this client, you will need to use Postgres database. Framework will be imported into an empty indexer project and contract logic for instructions will be defined by the framework consumer.


Usage

Add this to your Cargo.toml: toml [dependencies] solana-indexer = "0.1.2"

Code example: ```rust pub use { solanaindexer::{ FetchingParams, Indexer, IndexerError, IndexingParams, IndexingResult, Instruction, }, solanaprogram::pubkey, std::fmt::Display, std::process, std::sync::Arc, thiserror::Error, };

[derive(Error, Debug)]

pub enum CustomError { #[error("Custom")] Custom, }

impl From for IndexerError { fn from(err: CustomError) -> IndexerError { IndexerError::CbError(Box::new(err)) } }

fn unwraporexit(res: IndexingResult) -> T { match res { Ok(value) => value, Err(err) => { /* Error handling */ process::exit(1); } } }

fn simplecallback(instruction: &Instruction) -> IndexingResult<()> { /* Callback body */ if instruction.programid == "" { // You can use your custom error as cb result return Err(CustomError::Custom.into()); } else if instruction.program_id == "123" { // Also you can generate error from string to use it as cb result return Err("Custom string error".into()); } Ok(()) }

async fn run( programid: pubkey::Pubkey, connectionstr: String, dbconnection: String, timestampinterval: i64, ) { let indexerparams = IndexingParams::new( programid, connectionstr, dbconnection, FetchingParams::default(), timestamp_interval, );

// You can handle the result of indexing process
let mut solana_indexer = unwrap_or_exit(Indexer::new(indexer_params).await);

unwrap_or_exit(
    solana_indexer
        .start_indexing(Arc::new(simple_callback))
        .await,
);

}

```

License

Solana indexer is distributed under the terms of the MIT license.