Skip to content

feat(wallet): wrap apply_block_events, apply_block_connected_to_events, apply_evicted_txs, checkpoints#44

Draft
darioAnongba wants to merge 3 commits intomainfrom
feat/block-api
Draft

feat(wallet): wrap apply_block_events, apply_block_connected_to_events, apply_evicted_txs, checkpoints#44
darioAnongba wants to merge 3 commits intomainfrom
feat/block-api

Conversation

@darioAnongba
Copy link
Collaborator

Summary

Wraps BDK 2.3.0 block-by-block processing APIs with event returns.

Closes #20

Changes

New Wallet methods

  • apply_block_events(block, height) — Apply a block connecting via prev_blockhash, returns WalletEvent[]
  • apply_block_connected_to_events(block, height, connected_to) — Apply a block with explicit chain connection point, returns WalletEvent[]
  • apply_evicted_txs(evicted_txs) — Mark unconfirmed transactions as evicted from the mempool
  • checkpoints() — List all checkpoints in the wallet's internal chain

New types

  • Block — Full Bitcoin block with from_bytes() deserialization and accessors (block_hash, prev_blockhash, time, txdata, tx_count)
  • BlockId constructor — Create from height and hash string (was previously only constructable internally)
  • EvictedTx — Pair a transaction ID with an eviction timestamp for apply_evicted_txs

New error codes

  • BdkErrorCode.CannotConnect — Block cannot connect to existing chain
  • BdkErrorCode.UnexpectedConnectedToHash — Connected-to hash mismatch

Tests

  • Unit tests for BlockId, Block, EvictedTx, apply_evicted_txs, and checkpoints

CHANGELOG

  • Updated [Unreleased] section with all new items

Toshi added 3 commits March 26, 2026 10:21
…s, apply_evicted_txs, checkpoints

Add block-by-block processing APIs with event returns (closes #20):
- Wallet::apply_block_events for applying a block via prev_blockhash
- Wallet::apply_block_connected_to_events for explicit chain connection
- Wallet::apply_evicted_txs for marking unconfirmed txs as evicted
- Wallet::checkpoints for listing internal chain checkpoints

New types:
- Block (from_bytes deserialization, block_hash, prev_blockhash, time, txdata, tx_count)
- BlockId constructor from height and hash string
- EvictedTx for pairing txid with eviction timestamp

New error codes:
- BdkErrorCode::CannotConnect
- BdkErrorCode::UnexpectedConnectedToHash

Includes unit tests for BlockId, Block, EvictedTx, apply_evicted_txs, and checkpoints.
- Use CannotConnectError for apply_block_events (not ApplyBlockError)
- Use ApplyHeaderError for apply_block_connected_to_events
- Fix cargo fmt line wrapping in imports and map_err chains
Copy link
Collaborator Author

@darioAnongba darioAnongba left a comment

Choose a reason for hiding this comment

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

no real tests. The only tests in wallet.test.ts are doing nothing. We need real tests using the regtest environment.

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 apply_block_events / apply_block_connected_to_events

1 participant