subcoin_indexer/
types.rs

1//! Types for the indexer.
2
3use bitcoin::Txid;
4
5/// A transaction in an address's history.
6#[derive(Debug, Clone)]
7pub struct AddressHistory {
8    /// Transaction ID.
9    pub txid: Txid,
10    /// Block height of the transaction.
11    pub block_height: u32,
12    /// Net change in satoshis for this address in this transaction.
13    /// Positive = received, negative = sent.
14    pub delta: i64,
15    /// Block timestamp.
16    pub timestamp: u32,
17}
18
19/// An unspent transaction output.
20#[derive(Debug, Clone)]
21pub struct Utxo {
22    /// Transaction ID containing this output.
23    pub txid: Txid,
24    /// Output index within the transaction.
25    pub vout: u32,
26    /// Value in satoshis.
27    pub value: u64,
28    /// Block height where this output was created.
29    pub block_height: u32,
30    /// The scriptPubKey as hex.
31    pub script_pubkey: Vec<u8>,
32}
33
34/// Address balance summary.
35#[derive(Debug, Clone, Default)]
36pub struct AddressBalance {
37    /// Confirmed balance in satoshis.
38    pub confirmed: u64,
39    /// Number of transactions involving this address.
40    pub tx_count: u64,
41    /// Number of unspent outputs.
42    pub utxo_count: u64,
43    /// Total received in satoshis.
44    pub total_received: u64,
45    /// Total sent in satoshis.
46    pub total_sent: u64,
47}
48
49/// Indexer state for crash recovery.
50#[derive(Debug, Clone, Copy)]
51pub enum IndexerState {
52    /// Currently indexing historical blocks.
53    HistoricalIndexing {
54        /// Target block height to reach.
55        target_height: u32,
56        /// Current position in historical indexing.
57        current_height: u32,
58    },
59    /// Actively processing new blocks.
60    Active {
61        /// Last successfully indexed block height.
62        last_indexed: u32,
63    },
64}
65
66/// Indexer status for RPC queries.
67#[derive(Debug, Clone)]
68pub struct IndexerStatus {
69    /// Whether the indexer is currently syncing historical blocks.
70    pub is_syncing: bool,
71    /// Current indexed block height.
72    pub indexed_height: u32,
73    /// Target block height (only relevant during historical sync).
74    pub target_height: Option<u32>,
75    /// Sync progress as percentage (0.0 - 100.0).
76    pub progress_percent: f64,
77}
78
79/// Address statistics for RPC queries.
80#[derive(Debug, Clone, Default)]
81pub struct AddressStats {
82    /// Block height when address first received funds.
83    pub first_seen_height: Option<u32>,
84    /// Timestamp when address first received funds.
85    pub first_seen_timestamp: Option<u32>,
86    /// Block height of most recent transaction.
87    pub last_seen_height: Option<u32>,
88    /// Timestamp of most recent transaction.
89    pub last_seen_timestamp: Option<u32>,
90    /// Largest single receive amount in satoshis.
91    pub largest_receive: u64,
92    /// Largest single send amount in satoshis (absolute value).
93    pub largest_send: u64,
94    /// Total number of receive transactions.
95    pub receive_count: u64,
96    /// Total number of send transactions.
97    pub send_count: u64,
98}
99
100/// Output spending status.
101#[derive(Debug, Clone)]
102pub struct OutputStatus {
103    /// Whether the output has been spent.
104    pub spent: bool,
105    /// Transaction ID that spent this output (if spent).
106    pub spent_by_txid: Option<Txid>,
107    /// Input index in the spending transaction (if spent).
108    pub spent_by_vin: Option<u32>,
109    /// Block height where the output was spent (if spent).
110    pub spent_at_height: Option<u32>,
111}