Skip to main content

quicknode_cascade/solana/
mod.rs

1//! Solana chain support.
2//!
3//! Implements structured extraction of Solana blocks, transactions, token
4//! transfers, and account activity from JSON-RPC `getBlock` responses.
5//!
6//! # Two Approaches
7//!
8//! **Custom extraction** — implement [`Plugin::on_raw`] and parse raw JSON yourself:
9//!
10//! ```rust,no_run
11//! use quicknode_cascade::solana::{Plugin, PluginFuture};
12//!
13//! struct MyParser;
14//! impl Plugin for MyParser {
15//!     fn name(&self) -> &'static str { "my-parser" }
16//!     fn on_raw<'a>(&'a self, slot: u64, raw: &'a serde_json::Value) -> PluginFuture<'a> {
17//!         Box::pin(async move {
18//!             // parse raw JSON however you need
19//!             Ok(())
20//!         })
21//!     }
22//! }
23//! ```
24//!
25//! **Built-in extraction** — use [`Plugin::on_block`], [`Plugin::on_transaction`], etc.
26//! and let the framework extract structured data for you.
27//!
28//! Both can be combined. [`extract_block()`] is also exposed as a public utility
29//! you can call from `on_raw` if you want the framework's extraction as a starting point.
30
31mod plugin;
32mod types;
33pub(crate) mod extract;
34
35pub use plugin::{Plugin, PluginFuture};
36pub use types::{AccountActivityData, BlockData, TokenTransferData, TransactionData};
37
38/// Extract structured data from a raw `getBlock` JSON-RPC response.
39///
40/// Takes ownership of the JSON Value (zero-copy where possible).
41/// Returns block metadata, transactions, token transfers, and account activity.
42///
43/// Use this from [`Plugin::on_raw`] if you want the framework's extraction
44/// as a starting point alongside your own custom parsing.
45///
46/// # Example
47///
48/// ```rust,no_run
49/// use quicknode_cascade::solana::{self, Plugin, PluginFuture};
50///
51/// struct HybridPlugin;
52/// impl Plugin for HybridPlugin {
53///     fn name(&self) -> &'static str { "hybrid" }
54///     fn on_raw<'a>(&'a self, slot: u64, raw: &'a serde_json::Value) -> PluginFuture<'a> {
55///         Box::pin(async move {
56///             // Use the framework's extraction
57///             let extracted = solana::extract_block(slot, raw.clone());
58///             println!("{} txs", extracted.transactions.len());
59///
60///             // PLUS do your own custom parsing from the same raw JSON
61///             if let Some(rewards) = raw.get("rewards") {
62///                 println!("rewards: {}", rewards);
63///             }
64///             Ok(())
65///         })
66///     }
67/// }
68/// ```
69pub fn extract_block(slot: u64, block: serde_json::Value) -> SlotExtract {
70    extract::extract_block(slot, block)
71}
72
73/// All extracted data for a single slot.
74///
75/// Returned by [`extract_block()`]. Contains the block metadata, all transactions,
76/// token balance changes, and account activity records.
77pub use types::SlotExtract;
78
79/// Re-exports for convenience. `use quicknode_cascade::solana::prelude::*;`
80pub mod prelude {
81    pub use super::{
82        AccountActivityData, BlockData, Plugin, PluginFuture, SlotExtract,
83        TokenTransferData, TransactionData, extract_block,
84    };
85    pub use crate::CascadeRunner;
86}