[bdk_chain_redesign] Various tweaks and fixes
The `ConfirmationHeight` trait has been removed in favour of a second method on the `Anchor` trait: `confirmation_height_upper_bound()`. Methods `try_balance_at()` and `balance_at()` of `IndexedTxGraph` have been removed as they do not provide additional functionality. `IndexedTxGraph::insert_relevant_txs` now uses two loops, the first loop indexes all transactions first. This is done as some indexes require ancestor transactions to be indexed first and we cannot guarantee that the input transactions are in topological order.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::collections::BTreeMap;
|
||||
use crate::collections::BTreeSet;
|
||||
use crate::BlockId;
|
||||
use bitcoin::{Block, BlockHash, OutPoint, Transaction, TxOut};
|
||||
use bitcoin::{Block, OutPoint, Transaction, TxOut};
|
||||
|
||||
/// Trait to do something with every txout contained in a structure.
|
||||
///
|
||||
@@ -41,11 +41,17 @@ impl ForEachTxOut for Transaction {
|
||||
/// assume that transaction A is also confirmed in the best chain. This does not necessarily mean
|
||||
/// that transaction A is confirmed in block B. It could also mean transaction A is confirmed in a
|
||||
/// parent block of B.
|
||||
pub trait Anchor:
|
||||
core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash + Send + Sync + 'static
|
||||
{
|
||||
pub trait Anchor: core::fmt::Debug + Clone + Eq + PartialOrd + Ord + core::hash::Hash {
|
||||
/// Returns the [`BlockId`] that the associated blockchain data is "anchored" in.
|
||||
fn anchor_block(&self) -> BlockId;
|
||||
|
||||
/// Get the upper bound of the chain data's confirmation height.
|
||||
///
|
||||
/// The default definition gives a pessimistic answer. This can be overridden by the `Anchor`
|
||||
/// implementation for a more accurate value.
|
||||
fn confirmation_height_upper_bound(&self) -> u32 {
|
||||
self.anchor_block().height
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Anchor> Anchor for &'static A {
|
||||
@@ -54,21 +60,6 @@ impl<A: Anchor> Anchor for &'static A {
|
||||
}
|
||||
}
|
||||
|
||||
impl Anchor for (u32, BlockHash) {
|
||||
fn anchor_block(&self) -> BlockId {
|
||||
(*self).into()
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait that returns a confirmation height.
|
||||
///
|
||||
/// This is typically used to provide an [`Anchor`] implementation the exact confirmation height of
|
||||
/// the data being anchored.
|
||||
pub trait ConfirmationHeight {
|
||||
/// Returns the confirmation height.
|
||||
fn confirmation_height(&self) -> u32;
|
||||
}
|
||||
|
||||
/// Trait that makes an object appendable.
|
||||
pub trait Append {
|
||||
/// Append another object of the same type onto `self`.
|
||||
|
||||
Reference in New Issue
Block a user