-use core::{convert::Infallible, ops::AddAssign};
+use core::convert::Infallible;
use bitcoin::{OutPoint, Script, Transaction, TxOut};
use crate::{
keychain::Balance,
tx_graph::{Additions, TxGraph, TxNode},
- BlockAnchor, ChainOracle, FullTxOut, ObservedAs, TxIndex,
+ Append, BlockAnchor, ChainOracle, FullTxOut, ObservedAs, TxIndex,
};
/// An outwards-facing view of a transaction that is part of the *best chain*'s history.
}
}
-impl<A: BlockAnchor, IA: AddAssign> AddAssign for IndexedAdditions<A, IA> {
- fn add_assign(&mut self, rhs: Self) {
- let Self {
- graph_additions,
- index_additions: index_delta,
- last_height,
- } = rhs;
- self.graph_additions.append(graph_additions);
- self.index_additions += index_delta;
- if self.last_height < last_height {
- let last_height =
- last_height.expect("must exist as it is larger than self.last_height");
+impl<A: BlockAnchor, IA: Append> Append for IndexedAdditions<A, IA> {
+ fn append(&mut self, other: Self) {
+ self.graph_additions.append(other.graph_additions);
+ self.index_additions.append(other.index_additions);
+ if self.last_height < other.last_height {
+ let last_height = other
+ .last_height
+ .expect("must exist as it is larger than self.last_height");
self.last_height.replace(last_height);
}
}
) -> IndexedAdditions<A, I::Additions>
where
T: Iterator<Item = &'t Transaction>,
- I::Additions: Default + AddAssign,
+ I::Additions: Default + Append,
{
txs.filter_map(|tx| {
if self.index.is_tx_relevant(tx) {
}
})
.fold(IndexedAdditions::default(), |mut acc, other| {
- acc += other;
+ acc.append(other);
acc
})
}
//! [`KeychainChangeSet`]s.
//!
//! [`SpkTxOutIndex`]: crate::SpkTxOutIndex
-use core::ops::AddAssign;
use crate::{
chain_graph::{self, ChainGraph},
collections::BTreeMap,
sparse_chain::ChainPosition,
tx_graph::TxGraph,
- ForEachTxOut,
+ Append, ForEachTxOut,
};
#[cfg(feature = "miniscript")]
}
}
-impl<K: Ord> DerivationAdditions<K> {
+impl<K: Ord> Append for DerivationAdditions<K> {
/// Append another [`DerivationAdditions`] into self.
///
/// If the keychain already exists, increase the index when the other's index > self's index.
/// If the keychain did not exist, append the new keychain.
- pub fn append(&mut self, mut other: Self) {
+ fn append(&mut self, mut other: Self) {
self.0.iter_mut().for_each(|(key, index)| {
if let Some(other_index) = other.0.remove(key) {
*index = other_index.max(*index);
}
}
-impl<K: Ord> AddAssign for DerivationAdditions<K> {
- fn add_assign(&mut self, rhs: Self) {
- self.append(rhs)
- }
-}
-
impl<K> Default for DerivationAdditions<K> {
fn default() -> Self {
Self(Default::default())
Descriptor, DescriptorPublicKey,
},
sparse_chain::{self, ChainPosition},
- DescriptorExt, FullTxOut,
+ Append, DescriptorExt, FullTxOut,
};
use bdk_coin_select::{coin_select_bnb, CoinSelector, CoinSelectorOpt, WeightedValue};
use bdk_file_store::KeychainStore;