bdk_core/
block_id.rs

1use bitcoin::{hashes::Hash, BlockHash};
2
3/// A reference to a block in the canonical chain.
4#[derive(Debug, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
5#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
6pub struct BlockId {
7    /// The height of the block.
8    pub height: u32,
9    /// The hash of the block.
10    pub hash: BlockHash,
11}
12
13impl Default for BlockId {
14    fn default() -> Self {
15        Self {
16            height: Default::default(),
17            hash: BlockHash::all_zeros(),
18        }
19    }
20}
21
22impl From<(u32, BlockHash)> for BlockId {
23    fn from((height, hash): (u32, BlockHash)) -> Self {
24        Self { height, hash }
25    }
26}
27
28impl From<BlockId> for (u32, BlockHash) {
29    fn from(block_id: BlockId) -> Self {
30        (block_id.height, block_id.hash)
31    }
32}
33
34impl From<(&u32, &BlockHash)> for BlockId {
35    fn from((height, hash): (&u32, &BlockHash)) -> Self {
36        Self {
37            height: *height,
38            hash: *hash,
39        }
40    }
41}
42
43/// Represents the confirmation block and time of a transaction.
44#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)]
45#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
46pub struct ConfirmationBlockTime {
47    /// The anchor block.
48    pub block_id: BlockId,
49    /// The confirmation time of the transaction being anchored.
50    pub confirmation_time: u64,
51}