Skip to content
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

TxBuilder: Add an option to only use confirmed utxo's #1741

Open
ErikDeSmedt opened this issue Nov 21, 2024 · 1 comment
Open

TxBuilder: Add an option to only use confirmed utxo's #1741

ErikDeSmedt opened this issue Nov 21, 2024 · 1 comment
Labels
module-wallet new feature New feature or request

Comments

@ErikDeSmedt
Copy link

ErikDeSmedt commented Nov 21, 2024

Describe the enhancement

I want to create a transaction and ensure that prevout has been confirmed onchain.

Similar to ChangeSpendPolicy I'd like to introduce a ConfirmationSpendPolicy.
This could be used to spend only Confirmed, Trusted or Any output.

The code to use it could look like the example below

wallet.create_tx()
    .add_recipient(address.script_pubkey(), payment_amount)
    .only_spend_confirmed_utxos()
    .finalize()

Use case

When creating a transaction I want to ensure it cannot be doublespent.
If I use an unconfirmed and untrusted prevout, I cannot guarantee the transaction will not be doublespent

Additional context

@notmandatory notmandatory added this to BDK Nov 21, 2024
@notmandatory notmandatory moved this to Discussion in BDK Nov 21, 2024
@notmandatory notmandatory added the new feature New feature or request label Nov 21, 2024
@ValuedMammal
Copy link
Contributor

As an alternative to the enum idea, I think we could easily represent the confirmation policy as a BTreeMap<KeychainKind, u32> where an entry defines the number of confirmations needed to spend an output on that keychain. The API could look like this

/// The inputs to the transaction must be confirmed...
pub fn must_use_confirmed(&mut self) -> &mut Self {
    // ensure that each value in the map is at least 1
    // ...
}

/// Minimum number `n` of confirmations required to spend a UTXO of the given `keychain`.
pub fn min_confs(&mut self, keychain: KeychainKind, n: u32) -> &mut Self {
    self.params.confirmation_policy.insert(keychain, n);
    self
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module-wallet new feature New feature or request
Projects
Status: Discussion
Development

No branches or pull requests

3 participants