Skip to content

Exploring bdk-tx for Wallet type #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thunderbiscuit
Copy link
Member

This is just me hacking away at leveraging the bdk-tx crate to build transactions.

@thunderbiscuit
Copy link
Member Author

thunderbiscuit commented Apr 7, 2025

The API for building transactions using bdk-tx doesn't have to be any different than what we currently have with the TxBuilder, but it could also be. Here are some rough sketches.

Builder pattern

let mut tx_builder = wallet.create_transaction_builder();
tx_builder
    .add_output(address.script_pubkey(), SEND_AMOUNT)
    .fee_rate(FeeRate::from_sat_per_vb(4).unwrap());
let mut psbt = tx_builder.finish()?;

Single method

// pseudocode

let mut psbt = wallet.create_transaction(
    outputs,
    target_feerate,
    must_spend,
    // ...
    // 12 other arguments that basically mimic the current TxBuilder methods
);

Note that this method could also take a single argument TransactionParams which would just be a data structure of the requirements for the tx, again similar to what we have in the private fields of the TxBuilder.

let transaction_params = TransactionParams {
    outputs: vec![(address.script_pubkey(), SEND_AMOUNT)],
    target_feerate: FeeRate::from_sat_per_vb(4).unwrap(),
    must_spend: Vec::new(),
};
let mut psbt = wallet.create_transaction(transaction_params);

2 methods (one for simple common cases)

The first one for simple cases often used and one that takes the full TransactionParams argument.

// For simple transactions
let mut psbt = wallet.create_simple_transaction(
    outputs,        // (Script, Amount)
    target_feerate, // FeeRate
);

// For transactions that require more customization
let mut psbt = wallet.create_complex_transaction(transaction_params);

@thunderbiscuit thunderbiscuit force-pushed the feature/bdk-tx-explorations branch from 21fd10b to 8e9a006 Compare April 7, 2025 17:59
@coveralls
Copy link

Pull Request Test Coverage Report for Build 14316252517

Details

  • 0 of 102 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-1.0%) to 85.487%

Changes Missing Coverage Covered Lines Changed/Added Lines %
wallet/src/wallet/mod.rs 0 102 0.0%
Totals Coverage Status
Change from base Build 14270666930: -1.0%
Covered Lines: 7269
Relevant Lines: 8503

💛 - Coveralls

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.

2 participants