diff --git a/crates/chain/src/chain_data.rs b/crates/chain/src/chain_data.rs index a360b304e..3252febc2 100644 --- a/crates/chain/src/chain_data.rs +++ b/crates/chain/src/chain_data.rs @@ -160,12 +160,6 @@ impl Default for BlockId { } } -impl Anchor for BlockId { - fn anchor_block(&self) -> BlockId { - *self - } -} - impl From<(u32, BlockHash)> for BlockId { fn from((height, hash): (u32, BlockHash)) -> Self { Self { height, hash } @@ -187,6 +181,58 @@ impl From<(&u32, &BlockHash)> for BlockId { } } +/// An [`Anchor`] implementation that also records the exact confirmation height of the transaction. +#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)] +#[cfg_attr( + feature = "serde", + derive(serde::Deserialize, serde::Serialize), + serde(crate = "serde_crate") +)] +pub struct ConfirmationHeightAnchor { + /// The anchor block. + pub anchor_block: BlockId, + + /// The exact confirmation height of the transaction. + /// + /// It is assumed that this value is never larger than the height of the anchor block. + pub confirmation_height: u32, +} + +impl Anchor for ConfirmationHeightAnchor { + fn anchor_block(&self) -> BlockId { + self.anchor_block + } + + fn confirmation_height_upper_bound(&self) -> u32 { + self.confirmation_height + } +} + +/// An [`Anchor`] implementation that also records the exact confirmation time and height of the +/// transaction. +#[derive(Debug, Default, Clone, PartialEq, Eq, Copy, PartialOrd, Ord, core::hash::Hash)] +#[cfg_attr( + feature = "serde", + derive(serde::Deserialize, serde::Serialize), + serde(crate = "serde_crate") +)] +pub struct ConfirmationTimeAnchor { + /// The anchor block. + pub anchor_block: BlockId, + + pub confirmation_height: u32, + pub confirmation_time: u64, +} + +impl Anchor for ConfirmationTimeAnchor { + fn anchor_block(&self) -> BlockId { + self.anchor_block + } + + fn confirmation_height_upper_bound(&self) -> u32 { + self.confirmation_height + } +} /// A `TxOut` with as much data as we can retrieve about it #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct FullTxOut
{ diff --git a/crates/chain/src/chain_oracle.rs b/crates/chain/src/chain_oracle.rs index 2b4ad36fe..58fbf6c18 100644 --- a/crates/chain/src/chain_oracle.rs +++ b/crates/chain/src/chain_oracle.rs @@ -10,12 +10,13 @@ pub trait ChainOracle { /// Error type. type Error: core::fmt::Debug; - /// Determines whether `block` of [`BlockId`] exists as an ancestor of `static_block`. + /// Determines whether `block` of [`BlockId`] exists as an ancestor of `chain_tip`. /// - /// If `None` is returned, it means the implementation cannot determine whether `block` exists. + /// If `None` is returned, it means the implementation cannot determine whether `block` exists + /// under `chain_tip`. fn is_block_in_chain( &self, block: BlockId, - static_block: BlockId, + chain_tip: BlockId, ) -> Result