Skip to content

Commit d6bcd9b

Browse files
committed
Merge #1065: refactor!(chain): Unify ChangeSet nomenclature
62f2531 ci: Update tokio version (Daniela Brozzoni) 80f5ecf feat(chain): Add `initial_changeset` to graphs (Daniela Brozzoni) ea50b6a refactor!(chain): Unify ChangeSet nomenclature (Daniela Brozzoni) Pull request description: Solves #1022 ### Changelog notice Rename `indexed_tx_graph::IndexedAdditions` to `indexed_tx_graph::ChangeSet` Rename `indexed_tx_graph::IndexedAdditions::graph_additions` to `indexed_tx_graph::ChangeSet::graph` Rename `indexed_tx_graph::IndexedAdditions::index_additions` to `indexed_tx_graph::ChangeSet::indexer` Rename `tx_graph::Additions` to `tx_graph::ChangeSet` Rename `keychain::DerivationAdditions` to `keychain::ChangeSet` Rename `CanonicalTx::node` to `CanonicalTx::tx_node` Rename `CanonicalTx::observed_as` to `CanonicalTx::chain_position` Rename `LocalChangeSet` to `WalletChangeSet` Rename `LocalChangeSet::chain_changeset` to `WalletChangeSet::chain` Rename `LocalChangeSet::indexed_additions` to `WalletChangeSet::indexed_tx_graph` Rename `LocalUpdate` to `WalletUpdate` Make `TxGraph::determine_changeset` `pub(crate)` Add `TxGraph::initial_changeset` Add `IndexedTxGraph::initial_changeset` Remove `TxGraph::insert_txout_preview` Remove `TxGraph::insert_tx_preview` Remove `insert_anchor_preview` Remove `insert_seen_at_preview` ### Notes to reviewers I'm not sure whether we want to keep `TxGraph::determine_changeset` public or not ### 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: evanlinjin: ACK 62f2531 Tree-SHA512: 401bdf49c5f2082971cfcd54725ce98abd08263de7571205a324a2adbb5359be4f48454def415bedadde0a9c81db437b91c13cd6e892ba54b215059f75006dd5
2 parents 0cd2348 + 62f2531 commit d6bcd9b

File tree

17 files changed

+374
-384
lines changed

17 files changed

+374
-384
lines changed

.github/workflows/cont_integration.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
cargo update -p log --precise "0.4.18"
3434
cargo update -p tempfile --precise "3.6.0"
3535
cargo update -p rustls:0.21.6 --precise "0.21.1"
36-
cargo update -p tokio:1.31.0 --precise "1.29.1"
36+
cargo update -p tokio:1.32.0 --precise "1.29.1"
3737
cargo update -p flate2:1.0.27 --precise "1.0.26"
3838
- name: Build
3939
run: cargo build ${{ matrix.features }}

