Add apply_block_events and apply_block_connected_to_events#336
Conversation
Pull Request Test Coverage Report for Build 18988009424Details
💛 - Coveralls |
wallet/src/wallet/mod.rs
Outdated
| block: &Block, | ||
| height: u32, | ||
| ) -> Result<Vec<WalletEvent>, CannotConnectError> { | ||
| let connected_to = match height.checked_sub(1) { |
There was a problem hiding this comment.
Thanks for working on this. I noticed apply_block_events seems to duplicate logic from apply_block. Could we move the event handling from apply_block_connected_to_events into apply_block_events, then have it call apply_block instead of apply_block_connected_to? Would be more consistent with how apply_update_event works and avoid the duplication.
There was a problem hiding this comment.
No, I intentionally added variants for apply_block as well as for apply_block_connected_to as we may also want to use apply_block_connected_to_events at some point.
There was a problem hiding this comment.
You could have apply_block call the new apply_block_events and map the return value to ().
There was a problem hiding this comment.
You could have
apply_blockcall the newapply_block_eventsand map the return value to().
Hmm, but that would run the (possibly costly) delta calculation for everybody, even if they wouldn't make use of the events. I believe this is why @notmandatory added separate _event variants of the methods in the first place.
There was a problem hiding this comment.
In #319 (in v3.0) my plan is to always return events. But for this PR I agree it's best keep the two paths separate so events are only calculated on the _events functions.
|
PR needs a rebase on the |
Previously, we added a new `Wallet::apply_update_events` method that returned `WalletEvent`s. Unfortunately, no corresponding APIs were added for the `apply_block` counterparts. Here we fix this omission.
3039c1b to
df444d0
Compare
Rebased on |
|
ACK I changed the PR to target |
notmandatory
left a comment
There was a problem hiding this comment.
Thanks for doing this. Other than my suggested change to apply_wallet_events() it looks good to me.
I would like to see some tests. If you don't have time to do them I'm happy to push a commit with similar testing as I did for apply_update_events().
|
For the branching question. I'd prefer to have a |
Co-authored-by: Steve Myers <github@notmandatory.org>
Yes, if you don't mind feel free to push a test case. I'm generally happy to do it, but given it will be the first one for |
Also did minor cleanup of apply_update_events tests.
|
I added a few tests for |
That's a good suggestion. |
…0 milestone) fcdc006 docs: Add ADR `0003_events.md` (Steve Myers) acbfb67 test: Add `tests/wallet_events.rs` (Steve Myers) ec3d1e0 feat(wallet): Add `Wallet::apply_update_events` (Steve Myers) 6467969 feat(wallet): Introduce `WalletEvent` (Steve Myers) 132d4b6 docs: Fix typo (Steve Myers) Pull request description: ### Description Cherry-pick of commits from #310 and #336. ### Notes to the reviewers See #319 (comment) for proposed follow-up work. ### Changelog notice No changes from `release/2.x` branch. BREAKING: - `wallet::event` module is made private. `WalletEvent` can now be imported from the root level. ### 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 `just p` before pushing #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature * [x] This pull request breaks the existing API Top commit has no ACKs. Tree-SHA512: bbe0c48175543413a75b4dc7b5e3a59dd0186aadab08dc8af8f14dcb4a90444bcfece1c3f6fc8474949b98a0e925ad91ef30aae53fefefdcbff55cbb09d64ea1
Description
Previously, we added a new
Wallet::apply_update_eventsmethod that returnedWalletEvents. Unfortunately, no corresponding APIs were added for theapply_blockcounterparts. Here we fix this omission.Notes to the reviewers
I opened this towards the
release-2.2branch, but it would probably need another release branch. Or let me know if you prefer to open it against master (which seems to be lackingapply_update_eventscurrently though).I also added no test coverage given that none seems to exist for
Wallet::apply_blockin the first place. Let me know if I should add something here.Checklists
All Submissions:
just pbefore pushingNew Features:
cc @notmandatory