Skip to content

feat: wrap wallet events API (apply_update_events)#33

Draft
darioAnongba wants to merge 3 commits intomainfrom
feat/wallet-events
Draft

feat: wrap wallet events API (apply_update_events)#33
darioAnongba wants to merge 3 commits intomainfrom
feat/wallet-events

Conversation

@darioAnongba
Copy link
Collaborator

Summary

Wrap BDK's WalletEvent type and add Wallet::apply_update_events so JS consumers can react to wallet state changes after syncing.

New API

WalletEvent type

JS-friendly wrapper with getters instead of Rust enum pattern matching:

Getter Type Description
kind string Event type: chain_tip_changed, tx_confirmed, tx_unconfirmed, tx_replaced, tx_dropped
txid Txid? Transaction id (tx events only)
tx Transaction? Full transaction (tx events only)
old_tip BlockId? Previous chain tip (chain_tip_changed only)
new_tip BlockId? New chain tip (chain_tip_changed only)
block_time ConfirmationBlockTime? Confirmation info (tx_confirmed only)
old_block_time ConfirmationBlockTime? Previous confirmation (reorgs)

Wallet.apply_update_events(update)

Like apply_update but returns WalletEvent[] describing what changed.

Example usage

const update = await esploraClient.full_scan(request, stopGap, parallelRequests);
const events = wallet.apply_update_events(update);
for (const event of events) {
  switch (event.kind) {
    case 'tx_confirmed':
      console.log(`TX ${event.txid} confirmed at block ${event.block_time.block_id.height}`);
      break;
    case 'chain_tip_changed':
      console.log(`Chain tip: ${event.old_tip.height}${event.new_tip.height}`);
      break;
  }
}

Closes #19

Add WalletEvent type wrapping BDK's WalletEvent enum with JS-friendly
getters:
- kind: event type string (chain_tip_changed, tx_confirmed,
  tx_unconfirmed, tx_replaced, tx_dropped)
- txid, tx: transaction data (where applicable)
- old_tip, new_tip: chain tip changes
- block_time, old_block_time: confirmation data

Add Wallet::apply_update_events method that returns Vec<WalletEvent>
describing what changed after applying an update.

Closes #19
@darioAnongba darioAnongba self-assigned this Feb 26, 2026
///
/// One of: `"chain_tip_changed"`, `"tx_confirmed"`, `"tx_unconfirmed"`, `"tx_replaced"`, `"tx_dropped"`.
#[wasm_bindgen(getter)]
pub fn kind(&self) -> String {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can't this return a WalletEventKind, which is a TS enum instead of String? Like we have KeychainKind?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done — added WalletEventKind enum following the KeychainKind pattern. The kind() getter now returns it instead of String.

- Fix E0603: use bdk_wallet::event::WalletEvent (public) instead of
  bdk_wallet::wallet::event::WalletEvent (private)
- Fix E0282: explicit type in old_block_time getter to resolve inference
- Add WalletEventKind TS enum per review feedback, replacing String return
  type on kind() getter (follows KeychainKind pattern)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: wrap wallet events API (apply_update returning events)

1 participant