[bdk_chain_redesign] Introduce BlockAnchor trait

* Introduce `GraphedTx` struct to access transaction data of graphed
  transactions.
* Ability to insert/access anchors and "seen at" values for graphed
  transactions.
* `Additions` now records changes to anchors and last_seen_at.
This commit is contained in:
志宇
2023-03-24 09:23:36 +08:00
parent 82f9caddab
commit 5ae5fe30eb
21 changed files with 584 additions and 298 deletions

View File

@@ -1,4 +1,6 @@
use bitcoin::{Block, OutPoint, Transaction, TxOut};
use bitcoin::{Block, BlockHash, OutPoint, Transaction, TxOut};
use crate::BlockId;
/// Trait to do something with every txout contained in a structure.
///
@@ -31,3 +33,19 @@ impl ForEachTxOut for Transaction {
}
}
}
/// Trait that "anchors" blockchain data in a specific block of height and hash.
///
/// This trait is typically associated with blockchain data such as transactions.
pub trait BlockAnchor:
core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash + Send + Sync + 'static
{
/// Returns the [`BlockId`] that the associated blockchain data is "anchored" in.
fn anchor_block(&self) -> BlockId;
}
impl BlockAnchor for (u32, BlockHash) {
fn anchor_block(&self) -> BlockId {
(*self).into()
}
}