|
2 | 2 | //! |
3 | 3 | //! See: <https://github.com/Blockstream/esplora/blob/master/API.md> |
4 | 4 |
|
| 5 | +use bitcoin::hash_types; |
| 6 | +use serde::Deserialize; |
| 7 | + |
5 | 8 | pub use bitcoin::consensus::{deserialize, serialize}; |
6 | 9 | pub use bitcoin::hex::FromHex; |
7 | | -use bitcoin::Weight; |
8 | 10 | pub use bitcoin::{ |
9 | | - transaction, Amount, BlockHash, OutPoint, ScriptBuf, ScriptHash, Transaction, TxIn, TxOut, |
10 | | - Txid, Witness, |
| 11 | + absolute, block, transaction, Amount, BlockHash, OutPoint, ScriptBuf, ScriptHash, Transaction, |
| 12 | + TxIn, TxOut, Txid, Weight, Witness, |
11 | 13 | }; |
12 | 14 |
|
13 | | -use serde::Deserialize; |
14 | | - |
15 | 15 | #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] |
16 | 16 | pub struct PrevOut { |
17 | 17 | pub value: u64, |
@@ -88,6 +88,59 @@ pub struct BlockTime { |
88 | 88 | pub height: u32, |
89 | 89 | } |
90 | 90 |
|
| 91 | +/// Information about a [`Block`]. |
| 92 | +#[derive(Debug, Clone, Deserialize)] |
| 93 | +pub struct BlockInformation { |
| 94 | + /// The block's [`BlockHash`]. |
| 95 | + pub id: BlockHash, |
| 96 | + /// The block's height. |
| 97 | + pub height: u32, |
| 98 | + /// The block's version. |
| 99 | + pub version: block::Version, |
| 100 | + /// The block's timestamp. |
| 101 | + pub timestamp: u64, |
| 102 | + /// The block's transaction count. |
| 103 | + pub tx_count: u64, |
| 104 | + /// The block's size, in bytes. |
| 105 | + pub size: u64, |
| 106 | + /// The block's weight, in virtual bytes. |
| 107 | + pub weight: u64, |
| 108 | + /// The merkle root of the transactions in the block. |
| 109 | + pub merkle_root: hash_types::TxMerkleNode, |
| 110 | + /// The [`BlockHash`] of the previous block (`None`) for the genesis block. |
| 111 | + pub previousblockhash: Option<BlockHash>, |
| 112 | + /// The block's MTP (Median Time Past). |
| 113 | + pub mediantime: u64, |
| 114 | + /// The block's nonce value. |
| 115 | + pub nonce: u32, |
| 116 | + /// The block's `bits` value (`bits` is a compact representation of the target). |
| 117 | + pub bits: u32, |
| 118 | + /// The block's difficulty target value. |
| 119 | + pub difficulty: f64, |
| 120 | +} |
| 121 | + |
| 122 | +impl PartialEq for BlockInformation { |
| 123 | + fn eq(&self, other: &Self) -> bool { |
| 124 | + let Self { difficulty: d1, .. } = self; |
| 125 | + let Self { difficulty: d2, .. } = other; |
| 126 | + |
| 127 | + self.id == other.id |
| 128 | + && self.height == other.height |
| 129 | + && self.version == other.version |
| 130 | + && self.timestamp == other.timestamp |
| 131 | + && self.tx_count == other.tx_count |
| 132 | + && self.size == other.size |
| 133 | + && self.weight == other.weight |
| 134 | + && self.merkle_root == other.merkle_root |
| 135 | + && self.previousblockhash == other.previousblockhash |
| 136 | + && self.mediantime == other.mediantime |
| 137 | + && self.nonce == other.nonce |
| 138 | + && self.bits == other.bits |
| 139 | + && ((d1.is_nan() && d2.is_nan()) || (d1 == d2)) |
| 140 | + } |
| 141 | +} |
| 142 | +impl Eq for BlockInformation {} |
| 143 | + |
91 | 144 | #[derive(Debug, Clone, Deserialize, PartialEq, Eq)] |
92 | 145 | pub struct BlockSummary { |
93 | 146 | pub id: BlockHash, |
|
0 commit comments