1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct FeeEstimates {
11 pub fastest_fee: u64,
13 pub half_hour_fee: u64,
15 pub hour_fee: u64,
17 pub economy_fee: u64,
19 pub minimum_fee: u64,
21}
22
23impl FeeEstimates {
24 pub fn for_blocks(&self, blocks: u32) -> u64 {
31 match blocks {
32 0..=1 => self.fastest_fee,
33 2..=3 => self.half_hour_fee,
34 4..=6 => self.hour_fee,
35 _ => self.economy_fee,
36 }
37 }
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42pub struct AddressInfo {
43 pub address: String,
45 pub chain_stats: ChainStats,
47 pub mempool_stats: MempoolStats,
49}
50
51impl AddressInfo {
52 pub fn confirmed_balance(&self) -> i64 {
54 self.chain_stats.funded_txo_sum as i64 - self.chain_stats.spent_txo_sum as i64
55 }
56
57 pub fn unconfirmed_balance(&self) -> i64 {
59 self.mempool_stats.funded_txo_sum as i64 - self.mempool_stats.spent_txo_sum as i64
60 }
61
62 pub fn total_balance(&self) -> i64 {
64 self.confirmed_balance() + self.unconfirmed_balance()
65 }
66
67 pub fn tx_count(&self) -> u64 {
69 self.chain_stats.tx_count + self.mempool_stats.tx_count
70 }
71}
72
73#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
75pub struct ChainStats {
76 pub funded_txo_count: u64,
78 pub funded_txo_sum: u64,
80 pub spent_txo_count: u64,
82 pub spent_txo_sum: u64,
84 pub tx_count: u64,
86}
87
88#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
90pub struct MempoolStats {
91 pub funded_txo_count: u64,
93 pub funded_txo_sum: u64,
95 pub spent_txo_count: u64,
97 pub spent_txo_sum: u64,
99 pub tx_count: u64,
101}
102
103#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
105pub struct Utxo {
106 pub txid: String,
108 pub vout: u32,
110 pub value: u64,
112 pub status: UtxoStatus,
114}
115
116impl Utxo {
117 pub fn is_confirmed(&self) -> bool {
119 self.status.confirmed
120 }
121
122 pub fn outpoint(&self) -> String {
124 format!("{}:{}", self.txid, self.vout)
125 }
126}
127
128#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
130pub struct UtxoStatus {
131 pub confirmed: bool,
133 pub block_height: Option<u64>,
135 pub block_hash: Option<String>,
137 pub block_time: Option<u64>,
139}
140
141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
143pub struct Transaction {
144 pub txid: String,
146 pub version: i32,
148 pub locktime: u32,
150 pub size: u32,
152 pub weight: u32,
154 pub fee: u64,
156 pub status: TxStatus,
158}
159
160impl Transaction {
161 pub fn is_confirmed(&self) -> bool {
163 self.status.confirmed
164 }
165
166 pub fn vsize(&self) -> u32 {
168 self.weight.div_ceil(4)
169 }
170
171 pub fn fee_rate(&self) -> f64 {
173 self.fee as f64 / self.vsize() as f64
174 }
175}
176
177#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
179pub struct TxStatus {
180 pub confirmed: bool,
182 pub block_height: Option<u64>,
184 pub block_hash: Option<String>,
186 pub block_time: Option<u64>,
188}
189
190#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
192pub struct BlockInfo {
193 pub id: String,
195 pub height: u64,
197 pub version: i32,
199 pub timestamp: u64,
201 pub tx_count: u32,
203 pub size: u32,
205 pub weight: u32,
207 pub merkle_root: String,
209 pub previousblockhash: String,
211 pub nonce: u32,
213 pub bits: u32,
215}