use bitcoin::{hashes::Hash, BlockHash, OutPoint, TxOut, Txid};
-use crate::{Anchor, COINBASE_MATURITY};
+use crate::{Anchor, AnchorFromBlockPosition, COINBASE_MATURITY};
/// Represents the observed position of some chain data.
///
}
}
+impl AnchorFromBlockPosition for BlockId {
+ fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
+ block_id
+ }
+}
+
impl Default for BlockId {
fn default() -> Self {
Self {
}
}
+impl AnchorFromBlockPosition for ConfirmationHeightAnchor {
+ fn from_block_position(_block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
+ Self {
+ anchor_block: block_id,
+ confirmation_height: block_id.height,
+ }
+ }
+}
+
/// An [`Anchor`] implementation that also records the exact confirmation time and height of the
/// transaction.
///
self.confirmation_height
}
}
+
+impl AnchorFromBlockPosition for ConfirmationTimeAnchor {
+ fn from_block_position(block: &bitcoin::Block, block_id: BlockId, _tx_pos: usize) -> Self {
+ Self {
+ anchor_block: block_id,
+ confirmation_height: block_id.height,
+ confirmation_time: block.header.time as _,
+ }
+ }
+}
+
/// A `TxOut` with as much data as we can retrieve about it
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct FullTxOut<A> {
}
}
-impl<A: Anchor> Anchor for &'static A {
+impl<'a, A: Anchor> Anchor for &'a A {
fn anchor_block(&self) -> BlockId {
<A as Anchor>::anchor_block(self)
}
}
+/// An [`Anchor`] that can be constructed from a given block, block height and transaction position
+/// within the block.
+pub trait AnchorFromBlockPosition: Anchor {
+ /// Construct the anchor from a given `block`, block height and `tx_pos` within the block.
+ fn from_block_position(block: &bitcoin::Block, block_id: BlockId, tx_pos: usize) -> Self;
+}
+
/// Trait that makes an object appendable.
pub trait Append {
/// Append another object of the same type onto `self`.