Merge bitcoindevkit/bdk#1502: chore(chain)!: Rename Append
to Merge
962305f41546613b5b41b4131d4a5594f01a2de0 chore(chain)!: Rename `Append` to `Merge` (Wei Chen) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> Fixes #1467. ### Description <!-- Describe the purpose of this PR, what's being adding and/or fixed --> Renames the `Append` trait to `Merge`. ### Notes to the reviewers <!-- In this section you can include notes directed to the reviewers, like explaining why some parts of the PR were done in a specific way --> ### Changelog notice <!-- Notice the release manager should include in the release tag message changelog --> <!-- See https://keepachangelog.com/en/1.0.0/ for examples --> * Rename `bdk_chain::Append` to `bdk_chain::Merge`. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK 962305f41546613b5b41b4131d4a5594f01a2de0 Tree-SHA512: 2019d9ed631776850cda39c9a53bdd3660c7f4715d8c418824d8ad13718f2b2fd160159e03fd63743dbf0b9e91cfdfed7e4cd4a591636f67d2aaec419486d136
This commit is contained in:
commit
43f093d918
@ -4,7 +4,7 @@ use bdk_bitcoind_rpc::Emitter;
|
|||||||
use bdk_chain::{
|
use bdk_chain::{
|
||||||
bitcoin::{Address, Amount, Txid},
|
bitcoin::{Address, Amount, Txid},
|
||||||
local_chain::{CheckPoint, LocalChain},
|
local_chain::{CheckPoint, LocalChain},
|
||||||
Append, Balance, BlockId, IndexedTxGraph, SpkTxOutIndex,
|
Balance, BlockId, IndexedTxGraph, Merge, SpkTxOutIndex,
|
||||||
};
|
};
|
||||||
use bdk_testenv::{anyhow, TestEnv};
|
use bdk_testenv::{anyhow, TestEnv};
|
||||||
use bitcoin::{hashes::Hash, Block, OutPoint, ScriptBuf, WScriptHash};
|
use bitcoin::{hashes::Hash, Block, OutPoint, ScriptBuf, WScriptHash};
|
||||||
|
@ -34,10 +34,10 @@ impl<K, A> core::default::Default for CombinedChangeSet<K, A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "miniscript")]
|
#[cfg(feature = "miniscript")]
|
||||||
impl<K: Ord, A: crate::Anchor> crate::Append for CombinedChangeSet<K, A> {
|
impl<K: Ord, A: crate::Anchor> crate::Merge for CombinedChangeSet<K, A> {
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
crate::Append::append(&mut self.chain, other.chain);
|
crate::Merge::merge(&mut self.chain, other.chain);
|
||||||
crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph);
|
crate::Merge::merge(&mut self.indexed_tx_graph, other.indexed_tx_graph);
|
||||||
if other.network.is_some() {
|
if other.network.is_some() {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
self.network.is_none() || self.network == other.network,
|
self.network.is_none() || self.network == other.network,
|
||||||
|
@ -5,7 +5,7 @@ use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
tx_graph::{self, TxGraph},
|
tx_graph::{self, TxGraph},
|
||||||
Anchor, AnchorFromBlockPosition, Append, BlockId, Indexer,
|
Anchor, AnchorFromBlockPosition, BlockId, Indexer, Merge,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The [`IndexedTxGraph`] combines a [`TxGraph`] and an [`Indexer`] implementation.
|
/// The [`IndexedTxGraph`] combines a [`TxGraph`] and an [`Indexer`] implementation.
|
||||||
@ -67,7 +67,7 @@ impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I> {
|
|||||||
|
|
||||||
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
||||||
where
|
where
|
||||||
I::ChangeSet: Default + Append,
|
I::ChangeSet: Default + Merge,
|
||||||
{
|
{
|
||||||
fn index_tx_graph_changeset(
|
fn index_tx_graph_changeset(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -75,10 +75,10 @@ where
|
|||||||
) -> I::ChangeSet {
|
) -> I::ChangeSet {
|
||||||
let mut changeset = I::ChangeSet::default();
|
let mut changeset = I::ChangeSet::default();
|
||||||
for added_tx in &tx_graph_changeset.txs {
|
for added_tx in &tx_graph_changeset.txs {
|
||||||
changeset.append(self.index.index_tx(added_tx));
|
changeset.merge(self.index.index_tx(added_tx));
|
||||||
}
|
}
|
||||||
for (&added_outpoint, added_txout) in &tx_graph_changeset.txouts {
|
for (&added_outpoint, added_txout) in &tx_graph_changeset.txouts {
|
||||||
changeset.append(self.index.index_txout(added_outpoint, added_txout));
|
changeset.merge(self.index.index_txout(added_outpoint, added_txout));
|
||||||
}
|
}
|
||||||
changeset
|
changeset
|
||||||
}
|
}
|
||||||
@ -137,16 +137,16 @@ where
|
|||||||
|
|
||||||
let mut indexer = I::ChangeSet::default();
|
let mut indexer = I::ChangeSet::default();
|
||||||
for (tx, _) in &txs {
|
for (tx, _) in &txs {
|
||||||
indexer.append(self.index.index_tx(tx));
|
indexer.merge(self.index.index_tx(tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut graph = tx_graph::ChangeSet::default();
|
let mut graph = tx_graph::ChangeSet::default();
|
||||||
for (tx, anchors) in txs {
|
for (tx, anchors) in txs {
|
||||||
if self.index.is_tx_relevant(tx) {
|
if self.index.is_tx_relevant(tx) {
|
||||||
let txid = tx.compute_txid();
|
let txid = tx.compute_txid();
|
||||||
graph.append(self.graph.insert_tx(tx.clone()));
|
graph.merge(self.graph.insert_tx(tx.clone()));
|
||||||
for anchor in anchors {
|
for anchor in anchors {
|
||||||
graph.append(self.graph.insert_anchor(txid, anchor));
|
graph.merge(self.graph.insert_anchor(txid, anchor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ where
|
|||||||
|
|
||||||
let mut indexer = I::ChangeSet::default();
|
let mut indexer = I::ChangeSet::default();
|
||||||
for (tx, _) in &txs {
|
for (tx, _) in &txs {
|
||||||
indexer.append(self.index.index_tx(tx));
|
indexer.merge(self.index.index_tx(tx));
|
||||||
}
|
}
|
||||||
|
|
||||||
let graph = self.graph.batch_insert_unconfirmed(
|
let graph = self.graph.batch_insert_unconfirmed(
|
||||||
@ -210,7 +210,7 @@ where
|
|||||||
/// Methods are available if the anchor (`A`) implements [`AnchorFromBlockPosition`].
|
/// Methods are available if the anchor (`A`) implements [`AnchorFromBlockPosition`].
|
||||||
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
|
||||||
where
|
where
|
||||||
I::ChangeSet: Default + Append,
|
I::ChangeSet: Default + Merge,
|
||||||
A: AnchorFromBlockPosition,
|
A: AnchorFromBlockPosition,
|
||||||
{
|
{
|
||||||
/// Batch insert all transactions of the given `block` of `height`, filtering out those that are
|
/// Batch insert all transactions of the given `block` of `height`, filtering out those that are
|
||||||
@ -232,14 +232,14 @@ where
|
|||||||
};
|
};
|
||||||
let mut changeset = ChangeSet::<A, I::ChangeSet>::default();
|
let mut changeset = ChangeSet::<A, I::ChangeSet>::default();
|
||||||
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
||||||
changeset.indexer.append(self.index.index_tx(tx));
|
changeset.indexer.merge(self.index.index_tx(tx));
|
||||||
if self.index.is_tx_relevant(tx) {
|
if self.index.is_tx_relevant(tx) {
|
||||||
let txid = tx.compute_txid();
|
let txid = tx.compute_txid();
|
||||||
let anchor = A::from_block_position(block, block_id, tx_pos);
|
let anchor = A::from_block_position(block, block_id, tx_pos);
|
||||||
changeset.graph.append(self.graph.insert_tx(tx.clone()));
|
changeset.graph.merge(self.graph.insert_tx(tx.clone()));
|
||||||
changeset
|
changeset
|
||||||
.graph
|
.graph
|
||||||
.append(self.graph.insert_anchor(txid, anchor));
|
.merge(self.graph.insert_anchor(txid, anchor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changeset
|
changeset
|
||||||
@ -261,8 +261,8 @@ where
|
|||||||
let mut graph = tx_graph::ChangeSet::default();
|
let mut graph = tx_graph::ChangeSet::default();
|
||||||
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
for (tx_pos, tx) in block.txdata.iter().enumerate() {
|
||||||
let anchor = A::from_block_position(&block, block_id, tx_pos);
|
let anchor = A::from_block_position(&block, block_id, tx_pos);
|
||||||
graph.append(self.graph.insert_anchor(tx.compute_txid(), anchor));
|
graph.merge(self.graph.insert_anchor(tx.compute_txid(), anchor));
|
||||||
graph.append(self.graph.insert_tx(tx.clone()));
|
graph.merge(self.graph.insert_tx(tx.clone()));
|
||||||
}
|
}
|
||||||
let indexer = self.index_tx_graph_changeset(&graph);
|
let indexer = self.index_tx_graph_changeset(&graph);
|
||||||
ChangeSet { graph, indexer }
|
ChangeSet { graph, indexer }
|
||||||
@ -299,10 +299,10 @@ impl<A, IA: Default> Default for ChangeSet<A, IA> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Anchor, IA: Append> Append for ChangeSet<A, IA> {
|
impl<A: Anchor, IA: Merge> Merge for ChangeSet<A, IA> {
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
self.graph.append(other.graph);
|
self.graph.merge(other.graph);
|
||||||
self.indexer.append(other.indexer);
|
self.indexer.merge(other.indexer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
|
@ -14,7 +14,7 @@ use core::{
|
|||||||
ops::{Bound, RangeBounds},
|
ops::{Bound, RangeBounds},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::Append;
|
use crate::Merge;
|
||||||
|
|
||||||
/// The default lookahead for a [`KeychainTxOutIndex`]
|
/// The default lookahead for a [`KeychainTxOutIndex`]
|
||||||
pub const DEFAULT_LOOKAHEAD: u32 = 25;
|
pub const DEFAULT_LOOKAHEAD: u32 = 25;
|
||||||
@ -157,7 +157,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
|
|||||||
let mut changeset = ChangeSet::<K>::default();
|
let mut changeset = ChangeSet::<K>::default();
|
||||||
let txid = tx.compute_txid();
|
let txid = tx.compute_txid();
|
||||||
for (op, txout) in tx.output.iter().enumerate() {
|
for (op, txout) in tx.output.iter().enumerate() {
|
||||||
changeset.append(self.index_txout(OutPoint::new(txid, op as u32), txout));
|
changeset.merge(self.index_txout(OutPoint::new(txid, op as u32), txout));
|
||||||
}
|
}
|
||||||
changeset
|
changeset
|
||||||
}
|
}
|
||||||
@ -632,7 +632,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
|
|||||||
|
|
||||||
for (keychain, &index) in keychains {
|
for (keychain, &index) in keychains {
|
||||||
if let Some((_, new_changeset)) = self.reveal_to_target(keychain, index) {
|
if let Some((_, new_changeset)) = self.reveal_to_target(keychain, index) {
|
||||||
changeset.append(new_changeset);
|
changeset.merge(new_changeset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,7 +666,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
|
|||||||
match self.reveal_next_spk(keychain) {
|
match self.reveal_next_spk(keychain) {
|
||||||
Some(((i, spk), change)) => {
|
Some(((i, spk), change)) => {
|
||||||
spks.push((i, spk));
|
spks.push((i, spk));
|
||||||
changeset.append(change);
|
changeset.merge(change);
|
||||||
}
|
}
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
@ -856,12 +856,12 @@ impl<K: core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
|
|||||||
///
|
///
|
||||||
/// It can be applied to [`KeychainTxOutIndex`] with [`apply_changeset`].
|
/// It can be applied to [`KeychainTxOutIndex`] with [`apply_changeset`].
|
||||||
///
|
///
|
||||||
/// The `last_revealed` field is monotone in that [`append`] will never decrease it.
|
/// The `last_revealed` field is monotone in that [`merge`] will never decrease it.
|
||||||
/// `keychains_added` is *not* monotone, once it is set any attempt to change it is subject to the
|
/// `keychains_added` is *not* monotone, once it is set any attempt to change it is subject to the
|
||||||
/// same *one-to-one* keychain <-> descriptor mapping invariant as [`KeychainTxOutIndex`] itself.
|
/// same *one-to-one* keychain <-> descriptor mapping invariant as [`KeychainTxOutIndex`] itself.
|
||||||
///
|
///
|
||||||
/// [`apply_changeset`]: KeychainTxOutIndex::apply_changeset
|
/// [`apply_changeset`]: KeychainTxOutIndex::apply_changeset
|
||||||
/// [`append`]: Self::append
|
/// [`Merge`]: Self::merge
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde",
|
feature = "serde",
|
||||||
@ -882,14 +882,14 @@ pub struct ChangeSet<K> {
|
|||||||
pub last_revealed: BTreeMap<DescriptorId, u32>,
|
pub last_revealed: BTreeMap<DescriptorId, u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord> Append for ChangeSet<K> {
|
impl<K: Ord> Merge for ChangeSet<K> {
|
||||||
/// Merge another [`ChangeSet<K>`] into self.
|
/// Merge another [`ChangeSet<K>`] into self.
|
||||||
///
|
///
|
||||||
/// For the `keychains_added` field this method respects the invariants of
|
/// For the `keychains_added` field this method respects the invariants of
|
||||||
/// [`insert_descriptor`]. `last_revealed` always becomes the larger of the two.
|
/// [`insert_descriptor`]. `last_revealed` always becomes the larger of the two.
|
||||||
///
|
///
|
||||||
/// [`insert_descriptor`]: KeychainTxOutIndex::insert_descriptor
|
/// [`insert_descriptor`]: KeychainTxOutIndex::insert_descriptor
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
for (new_keychain, new_descriptor) in other.keychains_added {
|
for (new_keychain, new_descriptor) in other.keychains_added {
|
||||||
// enforce 1-to-1 invariance
|
// enforce 1-to-1 invariance
|
||||||
if !self.keychains_added.contains_key(&new_keychain)
|
if !self.keychains_added.contains_key(&new_keychain)
|
||||||
|
@ -113,10 +113,10 @@ pub trait AnchorFromBlockPosition: Anchor {
|
|||||||
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, tx_pos: usize) -> Self;
|
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, tx_pos: usize) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait that makes an object appendable.
|
/// Trait that makes an object mergeable.
|
||||||
pub trait Append: Default {
|
pub trait Merge: Default {
|
||||||
/// Append another object of the same type onto `self`.
|
/// Merge another object of the same type onto `self`.
|
||||||
fn append(&mut self, other: Self);
|
fn merge(&mut self, other: Self);
|
||||||
|
|
||||||
/// Returns whether the structure is considered empty.
|
/// Returns whether the structure is considered empty.
|
||||||
fn is_empty(&self) -> bool;
|
fn is_empty(&self) -> bool;
|
||||||
@ -131,8 +131,8 @@ pub trait Append: Default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: Ord, V> Append for BTreeMap<K, V> {
|
impl<K: Ord, V> Merge for BTreeMap<K, V> {
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
||||||
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
||||||
BTreeMap::extend(self, other)
|
BTreeMap::extend(self, other)
|
||||||
@ -143,8 +143,8 @@ impl<K: Ord, V> Append for BTreeMap<K, V> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Ord> Append for BTreeSet<T> {
|
impl<T: Ord> Merge for BTreeSet<T> {
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
||||||
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
||||||
BTreeSet::extend(self, other)
|
BTreeSet::extend(self, other)
|
||||||
@ -155,8 +155,8 @@ impl<T: Ord> Append for BTreeSet<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Append for Vec<T> {
|
impl<T> Merge for Vec<T> {
|
||||||
fn append(&mut self, mut other: Self) {
|
fn merge(&mut self, mut other: Self) {
|
||||||
Vec::append(self, &mut other)
|
Vec::append(self, &mut other)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,30 +165,30 @@ impl<T> Append for Vec<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_append_for_tuple {
|
macro_rules! impl_merge_for_tuple {
|
||||||
($($a:ident $b:tt)*) => {
|
($($a:ident $b:tt)*) => {
|
||||||
impl<$($a),*> Append for ($($a,)*) where $($a: Append),* {
|
impl<$($a),*> Merge for ($($a,)*) where $($a: Merge),* {
|
||||||
|
|
||||||
fn append(&mut self, _other: Self) {
|
fn merge(&mut self, _other: Self) {
|
||||||
$(Append::append(&mut self.$b, _other.$b) );*
|
$(Merge::merge(&mut self.$b, _other.$b) );*
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
$(Append::is_empty(&self.$b) && )* true
|
$(Merge::is_empty(&self.$b) && )* true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_append_for_tuple!();
|
impl_merge_for_tuple!();
|
||||||
impl_append_for_tuple!(T0 0);
|
impl_merge_for_tuple!(T0 0);
|
||||||
impl_append_for_tuple!(T0 0 T1 1);
|
impl_merge_for_tuple!(T0 0 T1 1);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
|
||||||
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10);
|
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9 T10 10);
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together.
|
//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! # use bdk_chain::{Append, BlockId};
|
//! # use bdk_chain::{Merge, BlockId};
|
||||||
//! # use bdk_chain::tx_graph::TxGraph;
|
//! # use bdk_chain::tx_graph::TxGraph;
|
||||||
//! # use bdk_chain::example_utils::*;
|
//! # use bdk_chain::example_utils::*;
|
||||||
//! # use bitcoin::Transaction;
|
//! # use bitcoin::Transaction;
|
||||||
@ -89,7 +89,7 @@
|
|||||||
//! [`insert_txout`]: TxGraph::insert_txout
|
//! [`insert_txout`]: TxGraph::insert_txout
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
collections::*, Anchor, Append, Balance, BlockId, ChainOracle, ChainPosition, FullTxOut,
|
collections::*, Anchor, Balance, BlockId, ChainOracle, ChainPosition, FullTxOut, Merge,
|
||||||
};
|
};
|
||||||
use alloc::collections::vec_deque::VecDeque;
|
use alloc::collections::vec_deque::VecDeque;
|
||||||
use alloc::sync::Arc;
|
use alloc::sync::Arc;
|
||||||
@ -547,8 +547,8 @@ impl<A: Clone + Ord> TxGraph<A> {
|
|||||||
) -> ChangeSet<A> {
|
) -> ChangeSet<A> {
|
||||||
let mut changeset = ChangeSet::<A>::default();
|
let mut changeset = ChangeSet::<A>::default();
|
||||||
for (tx, seen_at) in txs {
|
for (tx, seen_at) in txs {
|
||||||
changeset.append(self.insert_seen_at(tx.compute_txid(), seen_at));
|
changeset.merge(self.insert_seen_at(tx.compute_txid(), seen_at));
|
||||||
changeset.append(self.insert_tx(tx));
|
changeset.merge(self.insert_tx(tx));
|
||||||
}
|
}
|
||||||
changeset
|
changeset
|
||||||
}
|
}
|
||||||
@ -630,7 +630,7 @@ impl<A: Clone + Ord> TxGraph<A> {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for txid in unanchored_txs {
|
for txid in unanchored_txs {
|
||||||
changeset.append(self.insert_seen_at(txid, seen_at));
|
changeset.merge(self.insert_seen_at(txid, seen_at));
|
||||||
}
|
}
|
||||||
changeset
|
changeset
|
||||||
}
|
}
|
||||||
@ -1293,8 +1293,8 @@ impl<A> ChangeSet<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: Ord> Append for ChangeSet<A> {
|
impl<A: Ord> Merge for ChangeSet<A> {
|
||||||
fn append(&mut self, other: Self) {
|
fn merge(&mut self, other: Self) {
|
||||||
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
|
||||||
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
|
||||||
self.txs.extend(other.txs);
|
self.txs.extend(other.txs);
|
||||||
|
@ -10,7 +10,7 @@ use bdk_chain::{
|
|||||||
indexed_tx_graph::{self, IndexedTxGraph},
|
indexed_tx_graph::{self, IndexedTxGraph},
|
||||||
indexer::keychain_txout::KeychainTxOutIndex,
|
indexer::keychain_txout::KeychainTxOutIndex,
|
||||||
local_chain::LocalChain,
|
local_chain::LocalChain,
|
||||||
tx_graph, Append, Balance, ChainPosition, ConfirmationHeightAnchor, DescriptorExt,
|
tx_graph, Balance, ChainPosition, ConfirmationHeightAnchor, DescriptorExt, Merge,
|
||||||
};
|
};
|
||||||
use bitcoin::{
|
use bitcoin::{
|
||||||
secp256k1::Secp256k1, Amount, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut,
|
secp256k1::Secp256k1, Amount, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut,
|
||||||
|
@ -5,7 +5,7 @@ mod common;
|
|||||||
use bdk_chain::{
|
use bdk_chain::{
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
indexer::keychain_txout::{ChangeSet, KeychainTxOutIndex},
|
indexer::keychain_txout::{ChangeSet, KeychainTxOutIndex},
|
||||||
Append, DescriptorExt, DescriptorId, Indexer,
|
DescriptorExt, DescriptorId, Indexer, Merge,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bitcoin::{secp256k1::Secp256k1, Amount, OutPoint, ScriptBuf, Transaction, TxOut};
|
use bitcoin::{secp256k1::Secp256k1, Amount, OutPoint, ScriptBuf, Transaction, TxOut};
|
||||||
@ -51,13 +51,13 @@ fn spk_at_index(descriptor: &Descriptor<DescriptorPublicKey>, index: u32) -> Scr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We create two empty changesets lhs and rhs, we then insert various descriptors with various
|
// We create two empty changesets lhs and rhs, we then insert various descriptors with various
|
||||||
// last_revealed, append rhs to lhs, and check that the result is consistent with these rules:
|
// last_revealed, merge rhs to lhs, and check that the result is consistent with these rules:
|
||||||
// - Existing index doesn't update if the new index in `other` is lower than `self`.
|
// - Existing index doesn't update if the new index in `other` is lower than `self`.
|
||||||
// - Existing index updates if the new index in `other` is higher than `self`.
|
// - Existing index updates if the new index in `other` is higher than `self`.
|
||||||
// - Existing index is unchanged if keychain doesn't exist in `other`.
|
// - Existing index is unchanged if keychain doesn't exist in `other`.
|
||||||
// - New keychain gets added if the keychain is in `other` but not in `self`.
|
// - New keychain gets added if the keychain is in `other` but not in `self`.
|
||||||
#[test]
|
#[test]
|
||||||
fn append_changesets_check_last_revealed() {
|
fn merge_changesets_check_last_revealed() {
|
||||||
let secp = bitcoin::secp256k1::Secp256k1::signing_only();
|
let secp = bitcoin::secp256k1::Secp256k1::signing_only();
|
||||||
let descriptor_ids: Vec<_> = DESCRIPTORS
|
let descriptor_ids: Vec<_> = DESCRIPTORS
|
||||||
.iter()
|
.iter()
|
||||||
@ -88,7 +88,7 @@ fn append_changesets_check_last_revealed() {
|
|||||||
keychains_added: BTreeMap::<(), _>::new(),
|
keychains_added: BTreeMap::<(), _>::new(),
|
||||||
last_revealed: rhs_di,
|
last_revealed: rhs_di,
|
||||||
};
|
};
|
||||||
lhs.append(rhs);
|
lhs.merge(rhs);
|
||||||
|
|
||||||
// Existing index doesn't update if the new index in `other` is lower than `self`.
|
// Existing index doesn't update if the new index in `other` is lower than `self`.
|
||||||
assert_eq!(lhs.last_revealed.get(&descriptor_ids[0]), Some(&7));
|
assert_eq!(lhs.last_revealed.get(&descriptor_ids[0]), Some(&7));
|
||||||
@ -677,7 +677,7 @@ fn applying_changesets_one_by_one_vs_aggregate_must_have_same_result() {
|
|||||||
.iter()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
.reduce(|mut agg, cs| {
|
.reduce(|mut agg, cs| {
|
||||||
agg.append(cs);
|
agg.merge(cs);
|
||||||
agg
|
agg
|
||||||
})
|
})
|
||||||
.expect("must aggregate changesets");
|
.expect("must aggregate changesets");
|
||||||
|
@ -7,7 +7,7 @@ use bdk_chain::{
|
|||||||
collections::*,
|
collections::*,
|
||||||
local_chain::LocalChain,
|
local_chain::LocalChain,
|
||||||
tx_graph::{ChangeSet, TxGraph},
|
tx_graph::{ChangeSet, TxGraph},
|
||||||
Anchor, Append, BlockId, ChainOracle, ChainPosition, ConfirmationHeightAnchor,
|
Anchor, BlockId, ChainOracle, ChainPosition, ConfirmationHeightAnchor, Merge,
|
||||||
};
|
};
|
||||||
use bitcoin::{
|
use bitcoin::{
|
||||||
absolute, hashes::Hash, transaction, Amount, BlockHash, OutPoint, ScriptBuf, SignedAmount,
|
absolute, hashes::Hash, transaction, Amount, BlockHash, OutPoint, ScriptBuf, SignedAmount,
|
||||||
@ -1049,9 +1049,9 @@ fn test_chain_spends() {
|
|||||||
.is_none());
|
.is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure that `last_seen` values only increase during [`Append::append`].
|
/// Ensure that `last_seen` values only increase during [`Merge::merge`].
|
||||||
#[test]
|
#[test]
|
||||||
fn test_changeset_last_seen_append() {
|
fn test_changeset_last_seen_merge() {
|
||||||
let txid: Txid = h!("test txid");
|
let txid: Txid = h!("test txid");
|
||||||
|
|
||||||
let test_cases: &[(Option<u64>, Option<u64>)] = &[
|
let test_cases: &[(Option<u64>, Option<u64>)] = &[
|
||||||
@ -1074,7 +1074,7 @@ fn test_changeset_last_seen_append() {
|
|||||||
};
|
};
|
||||||
assert!(!update.is_empty() || update_ls.is_none());
|
assert!(!update.is_empty() || update_ls.is_none());
|
||||||
|
|
||||||
original.append(update);
|
original.merge(update);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
&original.last_seen.get(&txid).cloned(),
|
&original.last_seen.get(&txid).cloned(),
|
||||||
Ord::max(original_ls, update_ls),
|
Ord::max(original_ls, update_ls),
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::{bincode_options, EntryIter, FileError, IterError};
|
use crate::{bincode_options, EntryIter, FileError, IterError};
|
||||||
use bdk_chain::Append;
|
use bdk_chain::Merge;
|
||||||
use bincode::Options;
|
use bincode::Options;
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Debug},
|
fmt::{self, Debug},
|
||||||
@ -22,7 +22,7 @@ where
|
|||||||
|
|
||||||
impl<C> Store<C>
|
impl<C> Store<C>
|
||||||
where
|
where
|
||||||
C: Append
|
C: Merge
|
||||||
+ serde::Serialize
|
+ serde::Serialize
|
||||||
+ serde::de::DeserializeOwned
|
+ serde::de::DeserializeOwned
|
||||||
+ core::marker::Send
|
+ core::marker::Send
|
||||||
@ -147,7 +147,7 @@ where
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
match &mut changeset {
|
match &mut changeset {
|
||||||
Some(changeset) => changeset.append(next_changeset),
|
Some(changeset) => changeset.merge(next_changeset),
|
||||||
changeset => *changeset = Some(next_changeset),
|
changeset => *changeset = Some(next_changeset),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -365,7 +365,7 @@ mod test {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.changeset,
|
err.changeset,
|
||||||
changesets.iter().cloned().reduce(|mut acc, cs| {
|
changesets.iter().cloned().reduce(|mut acc, cs| {
|
||||||
Append::append(&mut acc, cs);
|
Merge::merge(&mut acc, cs);
|
||||||
acc
|
acc
|
||||||
}),
|
}),
|
||||||
"should recover all changesets that are written in full",
|
"should recover all changesets that are written in full",
|
||||||
@ -386,7 +386,7 @@ mod test {
|
|||||||
.cloned()
|
.cloned()
|
||||||
.chain(core::iter::once(last_changeset.clone()))
|
.chain(core::iter::once(last_changeset.clone()))
|
||||||
.reduce(|mut acc, cs| {
|
.reduce(|mut acc, cs| {
|
||||||
Append::append(&mut acc, cs);
|
Merge::merge(&mut acc, cs);
|
||||||
acc
|
acc
|
||||||
}),
|
}),
|
||||||
"should recover all changesets",
|
"should recover all changesets",
|
||||||
@ -422,13 +422,13 @@ mod test {
|
|||||||
.take(read_count)
|
.take(read_count)
|
||||||
.map(|r| r.expect("must read valid changeset"))
|
.map(|r| r.expect("must read valid changeset"))
|
||||||
.fold(TestChangeSet::default(), |mut acc, v| {
|
.fold(TestChangeSet::default(), |mut acc, v| {
|
||||||
Append::append(&mut acc, v);
|
Merge::merge(&mut acc, v);
|
||||||
acc
|
acc
|
||||||
});
|
});
|
||||||
// We write after a short read.
|
// We write after a short read.
|
||||||
db.append_changeset(&last_changeset)
|
db.append_changeset(&last_changeset)
|
||||||
.expect("last write must succeed");
|
.expect("last write must succeed");
|
||||||
Append::append(&mut exp_aggregation, last_changeset.clone());
|
Merge::merge(&mut exp_aggregation, last_changeset.clone());
|
||||||
drop(db);
|
drop(db);
|
||||||
|
|
||||||
// We open the file again and check whether aggregate changeset is expected.
|
// We open the file again and check whether aggregate changeset is expected.
|
||||||
|
@ -14,8 +14,8 @@ use std::sync::{Arc, Mutex};
|
|||||||
use crate::Error;
|
use crate::Error;
|
||||||
use bdk_chain::CombinedChangeSet;
|
use bdk_chain::CombinedChangeSet;
|
||||||
use bdk_chain::{
|
use bdk_chain::{
|
||||||
indexed_tx_graph, indexer::keychain_txout, local_chain, tx_graph, Anchor, Append,
|
indexed_tx_graph, indexer::keychain_txout, local_chain, tx_graph, Anchor, DescriptorExt,
|
||||||
DescriptorExt, DescriptorId,
|
DescriptorId, Merge,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Persists data in to a relational schema based [SQLite] database file.
|
/// Persists data in to a relational schema based [SQLite] database file.
|
||||||
@ -538,7 +538,7 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::store::Append;
|
use crate::store::Merge;
|
||||||
use bdk_chain::bitcoin::consensus::encode::deserialize;
|
use bdk_chain::bitcoin::consensus::encode::deserialize;
|
||||||
use bdk_chain::bitcoin::constants::genesis_block;
|
use bdk_chain::bitcoin::constants::genesis_block;
|
||||||
use bdk_chain::bitcoin::hashes::hex::FromHex;
|
use bdk_chain::bitcoin::hashes::hex::FromHex;
|
||||||
@ -750,7 +750,7 @@ mod test {
|
|||||||
changesets
|
changesets
|
||||||
.iter()
|
.iter()
|
||||||
.fold(CombinedChangeSet::<Keychain, A>::default(), |mut i, cs| {
|
.fold(CombinedChangeSet::<Keychain, A>::default(), |mut i, cs| {
|
||||||
i.append(cs.clone());
|
i.merge(cs.clone());
|
||||||
i
|
i
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ use bdk_chain::{
|
|||||||
},
|
},
|
||||||
spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
|
spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult},
|
||||||
tx_graph::{CanonicalTx, TxGraph, TxNode},
|
tx_graph::{CanonicalTx, TxGraph, TxNode},
|
||||||
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeHeightAnchor, FullTxOut,
|
BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeHeightAnchor, FullTxOut, Indexed,
|
||||||
Indexed, IndexedTxGraph,
|
IndexedTxGraph, Merge,
|
||||||
};
|
};
|
||||||
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
|
use bitcoin::sighash::{EcdsaSighashType, TapSighashType};
|
||||||
use bitcoin::{
|
use bitcoin::{
|
||||||
@ -666,7 +666,7 @@ impl Wallet {
|
|||||||
.reveal_next_spk(&keychain)
|
.reveal_next_spk(&keychain)
|
||||||
.expect("keychain must exist");
|
.expect("keychain must exist");
|
||||||
|
|
||||||
stage.append(indexed_tx_graph::ChangeSet::from(index_changeset).into());
|
stage.merge(indexed_tx_graph::ChangeSet::from(index_changeset).into());
|
||||||
|
|
||||||
AddressInfo {
|
AddressInfo {
|
||||||
index,
|
index,
|
||||||
@ -696,7 +696,7 @@ impl Wallet {
|
|||||||
.reveal_to_target(&keychain, index)
|
.reveal_to_target(&keychain, index)
|
||||||
.expect("keychain must exist");
|
.expect("keychain must exist");
|
||||||
|
|
||||||
self.stage.append(index_changeset.into());
|
self.stage.merge(index_changeset.into());
|
||||||
|
|
||||||
spks.into_iter().map(move |(index, spk)| AddressInfo {
|
spks.into_iter().map(move |(index, spk)| AddressInfo {
|
||||||
index,
|
index,
|
||||||
@ -721,7 +721,7 @@ impl Wallet {
|
|||||||
.expect("keychain must exist");
|
.expect("keychain must exist");
|
||||||
|
|
||||||
self.stage
|
self.stage
|
||||||
.append(indexed_tx_graph::ChangeSet::from(index_changeset).into());
|
.merge(indexed_tx_graph::ChangeSet::from(index_changeset).into());
|
||||||
|
|
||||||
AddressInfo {
|
AddressInfo {
|
||||||
index,
|
index,
|
||||||
@ -880,7 +880,7 @@ impl Wallet {
|
|||||||
/// [`list_output`]: Self::list_output
|
/// [`list_output`]: Self::list_output
|
||||||
pub fn insert_txout(&mut self, outpoint: OutPoint, txout: TxOut) {
|
pub fn insert_txout(&mut self, outpoint: OutPoint, txout: TxOut) {
|
||||||
let additions = self.indexed_graph.insert_txout(outpoint, txout);
|
let additions = self.indexed_graph.insert_txout(outpoint, txout);
|
||||||
self.stage.append(additions.into());
|
self.stage.merge(additions.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculates the fee of a given transaction. Returns [`Amount::ZERO`] if `tx` is a coinbase transaction.
|
/// Calculates the fee of a given transaction. Returns [`Amount::ZERO`] if `tx` is a coinbase transaction.
|
||||||
@ -1049,7 +1049,7 @@ impl Wallet {
|
|||||||
) -> Result<bool, local_chain::AlterCheckPointError> {
|
) -> Result<bool, local_chain::AlterCheckPointError> {
|
||||||
let changeset = self.chain.insert_block(block_id)?;
|
let changeset = self.chain.insert_block(block_id)?;
|
||||||
let changed = !changeset.is_empty();
|
let changed = !changeset.is_empty();
|
||||||
self.stage.append(changeset.into());
|
self.stage.merge(changeset.into());
|
||||||
Ok(changed)
|
Ok(changed)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1067,9 +1067,9 @@ impl Wallet {
|
|||||||
/// must be broadcast to the network and the wallet synced via a chain source.
|
/// must be broadcast to the network and the wallet synced via a chain source.
|
||||||
pub fn insert_tx(&mut self, tx: Transaction) -> bool {
|
pub fn insert_tx(&mut self, tx: Transaction) -> bool {
|
||||||
let mut changeset = ChangeSet::default();
|
let mut changeset = ChangeSet::default();
|
||||||
changeset.append(self.indexed_graph.insert_tx(tx).into());
|
changeset.merge(self.indexed_graph.insert_tx(tx).into());
|
||||||
let ret = !changeset.is_empty();
|
let ret = !changeset.is_empty();
|
||||||
self.stage.append(changeset);
|
self.stage.merge(changeset);
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1394,7 +1394,7 @@ impl Wallet {
|
|||||||
.next_unused_spk(&change_keychain)
|
.next_unused_spk(&change_keychain)
|
||||||
.expect("keychain must exist");
|
.expect("keychain must exist");
|
||||||
self.indexed_graph.index.mark_used(change_keychain, index);
|
self.indexed_graph.index.mark_used(change_keychain, index);
|
||||||
self.stage.append(index_changeset.into());
|
self.stage.merge(index_changeset.into());
|
||||||
spk
|
spk
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2230,9 +2230,9 @@ impl Wallet {
|
|||||||
.indexed_graph
|
.indexed_graph
|
||||||
.index
|
.index
|
||||||
.reveal_to_target_multi(&update.last_active_indices);
|
.reveal_to_target_multi(&update.last_active_indices);
|
||||||
changeset.append(index_changeset.into());
|
changeset.merge(index_changeset.into());
|
||||||
changeset.append(self.indexed_graph.apply_update(update.graph).into());
|
changeset.merge(self.indexed_graph.apply_update(update.graph).into());
|
||||||
self.stage.append(changeset);
|
self.stage.merge(changeset);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2317,17 +2317,17 @@ impl Wallet {
|
|||||||
connected_to: BlockId,
|
connected_to: BlockId,
|
||||||
) -> Result<(), ApplyHeaderError> {
|
) -> Result<(), ApplyHeaderError> {
|
||||||
let mut changeset = ChangeSet::default();
|
let mut changeset = ChangeSet::default();
|
||||||
changeset.append(
|
changeset.merge(
|
||||||
self.chain
|
self.chain
|
||||||
.apply_header_connected_to(&block.header, height, connected_to)?
|
.apply_header_connected_to(&block.header, height, connected_to)?
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
changeset.append(
|
changeset.merge(
|
||||||
self.indexed_graph
|
self.indexed_graph
|
||||||
.apply_block_relevant(block, height)
|
.apply_block_relevant(block, height)
|
||||||
.into(),
|
.into(),
|
||||||
);
|
);
|
||||||
self.stage.append(changeset);
|
self.stage.merge(changeset);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2350,7 +2350,7 @@ impl Wallet {
|
|||||||
let indexed_graph_changeset = self
|
let indexed_graph_changeset = self
|
||||||
.indexed_graph
|
.indexed_graph
|
||||||
.batch_insert_relevant_unconfirmed(unconfirmed_txs);
|
.batch_insert_relevant_unconfirmed(unconfirmed_txs);
|
||||||
self.stage.append(indexed_graph_changeset.into());
|
self.stage.merge(indexed_graph_changeset.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ use bdk_chain::{
|
|||||||
indexed_tx_graph,
|
indexed_tx_graph,
|
||||||
indexer::keychain_txout,
|
indexer::keychain_txout,
|
||||||
local_chain::{self, LocalChain},
|
local_chain::{self, LocalChain},
|
||||||
Append, ConfirmationTimeHeightAnchor, IndexedTxGraph,
|
ConfirmationTimeHeightAnchor, IndexedTxGraph, Merge,
|
||||||
};
|
};
|
||||||
use example_cli::{
|
use example_cli::{
|
||||||
anyhow,
|
anyhow,
|
||||||
@ -191,7 +191,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.apply_update(emission.checkpoint)
|
.apply_update(emission.checkpoint)
|
||||||
.expect("must always apply as we receive blocks in order from emitter");
|
.expect("must always apply as we receive blocks in order from emitter");
|
||||||
let graph_changeset = graph.apply_block_relevant(&emission.block, height);
|
let graph_changeset = graph.apply_block_relevant(&emission.block, height);
|
||||||
db_stage.append((chain_changeset, graph_changeset));
|
db_stage.merge((chain_changeset, graph_changeset));
|
||||||
|
|
||||||
// commit staged db changes in intervals
|
// commit staged db changes in intervals
|
||||||
if last_db_commit.elapsed() >= DB_COMMIT_DELAY {
|
if last_db_commit.elapsed() >= DB_COMMIT_DELAY {
|
||||||
@ -235,7 +235,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
);
|
);
|
||||||
{
|
{
|
||||||
let db = &mut *db.lock().unwrap();
|
let db = &mut *db.lock().unwrap();
|
||||||
db_stage.append((local_chain::ChangeSet::default(), graph_changeset));
|
db_stage.merge((local_chain::ChangeSet::default(), graph_changeset));
|
||||||
if let Some(changeset) = db_stage.take() {
|
if let Some(changeset) = db_stage.take() {
|
||||||
db.append_changeset(&changeset)?;
|
db.append_changeset(&changeset)?;
|
||||||
}
|
}
|
||||||
@ -321,7 +321,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
db_stage.append(changeset);
|
db_stage.merge(changeset);
|
||||||
|
|
||||||
if last_db_commit.elapsed() >= DB_COMMIT_DELAY {
|
if last_db_commit.elapsed() >= DB_COMMIT_DELAY {
|
||||||
let db = &mut *db.lock().unwrap();
|
let db = &mut *db.lock().unwrap();
|
||||||
|
@ -20,7 +20,7 @@ use bdk_chain::{
|
|||||||
descriptor::{DescriptorSecretKey, KeyMap},
|
descriptor::{DescriptorSecretKey, KeyMap},
|
||||||
Descriptor, DescriptorPublicKey,
|
Descriptor, DescriptorPublicKey,
|
||||||
},
|
},
|
||||||
Anchor, Append, ChainOracle, DescriptorExt, FullTxOut,
|
Anchor, ChainOracle, DescriptorExt, FullTxOut, Merge,
|
||||||
};
|
};
|
||||||
pub use bdk_file_store;
|
pub use bdk_file_store;
|
||||||
pub use clap;
|
pub use clap;
|
||||||
@ -263,7 +263,7 @@ where
|
|||||||
.index
|
.index
|
||||||
.next_unused_spk(&internal_keychain)
|
.next_unused_spk(&internal_keychain)
|
||||||
.expect("Must exist");
|
.expect("Must exist");
|
||||||
changeset.append(change_changeset);
|
changeset.merge(change_changeset);
|
||||||
|
|
||||||
let change_plan = bdk_tmp_plan::plan_satisfaction(
|
let change_plan = bdk_tmp_plan::plan_satisfaction(
|
||||||
&graph
|
&graph
|
||||||
@ -456,7 +456,7 @@ pub fn handle_commands<CS: clap::Subcommand, S: clap::Args, A: Anchor, O: ChainO
|
|||||||
where
|
where
|
||||||
O::Error: std::error::Error + Send + Sync + 'static,
|
O::Error: std::error::Error + Send + Sync + 'static,
|
||||||
C: Default
|
C: Default
|
||||||
+ Append
|
+ Merge
|
||||||
+ DeserializeOwned
|
+ DeserializeOwned
|
||||||
+ Serialize
|
+ Serialize
|
||||||
+ From<KeychainChangeSet<A>>
|
+ From<KeychainChangeSet<A>>
|
||||||
@ -675,7 +675,7 @@ where
|
|||||||
/// The initial state returned by [`init`].
|
/// The initial state returned by [`init`].
|
||||||
pub struct Init<CS: clap::Subcommand, S: clap::Args, C>
|
pub struct Init<CS: clap::Subcommand, S: clap::Args, C>
|
||||||
where
|
where
|
||||||
C: Default + Append + Serialize + DeserializeOwned + Debug + Send + Sync + 'static,
|
C: Default + Merge + Serialize + DeserializeOwned + Debug + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
/// Arguments parsed by the cli.
|
/// Arguments parsed by the cli.
|
||||||
pub args: Args<CS, S>,
|
pub args: Args<CS, S>,
|
||||||
@ -697,7 +697,7 @@ pub fn init<CS: clap::Subcommand, S: clap::Args, C>(
|
|||||||
) -> anyhow::Result<Init<CS, S, C>>
|
) -> anyhow::Result<Init<CS, S, C>>
|
||||||
where
|
where
|
||||||
C: Default
|
C: Default
|
||||||
+ Append
|
+ Merge
|
||||||
+ Serialize
|
+ Serialize
|
||||||
+ DeserializeOwned
|
+ DeserializeOwned
|
||||||
+ Debug
|
+ Debug
|
||||||
|
@ -10,7 +10,7 @@ use bdk_chain::{
|
|||||||
indexer::keychain_txout,
|
indexer::keychain_txout,
|
||||||
local_chain::{self, LocalChain},
|
local_chain::{self, LocalChain},
|
||||||
spk_client::{FullScanRequest, SyncRequest},
|
spk_client::{FullScanRequest, SyncRequest},
|
||||||
Append, ConfirmationHeightAnchor,
|
ConfirmationHeightAnchor, Merge,
|
||||||
};
|
};
|
||||||
use bdk_electrum::{
|
use bdk_electrum::{
|
||||||
electrum_client::{self, Client, ElectrumApi},
|
electrum_client::{self, Client, ElectrumApi},
|
||||||
@ -343,9 +343,9 @@ fn main() -> anyhow::Result<()> {
|
|||||||
indexed_tx_graph::ChangeSet::<ConfirmationHeightAnchor, _>::default();
|
indexed_tx_graph::ChangeSet::<ConfirmationHeightAnchor, _>::default();
|
||||||
if let Some(keychain_update) = keychain_update {
|
if let Some(keychain_update) = keychain_update {
|
||||||
let keychain_changeset = graph.index.reveal_to_target_multi(&keychain_update);
|
let keychain_changeset = graph.index.reveal_to_target_multi(&keychain_update);
|
||||||
indexed_tx_graph_changeset.append(keychain_changeset.into());
|
indexed_tx_graph_changeset.merge(keychain_changeset.into());
|
||||||
}
|
}
|
||||||
indexed_tx_graph_changeset.append(graph.apply_update(graph_update));
|
indexed_tx_graph_changeset.merge(graph.apply_update(graph_update));
|
||||||
|
|
||||||
(chain_changeset, indexed_tx_graph_changeset)
|
(chain_changeset, indexed_tx_graph_changeset)
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ use bdk_chain::{
|
|||||||
indexer::keychain_txout,
|
indexer::keychain_txout,
|
||||||
local_chain::{self, LocalChain},
|
local_chain::{self, LocalChain},
|
||||||
spk_client::{FullScanRequest, SyncRequest},
|
spk_client::{FullScanRequest, SyncRequest},
|
||||||
Append, ConfirmationTimeHeightAnchor,
|
ConfirmationTimeHeightAnchor, Merge,
|
||||||
};
|
};
|
||||||
|
|
||||||
use bdk_esplora::{esplora_client, EsploraExt};
|
use bdk_esplora::{esplora_client, EsploraExt};
|
||||||
@ -208,7 +208,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
.index
|
.index
|
||||||
.reveal_to_target_multi(&update.last_active_indices);
|
.reveal_to_target_multi(&update.last_active_indices);
|
||||||
let mut indexed_tx_graph_changeset = graph.apply_update(update.graph_update);
|
let mut indexed_tx_graph_changeset = graph.apply_update(update.graph_update);
|
||||||
indexed_tx_graph_changeset.append(index_changeset.into());
|
indexed_tx_graph_changeset.merge(index_changeset.into());
|
||||||
indexed_tx_graph_changeset
|
indexed_tx_graph_changeset
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user