Skip to content

Conversation

notmandatory
Copy link
Member

Description

Cherry-pick of commits from #310.

DRAFT and may modify based on feed back from users with 2.2.

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

WalletEvent is a enum of user facing events that are
generated when a sync update is applied to a wallet using the
Wallet::apply_update_events function.
@notmandatory notmandatory self-assigned this Sep 26, 2025
@notmandatory notmandatory added this to the Wallet 3.0.0 milestone Sep 26, 2025
@notmandatory notmandatory moved this to In Progress in BDK Wallet Sep 26, 2025
@notmandatory notmandatory moved this from In Progress to Todo in BDK Wallet Sep 26, 2025
Copy link
Collaborator

@ValuedMammal ValuedMammal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @notmandatory thanks for your work on this! I left some comments related to code quality. As always, nits are non-blocking.

};

// re-exports
use crate::event::{wallet_events, WalletEvent};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good place to re-export the WalletEvent type. That would also help keep the use statements organized.

.collect::<BTreeMap<Txid, (Arc<Transaction>, ChainPosition<ConfirmationBlockTime>)>>();

// apply update
self.apply_update(update)?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to apply the update and use the resulting changeset to produce a summary of what changed in the Wallet?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resulting Wallet::ChangeSet only contains the new blocks, tx, and anchors found after applying the sync update but don't show how this new data changes the canonical status of existing tx.

},
}

pub(crate) fn wallet_events(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📌 A code comment somewhere would help to explain what this function is doing.

Comment on lines +94 to +99
if chain_tip1 != chain_tip2 {
events.push(WalletEvent::ChainTipChanged {
old_tip: chain_tip1,
new_tip: chain_tip2,
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be helpful to know which blocks were connected and/or disconnected.

Copy link
Member Author

@notmandatory notmandatory Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a list of connected/disconnected block ids? I didn't add any other info here because @tnull didn't need it for LDK's use case. Do you have some use or user in mind for this extra info?

});
}

wallet_txs2.iter().for_each(|(txid2, (tx2, cp2))| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please use a for loop for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind using a for loop, but just curious what the benefit is, is it just easier to read?

}

wallet_txs2.iter().for_each(|(txid2, (tx2, cp2))| {
if let Some((tx1, cp1)) = wallet_txs1.get(txid2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pos1 or chain_position1. "cp" usually signifies something else.

use bdk_chain::{BlockId, CheckPoint, ConfirmationBlockTime};
use bdk_wallet::event::WalletEvent;
use bdk_wallet::test_utils::{get_test_wpkh_and_change_desc, new_wallet_and_funding_update};
use bdk_wallet::{SignOptions, Update};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be more future proof if you can do it using the unsigned txs.


wallet_txs2.iter().for_each(|(txid2, (tx2, cp2))| {
if let Some((tx1, cp1)) = wallet_txs1.get(txid2) {
assert_eq!(tx1.compute_txid(), *txid2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just a debug_assert here.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 18025823526

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 158 of 161 (98.14%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 84.982%

Changes Missing Coverage Covered Lines Changed/Added Lines %
wallet/src/wallet/event.rs 79 82 96.34%
Totals Coverage Status
Change from base Build 17957725258: 0.2%
Covered Lines: 7017
Relevant Lines: 8257

💛 - Coveralls

@ValuedMammal ValuedMammal moved this from Todo to In Progress in BDK Wallet Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants