Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin:
    Send
    + Sync
    + 'static {
    // Required method
    fn name(&self) -> &'static str;

    // Provided methods
    fn on_load<'a>(&'a self) -> PluginFuture<'a> { ... }
    fn on_block<'a>(&'a self, _block: &'a BlockData) -> PluginFuture<'a> { ... }
    fn on_transaction<'a>(
        &'a self,
        _tx: &'a TransactionData,
    ) -> PluginFuture<'a> { ... }
    fn on_token_transfer<'a>(
        &'a self,
        _transfer: &'a TokenTransferData,
    ) -> PluginFuture<'a> { ... }
    fn on_account_activity<'a>(
        &'a self,
        _activity: &'a AccountActivityData,
    ) -> PluginFuture<'a> { ... }
    fn on_skipped_slot<'a>(&'a self, _slot: u64) -> PluginFuture<'a> { ... }
    fn on_raw_block<'a>(
        &'a self,
        _slot: u64,
        _raw: &'a Value,
    ) -> PluginFuture<'a> { ... }
    fn on_exit<'a>(&'a self) -> PluginFuture<'a> { ... }
}
Expand description

Observe Solana block and transaction events.

Register your plugin with CascadeRunner::with_plugin() and the framework handles all fetching, retries, parallelism, and cursor management.

All hooks have default no-op implementations. Override only the events you care about.

§Example

use quicknode_cascade::solana::{Plugin, PluginFuture, BlockData, TransactionData};

struct MyIndexer;

impl Plugin for MyIndexer {
    fn name(&self) -> &'static str { "my-indexer" }

    fn on_block<'a>(&'a self, block: &'a BlockData) -> PluginFuture<'a> {
        Box::pin(async move {
            println!("slot {} — {} txs", block.slot, block.transaction_count);
            Ok(())
        })
    }

    fn on_transaction<'a>(&'a self, tx: &'a TransactionData) -> PluginFuture<'a> {
        Box::pin(async move {
            if !tx.is_vote {
                println!("  tx {}", tx.signature);
            }
            Ok(())
        })
    }
}

Required Methods§

Source

fn name(&self) -> &'static str

Human-friendly name for this plugin (used in logs).

Provided Methods§

Source

fn on_load<'a>(&'a self) -> PluginFuture<'a>

Called once when the runner starts, before any data is fetched. Use this to create tables, open connections, or validate config.

Source

fn on_block<'a>(&'a self, _block: &'a BlockData) -> PluginFuture<'a>

Called for each block. Fired once per slot, before transactions.

Source

fn on_transaction<'a>(&'a self, _tx: &'a TransactionData) -> PluginFuture<'a>

Called for each transaction within a block. Fired in order of tx_index within the slot.

Source

fn on_token_transfer<'a>( &'a self, _transfer: &'a TokenTransferData, ) -> PluginFuture<'a>

Called for each token balance change within a transaction. Only fired when the balance actually changed (pre != post).

Source

fn on_account_activity<'a>( &'a self, _activity: &'a AccountActivityData, ) -> PluginFuture<'a>

Called for each account touched by a transaction (SOL balance changes).

Source

fn on_skipped_slot<'a>(&'a self, _slot: u64) -> PluginFuture<'a>

Called when a slot was skipped by the Solana leader (no block produced).

Source

fn on_raw_block<'a>(&'a self, _slot: u64, _raw: &'a Value) -> PluginFuture<'a>

Called for each slot in raw mode. Receives the full JSON-RPC response. Only fired when the runner is in raw encoding mode.

Source

fn on_exit<'a>(&'a self) -> PluginFuture<'a>

Called once when the runner is shutting down. Flush buffers, close connections.

Implementors§