esplora_rs/models.rs
1use serde::Deserialize;
2
3/// Represents a Bitcoin block.
4#[derive(Debug, Clone, Deserialize)]
5pub struct Block {
6 /// The block hash.
7 pub id: String,
8 /// The block height.
9 pub height: u64,
10 /// The block version. Bitcoin's `nVersion` is a signed `int32`
11 /// (rust-bitcoin `block::Version` wraps `i32`), so Esplora can surface a
12 /// negative value; typed `i32` to avoid a decode failure of the same class
13 /// as the waterfalls `v: -1` sentinel.
14 pub version: i32,
15 /// The block timestamp.
16 pub timestamp: u64,
17 /// The number of transactions in the block.
18 pub tx_count: u64,
19 /// The block size in bytes.
20 pub size: u64,
21 /// The block weight in weight units.
22 pub weight: u64,
23 /// The Merkle root of the block's transactions.
24 pub merkle_root: String,
25 /// The hash of the previous block.
26 pub previousblockhash: Option<String>,
27 /// The block nonce.
28 pub nonce: u32,
29 /// The block bits.
30 pub bits: u32,
31}
32
33/// Represents the confirmation status of a block.
34#[derive(Debug, Clone, Deserialize)]
35pub struct BlockStatus {
36 /// Whether the block is in the best chain.
37 pub in_best_chain: bool,
38 /// The hash of the next block in the best chain.
39 pub next_best: Option<String>,
40}
41
42/// Represents the confirmation status of a transaction.
43#[derive(Debug, Clone, Deserialize)]
44pub struct TxStatus {
45 /// Whether the transaction is confirmed.
46 pub confirmed: bool,
47 /// The height of the block that contains the transaction.
48 pub block_height: Option<u64>,
49 /// The hash of the block that contains the transaction.
50 pub block_hash: Option<String>,
51 /// The timestamp of the block that contains the transaction.
52 pub block_time: Option<u64>,
53}
54
55/// Represents a previous output of a transaction input.
56#[derive(Debug, Clone, Deserialize)]
57pub struct Prevout {
58 /// The script public key.
59 pub scriptpubkey: String,
60 /// The assembly representation of the script public key.
61 pub scriptpubkey_asm: String,
62 /// The type of the script public key.
63 pub scriptpubkey_type: String,
64 /// The address associated with the script public key.
65 pub scriptpubkey_address: Option<String>,
66 /// The value of the output in satoshis.
67 pub value: u64,
68}
69
70/// Represents a transaction input.
71#[derive(Debug, Clone, Deserialize)]
72pub struct Vin {
73 /// The ID of the transaction that contains the input.
74 pub txid: String,
75 /// The index of the input in the transaction.
76 pub vout: u32,
77 /// The previous output being spent.
78 pub prevout: Option<Prevout>,
79 /// The script signature.
80 pub scriptsig: String,
81 /// The assembly representation of the script signature.
82 pub scriptsig_asm: String,
83 /// The witness data for the input.
84 pub witness: Option<Vec<String>>,
85 /// Whether the input is a coinbase input.
86 pub is_coinbase: bool,
87 /// The sequence number of the input.
88 pub sequence: u32,
89}
90
91/// Represents a transaction output.
92#[derive(Debug, Clone, Deserialize)]
93pub struct Vout {
94 /// The script public key.
95 pub scriptpubkey: String,
96 /// The assembly representation of the script public key.
97 pub scriptpubkey_asm: String,
98 /// The type of the script public key.
99 pub scriptpubkey_type: String,
100 /// The address associated with the script public key.
101 pub scriptpubkey_address: Option<String>,
102 /// The value of the output in satoshis.
103 pub value: u64,
104}
105
106/// Represents a Bitcoin transaction.
107#[derive(Debug, Clone, Deserialize)]
108pub struct Transaction {
109 /// The transaction ID.
110 pub txid: String,
111 /// The transaction version. `nVersion` is a signed `int32` at the consensus
112 /// level (rust-bitcoin `transaction::Version` wraps `i32`), so a negative
113 /// value is representable on the wire; typed `i32` for the same reason as
114 /// [`Block::version`].
115 pub version: i32,
116 /// The transaction locktime.
117 pub locktime: u32,
118 /// The list of transaction inputs.
119 pub vin: Vec<Vin>,
120 /// The list of transaction outputs.
121 pub vout: Vec<Vout>,
122 /// The transaction size in bytes.
123 pub size: u64,
124 /// The transaction weight in weight units.
125 pub weight: u64,
126 /// The transaction fee in satoshis.
127 pub fee: u64,
128 /// The confirmation status of the transaction.
129 pub status: TxStatus,
130}
131
132/// Represents the spending status of a transaction output.
133#[derive(Debug, Clone, Deserialize)]
134pub struct Outspend {
135 /// Whether the output is spent.
136 pub spent: bool,
137 /// The ID of the transaction that spent the output.
138 pub txid: Option<String>,
139 /// The index of the input that spent the output.
140 pub vin: Option<u32>,
141 /// The confirmation status of the spending transaction.
142 pub status: Option<TxStatus>,
143}
144
145/// Represents statistics for an address.
146#[derive(Debug, Clone, Deserialize)]
147pub struct Stats {
148 /// The total number of transactions for the address.
149 pub tx_count: u64,
150 /// The number of funded transaction outputs.
151 pub funded_txo_count: u64,
152 /// The sum of all funded transaction outputs.
153 pub funded_txo_sum: Option<u64>,
154 /// The number of spent transaction outputs.
155 pub spent_txo_count: u64,
156 /// The sum of all spent transaction outputs.
157 pub spent_txo_sum: Option<u64>,
158}
159
160/// Represents information about an address.
161#[derive(Debug, Clone, Deserialize)]
162pub struct AddressInfo {
163 /// The address.
164 pub address: String,
165 /// The chain-level statistics for the address.
166 pub chain_stats: Stats,
167 /// The mempool-level statistics for the address.
168 pub mempool_stats: Stats,
169}
170
171/// Represents an unspent transaction output (UTXO).
172#[derive(Debug, Clone, Deserialize)]
173pub struct Utxo {
174 /// The transaction ID of the UTXO.
175 pub txid: String,
176 /// The output index of the UTXO.
177 pub vout: u32,
178 /// The confirmation status of the UTXO.
179 pub status: TxStatus,
180 /// The value of the UTXO in satoshis.
181 pub value: u64,
182 /// The asset ID of the UTXO (for Elements-based chains).
183 pub asset: Option<String>,
184}
185
186/// Represents information about the mempool.
187#[derive(Debug, Clone, Deserialize)]
188pub struct Mempool {
189 /// The number of transactions in the mempool.
190 pub count: u64,
191 /// The total size of the mempool in virtual bytes.
192 pub vsize: u64,
193 /// The total fee of all transactions in the mempool.
194 pub total_fee: u64,
195 /// The fee histogram of the mempool.
196 pub fee_histogram: Vec<(f64, f64)>,
197}
198
199/// Represents a recent transaction in the mempool.
200#[derive(Debug, Clone, Deserialize)]
201pub struct RecentTx {
202 /// The transaction ID.
203 pub txid: String,
204 /// The transaction fee in satoshis.
205 pub fee: u64,
206 /// The transaction size in virtual bytes.
207 pub vsize: u64,
208 /// The transaction value in satoshis.
209 pub value: u64,
210}
211
212/// A map of confirmation targets to fee estimates.
213pub type FeeEstimates = std::collections::HashMap<String, f64>;
214
215/// Represents statistics for an asset.
216#[derive(Debug, Clone, Deserialize)]
217pub struct AssetStats {
218 /// The number of transactions for the asset.
219 pub tx_count: u64,
220 // Native asset stats
221 /// The number of peg-in transactions.
222 pub peg_in_count: Option<u64>,
223 /// The total amount of pegged-in assets.
224 pub peg_in_amount: Option<u64>,
225 /// The number of peg-out transactions.
226 pub peg_out_count: Option<u64>,
227 /// The total amount of pegged-out assets.
228 pub peg_out_amount: Option<u64>,
229 /// The number of burn transactions.
230 pub burn_count: Option<u64>,
231 /// The total amount of burned assets.
232 pub burned_amount: Option<u64>,
233 // User-issued asset stats
234 /// The number of issuance transactions.
235 pub issuance_count: Option<u64>,
236 /// The total amount of issued assets.
237 pub issued_amount: Option<u64>,
238 /// Whether the asset has had any blinded issuances.
239 pub has_blinded_issuances: Option<bool>,
240 /// The number of reissuance tokens.
241 pub reissuance_tokens: Option<u64>,
242 /// The number of burned reissuance tokens.
243 pub burned_reissuance_tokens: Option<u64>,
244}
245
246/// Represents the transaction input of an asset issuance.
247#[derive(Debug, Clone, Deserialize)]
248pub struct AssetIssuanceTxin {
249 /// The transaction ID of the issuance.
250 pub txid: String,
251 /// The input index of the issuance.
252 pub vin: u32,
253}
254
255/// Represents the previous output of an asset issuance.
256#[derive(Debug, Clone, Deserialize)]
257pub struct AssetIssuancePrevout {
258 /// The transaction ID of the previous output.
259 pub txid: String,
260 /// The output index of the previous output.
261 pub vout: u32,
262}
263
264/// Represents the entity associated with an asset.
265#[derive(Debug, Clone, Deserialize)]
266pub struct AssetEntity {
267 /// The domain of the entity.
268 pub domain: String,
269}
270
271/// Represents information about an asset.
272#[derive(Debug, Clone, Deserialize)]
273pub struct AssetInfo {
274 /// The asset ID.
275 pub asset_id: String,
276 /// The transaction input of the issuance.
277 pub issuance_txin: Option<AssetIssuanceTxin>,
278 /// The previous output of the issuance.
279 pub issuance_prevout: Option<AssetIssuancePrevout>,
280 /// The reissuance token for the asset.
281 pub reissuance_token: Option<String>,
282 /// The contract hash for the asset.
283 pub contract_hash: Option<String>,
284 /// The confirmation status of the asset issuance.
285 pub status: Option<TxStatus>,
286 /// The chain-level statistics for the asset.
287 pub chain_stats: AssetStats,
288 /// The mempool-level statistics for the asset.
289 pub mempool_stats: AssetStats,
290 // From asset registry
291 /// The ticker symbol for the asset.
292 pub ticker: Option<String>,
293 /// The name of the asset.
294 pub name: Option<String>,
295 /// The precision of the asset.
296 pub precision: Option<u8>,
297 /// The entity associated with the asset.
298 pub entity: Option<AssetEntity>,
299}
300
301/// A single QuickSync/Waterfalls (`/v2/waterfalls`) sighting of a transaction
302/// at a derivation index.
303#[derive(Debug, Clone, Deserialize)]
304pub struct TxSeen {
305 /// The transaction id (hex).
306 pub txid: String,
307 /// The block height; `0` (or an absent block) means unconfirmed/mempool.
308 pub height: i64,
309 /// The hash of the confirming block (hex), when confirmed.
310 #[serde(default)]
311 pub block_hash: Option<String>,
312 /// The timestamp of the confirming block, when confirmed.
313 #[serde(default)]
314 pub block_timestamp: Option<u64>,
315 /// A per-sighting marker present in some server responses. Waterfalls uses
316 /// it to distinguish an *output* sighting (small non-negative index) from a
317 /// *spend/input* sighting, which the server flags with the sentinel `-1`.
318 /// Kept as `i64` so that sentinel deserializes (the earlier `height` u32→i64
319 /// loosening in 8c9b645 missed this field); the client never reads it — the
320 /// waterfalls scan uses only `txid` + the sighting's index position.
321 #[serde(default)]
322 pub v: Option<i64>,
323}
324
325/// The `/v2/waterfalls` response: a descriptor's (or address set's) transaction
326/// history returned in a single call, grouped per single-path descriptor and
327/// per derivation index.
328#[derive(Debug, Clone, Deserialize)]
329pub struct WaterfallResponse {
330 /// Keyed by the single-path descriptor string (a multipath `<0;1>` request
331 /// returns separate `…/0/*` and `…/1/*` keys), or the literal `"addresses"`
332 /// when queried by address. The outer `Vec` is indexed by derivation index;
333 /// each inner `Vec` holds the transactions seen at that index.
334 pub txs_seen: std::collections::BTreeMap<String, Vec<Vec<TxSeen>>>,
335 /// The page number echoed by the server.
336 pub page: u16,
337 /// The chain tip block hash (hex) at scan time.
338 pub tip: String,
339}