Skip to main content

quicknode_cascade/solana/
types.rs

1//! Solana data types passed to plugin hooks.
2//!
3//! Each type carries extracted fields plus the original `raw` JSON so plugins
4//! can access any field the framework doesn't extract.
5
6use serde::{Deserialize, Serialize};
7
8/// Block-level data passed to `Plugin::on_block`.
9///
10/// Contains both extracted fields and the full raw JSON response
11/// so plugins can access any field the framework doesn't extract.
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct BlockData {
14    pub slot: u64,
15    pub blockhash: String,
16    pub parent_slot: u64,
17    pub parent_blockhash: String,
18    pub block_time: Option<i64>,
19    pub block_height: Option<u64>,
20    pub transaction_count: u64,
21    pub raw: serde_json::Value,
22}
23
24/// Transaction-level data passed to `Plugin::on_transaction`.
25///
26/// One call per transaction in the block, in order of `tx_index`.
27/// Carries the full transaction JSON in `raw` for custom parsing.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct TransactionData {
30    pub slot: u64,
31    pub tx_index: u32,
32    pub signature: String,
33    pub success: bool,
34    pub fee: u64,
35    pub compute_units_consumed: Option<u64>,
36    pub is_vote: bool,
37    pub pre_balances: Vec<u64>,
38    pub post_balances: Vec<u64>,
39    pub log_messages: Option<Vec<String>>,
40    pub block_time: Option<i64>,
41    pub raw: serde_json::Value,
42}
43
44/// Token balance change data passed to `Plugin::on_token_transfer`.
45///
46/// Emitted when a token account's balance changes within a transaction.
47/// Only emitted when `pre_amount != post_amount` (actual transfers).
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct TokenTransferData {
50    pub slot: u64,
51    pub tx_index: u32,
52    pub signature: String,
53    pub mint: String,
54    pub owner: String,
55    pub pre_amount: String,
56    pub post_amount: String,
57    pub decimals: u8,
58    pub block_time: Option<i64>,
59}
60
61/// SOL balance change data passed to `Plugin::on_account_activity`.
62///
63/// One entry per account key touched by the transaction.
64/// Includes signer/fee-payer flags for filtering.
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct AccountActivityData {
67    pub slot: u64,
68    pub tx_index: u32,
69    pub signature: String,
70    pub account: String,
71    pub pre_balance: u64,
72    pub post_balance: u64,
73    pub balance_change: i64,
74    pub is_signer: bool,
75    pub is_fee_payer: bool,
76    pub block_time: Option<i64>,
77}
78
79/// All extracted data for a single slot. Used internally by the dispatch engine.
80pub struct SlotExtract {
81    pub block: BlockData,
82    pub transactions: Vec<TransactionData>,
83    pub token_transfers: Vec<TokenTransferData>,
84    pub account_activity: Vec<AccountActivityData>,
85}