Skip to content

feat: expand TxBuilder and Wallet API surface#36

Merged
darioAnongba merged 6 commits intomainfrom
feat/expand-txbuilder-api
Mar 3, 2026
Merged

feat: expand TxBuilder and Wallet API surface#36
darioAnongba merged 6 commits intomainfrom
feat/expand-txbuilder-api

Conversation

@darioAnongba
Copy link
Collaborator

Summary

First pass on expanding the WASM API surface (ref #21). Focuses on the most commonly needed TxBuilder options and Wallet methods.

TxBuilder — New Methods

Method Description
fee_absolute(amount) Set absolute fee instead of fee rate
add_utxo(outpoint) Add a must-spend UTXO
add_utxos(outpoints) Add multiple must-spend UTXOs
only_spend_from() Only spend manually added UTXOs
enable_rbf() Signal BIP 125 (default sequence)
enable_rbf_with_sequence(n) Signal BIP 125 with custom sequence
nlocktime(height) Set absolute locktime
version(v) Set transaction version
change_policy(policy) Control change output usage
do_not_spend_change() Shorthand for ChangeForbidden

New enum: ChangeSpendPolicy (ChangeAllowed, OnlyChange, ChangeForbidden)

Wallet — New Methods

Method Description
create_single(network, descriptor) Single-descriptor wallet (no change keychain)
build_fee_bump(txid) Create RBF fee-bump TxBuilder
mark_used(keychain, index) Mark address as used
unmark_used(keychain, index) Undo mark_used
insert_txout(outpoint, txout) Insert external TxOut for fee calculation

Error Types

Added BuildFeeBumpError variants to BdkErrorCode: TransactionNotFound, TransactionConfirmed, IrreplaceableTransaction, FeeRateUnavailable, InvalidOutputIndex.

Design Notes

  • build_fee_bump returns a TxBuilder with an internal flag. The actual BDK build_fee_bump call happens inside finish() to avoid lifetime issues with wasm_bindgen.
  • All new TxBuilder methods follow the existing "collect options, apply at finish" pattern.
  • fee_rate and fee_absolute are mutually exclusive (last one wins), matching BDK behavior.

Not Yet Wrapped (future PRs)

  • add_foreign_utxo (experimental, complex types)
  • policy_path (needs Map type bridging)
  • coin_selection (needs trait bridging)
  • sighash (needs EcdsaSighashType/TapSighashType bridging)
  • Descriptor templates (BIP44/49/84/86)
  • Wallet::policies / spending policy introspection

Ref #21

darioAnongba and others added 5 commits February 27, 2026 16:30
TxBuilder:
- fee_absolute: set absolute fee amount
- add_utxo/add_utxos: must-spend UTXOs
- only_spend_from: restrict to manually added UTXOs
- enable_rbf/enable_rbf_with_sequence: BIP 125 signaling
- nlocktime: absolute locktime
- version: transaction version
- change_policy/do_not_spend_change: change output control
- ChangeSpendPolicy enum

Wallet:
- build_fee_bump: RBF fee bumping via TxBuilder
- create_single: single-descriptor wallet constructor
- mark_used/unmark_used: address usage management
- insert_txout: external TxOut for fee calculation

Error types:
- BuildFeeBumpError variants added to BdkErrorCode

Ref #21
- Replace builder.only_spend_from() with builder.manually_selected_only()
  (method was renamed in bdk_wallet 2.x)
- Remove enable_rbf/enable_rbf_with_sequence calls from finish() since
  RBF is enabled by default in BDK 2.x (nSequence = 0xFFFFFFFD)
- Keep enable_rbf/enable_rbf_with_sequence wrapper methods as no-ops
  for API compatibility
- Add From<AddUtxoError> impl for BdkError to support add_utxos error
  propagation
- Remove unused enable_rbf and rbf_sequence fields from TxBuilder struct
AddUtxoError is at bdk_wallet::AddUtxoError, not bdk_wallet::error::AddUtxoError
@darioAnongba darioAnongba self-assigned this Mar 3, 2026
- Test create_single for single-descriptor wallets
- Test mark_used and unmark_used address management
- Test fee_absolute, change_policy, do_not_spend_change
- Test enable_rbf and enable_rbf_with_sequence chaining
- Test nlocktime and version builder options
- Test add_utxo, add_utxos, and only_spend_from
- Test full fluent API chaining of all options
- Test build_fee_bump with TransactionNotFound error
- Test ChangeSpendPolicy enum variants
@darioAnongba darioAnongba merged commit 9d5be3c into main Mar 3, 2026
22 of 24 checks passed
@darioAnongba darioAnongba deleted the feat/expand-txbuilder-api branch March 3, 2026 20:09
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.

1 participant