crates/bdk/src/wallet/export.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,12 @@ impl FullyNodedExport {
126126
Self::is_compatible_with_core(&descriptor)?;
127127

128128
let blockheight = if include_blockheight {
129-
wallet
130-
.transactions()
131-
.next()
132-
.map_or(0, |canonical_tx| match canonical_tx.observed_as {
129+
wallet.transactions().next().map_or(0, |canonical_tx| {
130+
match canonical_tx.chain_position {
133131
bdk_chain::ChainPosition::Confirmed(a) => a.confirmation_height,
134132
bdk_chain::ChainPosition::Unconfirmed(_) => 0,
135-
})
133+
}
134+
})
136135
} else {
137136
0
138137
};

crates/bdk/src/wallet/mod.rs

+30-24
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use alloc::{
2121
};
2222
pub use bdk_chain::keychain::Balance;
2323
use bdk_chain::{
24-
indexed_tx_graph::IndexedAdditions,
25-
keychain::{KeychainTxOutIndex, LocalChangeSet, LocalUpdate},
24+
indexed_tx_graph,
25+
keychain::{KeychainTxOutIndex, WalletChangeSet, WalletUpdate},
2626
local_chain::{self, CannotConnectError, CheckPoint, CheckPointIter, LocalChain},
2727
tx_graph::{CanonicalTx, TxGraph},
2828
Append, BlockId, ChainPosition, ConfirmationTime, ConfirmationTimeAnchor, FullTxOut,
@@ -95,10 +95,10 @@ pub struct Wallet<D = ()> {
9595
}
9696

9797
/// The update to a [`Wallet`] used in [`Wallet::apply_update`]. This is usually returned from blockchain data sources.
98-
pub type Update = LocalUpdate<KeychainKind, ConfirmationTimeAnchor>;
98+
pub type Update = WalletUpdate<KeychainKind, ConfirmationTimeAnchor>;
9999

100100
/// The changeset produced internally by [`Wallet`] when mutated.
101-
pub type ChangeSet = LocalChangeSet<KeychainKind, ConfirmationTimeAnchor>;
101+
pub type ChangeSet = WalletChangeSet<KeychainKind, ConfirmationTimeAnchor>;
102102

103103
/// The address index selection strategy to use to derived an address from the wallet's external
104104
/// descriptor. See [`Wallet::get_address`]. If you're unsure which one to use use `WalletIndex::New`.
@@ -246,8 +246,8 @@ impl<D> Wallet<D> {
246246
};
247247

248248
let changeset = db.load_from_persistence().map_err(NewError::Persist)?;
249-
chain.apply_changeset(&changeset.chain_changeset);
250-
indexed_graph.apply_additions(changeset.indexed_additions);
249+
chain.apply_changeset(&changeset.chain);
250+
indexed_graph.apply_changeset(changeset.index_tx_graph);
251251

252252
let persist = Persist::new(db);
253253

@@ -320,14 +320,14 @@ impl<D> Wallet<D> {
320320
{
321321
let keychain = self.map_keychain(keychain);
322322
let txout_index = &mut self.indexed_graph.index;
323-
let (index, spk, additions) = match address_index {
323+
let (index, spk, changeset) = match address_index {
324324
AddressIndex::New => {
325-
let ((index, spk), index_additions) = txout_index.reveal_next_spk(&keychain);
326-
(index, spk.into(), Some(index_additions))
325+
let ((index, spk), index_changeset) = txout_index.reveal_next_spk(&keychain);
326+
(index, spk.into(), Some(index_changeset))
327327
}
328328
AddressIndex::LastUnused => {
329-
let ((index, spk), index_additions) = txout_index.next_unused_spk(&keychain);
330-
(index, spk.into(), Some(index_additions))
329+
let ((index, spk), index_changeset) = txout_index.next_unused_spk(&keychain);
330+
(index, spk.into(), Some(index_changeset))
331331
}
332332
AddressIndex::Peek(index) => {
333333
let (index, spk) = txout_index
@@ -339,9 +339,11 @@ impl<D> Wallet<D> {
339339
}
340340
};
341341

342-
if let Some(additions) = additions {
342+
if let Some(changeset) = changeset {
343343
self.persist
344-
.stage(ChangeSet::from(IndexedAdditions::from(additions)));
344+
.stage(ChangeSet::from(indexed_tx_graph::ChangeSet::from(
345+
changeset,
346+
)));
345347
self.persist.commit()?;
346348
}
347349

@@ -436,12 +438,12 @@ impl<D> Wallet<D> {
436438
let graph = self.indexed_graph.graph();
437439

438440
let canonical_tx = CanonicalTx {
439-
observed_as: graph.get_chain_position(
441+
chain_position: graph.get_chain_position(
440442
&self.chain,
441443
self.chain.tip().map(|cp| cp.block_id()).unwrap_or_default(),
442444
txid,
443445
)?,
444-
node: graph.get_tx_node(txid)?,
446+
tx_node: graph.get_tx_node(txid)?,
445447
};
446448

447449
Some(new_tx_details(
@@ -889,12 +891,14 @@ impl<D> Wallet<D> {
889891
Some(ref drain_recipient) => drain_recipient.clone(),
890892
None => {
891893
let change_keychain = self.map_keychain(KeychainKind::Internal);
892-
let ((index, spk), index_additions) =
894+
let ((index, spk), index_changeset) =
893895
self.indexed_graph.index.next_unused_spk(&change_keychain);
894896
let spk = spk.into();
895897
self.indexed_graph.index.mark_used(&change_keychain, index);
896898
self.persist
897-
.stage(ChangeSet::from(IndexedAdditions::from(index_additions)));
899+
.stage(ChangeSet::from(indexed_tx_graph::ChangeSet::from(
900+
index_changeset,
901+
)));
898902
self.persist.commit().expect("TODO");
899903
spk
900904
}
@@ -1286,7 +1290,7 @@ impl<D> Wallet<D> {
12861290
.indexed_graph
12871291
.graph()
12881292
.get_chain_position(&self.chain, chain_tip, input.previous_output.txid)
1289-
.map(|observed_as| match observed_as {
1293+
.map(|chain_position| match chain_position {
12901294
ChainPosition::Confirmed(a) => a.confirmation_height,
12911295
ChainPosition::Unconfirmed(_) => u32::MAX,
12921296
});
@@ -1469,7 +1473,7 @@ impl<D> Wallet<D> {
14691473
.graph()
14701474
.get_chain_position(&self.chain, chain_tip, txid)
14711475
{
1472-
Some(observed_as) => observed_as.cloned().into(),
1476+
Some(chain_position) => chain_position.cloned().into(),
14731477
None => return false,
14741478
};
14751479

@@ -1716,11 +1720,13 @@ impl<D> Wallet<D> {
17161720
D: PersistBackend<ChangeSet>,
17171721
{
17181722
let mut changeset = ChangeSet::from(self.chain.apply_update(update.chain)?);
1719-
let (_, index_additions) = self
1723+
let (_, index_changeset) = self
17201724
.indexed_graph
17211725
.index
17221726
.reveal_to_target_multi(&update.last_active_indices);
1723-
changeset.append(ChangeSet::from(IndexedAdditions::from(index_additions)));
1727+
changeset.append(ChangeSet::from(indexed_tx_graph::ChangeSet::from(
1728+
index_changeset,
1729+
)));
17241730
changeset.append(ChangeSet::from(
17251731
self.indexed_graph.apply_update(update.graph),
17261732
));
@@ -1827,7 +1833,7 @@ fn new_tx_details(
18271833
) -> TransactionDetails {
18281834
let graph = indexed_graph.graph();
18291835
let index = &indexed_graph.index;
1830-
let tx = canonical_tx.node.tx;
1836+
let tx = canonical_tx.tx_node.tx;
18311837

18321838
let received = tx
18331839
.output
@@ -1867,11 +1873,11 @@ fn new_tx_details(
18671873

18681874
TransactionDetails {
18691875
transaction: if include_raw { Some(tx.clone()) } else { None },
1870-
txid: canonical_tx.node.txid,
1876+
txid: canonical_tx.tx_node.txid,
18711877
received,
18721878
sent,
18731879
fee,
1874-
confirmation_time: canonical_tx.observed_as.cloned().into(),
1880+
confirmation_time: canonical_tx.chain_position.cloned().into(),
18751881
}
18761882
}
18771883

crates/bdk/tests/wallet.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ fn test_bump_fee_remove_output_manually_selected_only() {
15711571
.transactions()
15721572
.last()
15731573
.unwrap()
1574-
.observed_as
1574+
.chain_position
15751575
.cloned()
15761576
.into(),
15771577
)
@@ -1621,7 +1621,7 @@ fn test_bump_fee_add_input() {
16211621
.transactions()
16221622
.last()
16231623
.unwrap()
1624-
.observed_as
1624+
.chain_position
16251625
.cloned()
16261626
.into();
16271627
wallet.insert_tx(init_tx, pos).unwrap();

0 commit comments

Comments
 (0)