Skip to content

Commit 43f093d

Browse files
committed
Merge #1502: chore(chain)!: Rename Append to Merge
962305f 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 962305f Tree-SHA512: 2019d9ed631776850cda39c9a53bdd3660c7f4715d8c418824d8ad13718f2b2fd160159e03fd63743dbf0b9e91cfdfed7e4cd4a591636f67d2aaec419486d136
2 parents db8fbd7 + 962305f commit 43f093d

16 files changed

Lines changed: 117 additions & 117 deletions

File tree

crates/bitcoind_rpc/tests/test_emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bdk_bitcoind_rpc::Emitter;
44
use bdk_chain::{
55
bitcoin::{Address, Amount, Txid},
66
local_chain::{CheckPoint, LocalChain},
7-
Append, Balance, BlockId, IndexedTxGraph, SpkTxOutIndex,
7+
Balance, BlockId, IndexedTxGraph, Merge, SpkTxOutIndex,
88
};
99
use bdk_testenv::{anyhow, TestEnv};
1010
use bitcoin::{hashes::Hash, Block, OutPoint, ScriptBuf, WScriptHash};

crates/chain/src/changeset.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ impl<K, A> core::default::Default for CombinedChangeSet<K, A> {
3434
}
3535

3636
#[cfg(feature = "miniscript")]
37-
impl<K: Ord, A: crate::Anchor> crate::Append for CombinedChangeSet<K, A> {
38-
fn append(&mut self, other: Self) {
39-
crate::Append::append(&mut self.chain, other.chain);
40-
crate::Append::append(&mut self.indexed_tx_graph, other.indexed_tx_graph);
37+
impl<K: Ord, A: crate::Anchor> crate::Merge for CombinedChangeSet<K, A> {
38+
fn merge(&mut self, other: Self) {
39+
crate::Merge::merge(&mut self.chain, other.chain);
40+
crate::Merge::merge(&mut self.indexed_tx_graph, other.indexed_tx_graph);
4141
if other.network.is_some() {
4242
debug_assert!(
4343
self.network.is_none() || self.network == other.network,

crates/chain/src/indexed_tx_graph.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use bitcoin::{Block, OutPoint, Transaction, TxOut, Txid};
55

66
use crate::{
77
tx_graph::{self, TxGraph},
8-
Anchor, AnchorFromBlockPosition, Append, BlockId, Indexer,
8+
Anchor, AnchorFromBlockPosition, BlockId, Indexer, Merge,
99
};
1010

1111
/// The [`IndexedTxGraph`] combines a [`TxGraph`] and an [`Indexer`] implementation.
@@ -67,18 +67,18 @@ impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I> {
6767

6868
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
6969
where
70-
I::ChangeSet: Default + Append,
70+
I::ChangeSet: Default + Merge,
7171
{
7272
fn index_tx_graph_changeset(
7373
&mut self,
7474
tx_graph_changeset: &tx_graph::ChangeSet<A>,
7575
) -> I::ChangeSet {
7676
let mut changeset = I::ChangeSet::default();
7777
for added_tx in &tx_graph_changeset.txs {
78-
changeset.append(self.index.index_tx(added_tx));
78+
changeset.merge(self.index.index_tx(added_tx));
7979
}
8080
for (&added_outpoint, added_txout) in &tx_graph_changeset.txouts {
81-
changeset.append(self.index.index_txout(added_outpoint, added_txout));
81+
changeset.merge(self.index.index_txout(added_outpoint, added_txout));
8282
}
8383
changeset
8484
}
@@ -137,16 +137,16 @@ where
137137

138138
let mut indexer = I::ChangeSet::default();
139139
for (tx, _) in &txs {
140-
indexer.append(self.index.index_tx(tx));
140+
indexer.merge(self.index.index_tx(tx));
141141
}
142142

143143
let mut graph = tx_graph::ChangeSet::default();
144144
for (tx, anchors) in txs {
145145
if self.index.is_tx_relevant(tx) {
146146
let txid = tx.compute_txid();
147-
graph.append(self.graph.insert_tx(tx.clone()));
147+
graph.merge(self.graph.insert_tx(tx.clone()));
148148
for anchor in anchors {
149-
graph.append(self.graph.insert_anchor(txid, anchor));
149+
graph.merge(self.graph.insert_anchor(txid, anchor));
150150
}
151151
}
152152
}
@@ -176,7 +176,7 @@ where
176176

177177
let mut indexer = I::ChangeSet::default();
178178
for (tx, _) in &txs {
179-
indexer.append(self.index.index_tx(tx));
179+
indexer.merge(self.index.index_tx(tx));
180180
}
181181

182182
let graph = self.graph.batch_insert_unconfirmed(
@@ -210,7 +210,7 @@ where
210210
/// Methods are available if the anchor (`A`) implements [`AnchorFromBlockPosition`].
211211
impl<A: Anchor, I: Indexer> IndexedTxGraph<A, I>
212212
where
213-
I::ChangeSet: Default + Append,
213+
I::ChangeSet: Default + Merge,
214214
A: AnchorFromBlockPosition,
215215
{
216216
/// Batch insert all transactions of the given `block` of `height`, filtering out those that are
@@ -232,14 +232,14 @@ where
232232
};
233233
let mut changeset = ChangeSet::<A, I::ChangeSet>::default();
234234
for (tx_pos, tx) in block.txdata.iter().enumerate() {
235-
changeset.indexer.append(self.index.index_tx(tx));
235+
changeset.indexer.merge(self.index.index_tx(tx));
236236
if self.index.is_tx_relevant(tx) {
237237
let txid = tx.compute_txid();
238238
let anchor = A::from_block_position(block, block_id, tx_pos);
239-
changeset.graph.append(self.graph.insert_tx(tx.clone()));
239+
changeset.graph.merge(self.graph.insert_tx(tx.clone()));
240240
changeset
241241
.graph
242-
.append(self.graph.insert_anchor(txid, anchor));
242+
.merge(self.graph.insert_anchor(txid, anchor));
243243
}
244244
}
245245
changeset
@@ -261,8 +261,8 @@ where
261261
let mut graph = tx_graph::ChangeSet::default();
262262
for (tx_pos, tx) in block.txdata.iter().enumerate() {
263263
let anchor = A::from_block_position(&block, block_id, tx_pos);
264-
graph.append(self.graph.insert_anchor(tx.compute_txid(), anchor));
265-
graph.append(self.graph.insert_tx(tx.clone()));
264+
graph.merge(self.graph.insert_anchor(tx.compute_txid(), anchor));
265+
graph.merge(self.graph.insert_tx(tx.clone()));
266266
}
267267
let indexer = self.index_tx_graph_changeset(&graph);
268268
ChangeSet { graph, indexer }
@@ -299,10 +299,10 @@ impl<A, IA: Default> Default for ChangeSet<A, IA> {
299299
}
300300
}
301301

302-
impl<A: Anchor, IA: Append> Append for ChangeSet<A, IA> {
303-
fn append(&mut self, other: Self) {
304-
self.graph.append(other.graph);
305-
self.indexer.append(other.indexer);
302+
impl<A: Anchor, IA: Merge> Merge for ChangeSet<A, IA> {
303+
fn merge(&mut self, other: Self) {
304+
self.graph.merge(other.graph);
305+
self.indexer.merge(other.indexer);
306306
}
307307

308308
fn is_empty(&self) -> bool {

crates/chain/src/indexer/keychain_txout.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::{
1414
ops::{Bound, RangeBounds},
1515
};
1616

17-
use crate::Append;
17+
use crate::Merge;
1818

1919
/// The default lookahead for a [`KeychainTxOutIndex`]
2020
pub const DEFAULT_LOOKAHEAD: u32 = 25;
@@ -157,7 +157,7 @@ impl<K: Clone + Ord + Debug> Indexer for KeychainTxOutIndex<K> {
157157
let mut changeset = ChangeSet::<K>::default();
158158
let txid = tx.compute_txid();
159159
for (op, txout) in tx.output.iter().enumerate() {
160-
changeset.append(self.index_txout(OutPoint::new(txid, op as u32), txout));
160+
changeset.merge(self.index_txout(OutPoint::new(txid, op as u32), txout));
161161
}
162162
changeset
163163
}
@@ -632,7 +632,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
632632

633633
for (keychain, &index) in keychains {
634634
if let Some((_, new_changeset)) = self.reveal_to_target(keychain, index) {
635-
changeset.append(new_changeset);
635+
changeset.merge(new_changeset);
636636
}
637637
}
638638

@@ -666,7 +666,7 @@ impl<K: Clone + Ord + Debug> KeychainTxOutIndex<K> {
666666
match self.reveal_next_spk(keychain) {
667667
Some(((i, spk), change)) => {
668668
spks.push((i, spk));
669-
changeset.append(change);
669+
changeset.merge(change);
670670
}
671671
None => break,
672672
}
@@ -856,12 +856,12 @@ impl<K: core::fmt::Debug> std::error::Error for InsertDescriptorError<K> {}
856856
///
857857
/// It can be applied to [`KeychainTxOutIndex`] with [`apply_changeset`].
858858
///
859-
/// The `last_revealed` field is monotone in that [`append`] will never decrease it.
859+
/// The `last_revealed` field is monotone in that [`merge`] will never decrease it.
860860
/// `keychains_added` is *not* monotone, once it is set any attempt to change it is subject to the
861861
/// same *one-to-one* keychain <-> descriptor mapping invariant as [`KeychainTxOutIndex`] itself.
862862
///
863863
/// [`apply_changeset`]: KeychainTxOutIndex::apply_changeset
864-
/// [`append`]: Self::append
864+
/// [`Merge`]: Self::merge
865865
#[derive(Clone, Debug, PartialEq)]
866866
#[cfg_attr(
867867
feature = "serde",
@@ -882,14 +882,14 @@ pub struct ChangeSet<K> {
882882
pub last_revealed: BTreeMap<DescriptorId, u32>,
883883
}
884884

885-
impl<K: Ord> Append for ChangeSet<K> {
885+
impl<K: Ord> Merge for ChangeSet<K> {
886886
/// Merge another [`ChangeSet<K>`] into self.
887887
///
888888
/// For the `keychains_added` field this method respects the invariants of
889889
/// [`insert_descriptor`]. `last_revealed` always becomes the larger of the two.
890890
///
891891
/// [`insert_descriptor`]: KeychainTxOutIndex::insert_descriptor
892-
fn append(&mut self, other: Self) {
892+
fn merge(&mut self, other: Self) {
893893
for (new_keychain, new_descriptor) in other.keychains_added {
894894
// enforce 1-to-1 invariance
895895
if !self.keychains_added.contains_key(&new_keychain)

crates/chain/src/tx_data_traits.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ pub trait AnchorFromBlockPosition: Anchor {
113113
fn from_block_position(block: &bitcoin::Block, block_id: BlockId, tx_pos: usize) -> Self;
114114
}
115115

116-
/// Trait that makes an object appendable.
117-
pub trait Append: Default {
118-
/// Append another object of the same type onto `self`.
119-
fn append(&mut self, other: Self);
116+
/// Trait that makes an object mergeable.
117+
pub trait Merge: Default {
118+
/// Merge another object of the same type onto `self`.
119+
fn merge(&mut self, other: Self);
120120

121121
/// Returns whether the structure is considered empty.
122122
fn is_empty(&self) -> bool;
@@ -131,8 +131,8 @@ pub trait Append: Default {
131131
}
132132
}
133133

134-
impl<K: Ord, V> Append for BTreeMap<K, V> {
135-
fn append(&mut self, other: Self) {
134+
impl<K: Ord, V> Merge for BTreeMap<K, V> {
135+
fn merge(&mut self, other: Self) {
136136
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
137137
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
138138
BTreeMap::extend(self, other)
@@ -143,8 +143,8 @@ impl<K: Ord, V> Append for BTreeMap<K, V> {
143143
}
144144
}
145145

146-
impl<T: Ord> Append for BTreeSet<T> {
147-
fn append(&mut self, other: Self) {
146+
impl<T: Ord> Merge for BTreeSet<T> {
147+
fn merge(&mut self, other: Self) {
148148
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
149149
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
150150
BTreeSet::extend(self, other)
@@ -155,8 +155,8 @@ impl<T: Ord> Append for BTreeSet<T> {
155155
}
156156
}
157157

158-
impl<T> Append for Vec<T> {
159-
fn append(&mut self, mut other: Self) {
158+
impl<T> Merge for Vec<T> {
159+
fn merge(&mut self, mut other: Self) {
160160
Vec::append(self, &mut other)
161161
}
162162

@@ -165,30 +165,30 @@ impl<T> Append for Vec<T> {
165165
}
166166
}
167167

168-
macro_rules! impl_append_for_tuple {
168+
macro_rules! impl_merge_for_tuple {
169169
($($a:ident $b:tt)*) => {
170-
impl<$($a),*> Append for ($($a,)*) where $($a: Append),* {
170+
impl<$($a),*> Merge for ($($a,)*) where $($a: Merge),* {
171171

172-
fn append(&mut self, _other: Self) {
173-
$(Append::append(&mut self.$b, _other.$b) );*
172+
fn merge(&mut self, _other: Self) {
173+
$(Merge::merge(&mut self.$b, _other.$b) );*
174174
}
175175

176176
fn is_empty(&self) -> bool {
177-
$(Append::is_empty(&self.$b) && )* true
177+
$(Merge::is_empty(&self.$b) && )* true
178178
}
179179
}
180180
}
181181
}
182182

183-
impl_append_for_tuple!();
184-
impl_append_for_tuple!(T0 0);
185-
impl_append_for_tuple!(T0 0 T1 1);
186-
impl_append_for_tuple!(T0 0 T1 1 T2 2);
187-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3);
188-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
189-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
190-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
191-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
192-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
193-
impl_append_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
194-
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);
183+
impl_merge_for_tuple!();
184+
impl_merge_for_tuple!(T0 0);
185+
impl_merge_for_tuple!(T0 0 T1 1);
186+
impl_merge_for_tuple!(T0 0 T1 1 T2 2);
187+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3);
188+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4);
189+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5);
190+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6);
191+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7);
192+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8);
193+
impl_merge_for_tuple!(T0 0 T1 1 T2 2 T3 3 T4 4 T5 5 T6 6 T7 7 T8 8 T9 9);
194+
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);

crates/chain/src/tx_graph.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
//! A [`TxGraph`] can also be updated with another [`TxGraph`] which merges them together.
7070
//!
7171
//! ```
72-
//! # use bdk_chain::{Append, BlockId};
72+
//! # use bdk_chain::{Merge, BlockId};
7373
//! # use bdk_chain::tx_graph::TxGraph;
7474
//! # use bdk_chain::example_utils::*;
7575
//! # use bitcoin::Transaction;
@@ -89,7 +89,7 @@
8989
//! [`insert_txout`]: TxGraph::insert_txout
9090
9191
use crate::{
92-
collections::*, Anchor, Append, Balance, BlockId, ChainOracle, ChainPosition, FullTxOut,
92+
collections::*, Anchor, Balance, BlockId, ChainOracle, ChainPosition, FullTxOut, Merge,
9393
};
9494
use alloc::collections::vec_deque::VecDeque;
9595
use alloc::sync::Arc;
@@ -547,8 +547,8 @@ impl<A: Clone + Ord> TxGraph<A> {
547547
) -> ChangeSet<A> {
548548
let mut changeset = ChangeSet::<A>::default();
549549
for (tx, seen_at) in txs {
550-
changeset.append(self.insert_seen_at(tx.compute_txid(), seen_at));
551-
changeset.append(self.insert_tx(tx));
550+
changeset.merge(self.insert_seen_at(tx.compute_txid(), seen_at));
551+
changeset.merge(self.insert_tx(tx));
552552
}
553553
changeset
554554
}
@@ -630,7 +630,7 @@ impl<A: Clone + Ord> TxGraph<A> {
630630
.collect();
631631

632632
for txid in unanchored_txs {
633-
changeset.append(self.insert_seen_at(txid, seen_at));
633+
changeset.merge(self.insert_seen_at(txid, seen_at));
634634
}
635635
changeset
636636
}
@@ -1293,8 +1293,8 @@ impl<A> ChangeSet<A> {
12931293
}
12941294
}
12951295

1296-
impl<A: Ord> Append for ChangeSet<A> {
1297-
fn append(&mut self, other: Self) {
1296+
impl<A: Ord> Merge for ChangeSet<A> {
1297+
fn merge(&mut self, other: Self) {
12981298
// We use `extend` instead of `BTreeMap::append` due to performance issues with `append`.
12991299
// Refer to https://github.com/rust-lang/rust/issues/34666#issuecomment-675658420
13001300
self.txs.extend(other.txs);

crates/chain/tests/test_indexed_tx_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bdk_chain::{
1010
indexed_tx_graph::{self, IndexedTxGraph},
1111
indexer::keychain_txout::KeychainTxOutIndex,
1212
local_chain::LocalChain,
13-
tx_graph, Append, Balance, ChainPosition, ConfirmationHeightAnchor, DescriptorExt,
13+
tx_graph, Balance, ChainPosition, ConfirmationHeightAnchor, DescriptorExt, Merge,
1414
};
1515
use bitcoin::{
1616
secp256k1::Secp256k1, Amount, OutPoint, Script, ScriptBuf, Transaction, TxIn, TxOut,

0 commit comments

Comments
 (0)