Skip to content

Commit

Permalink
feat: add enable_rbf method on txbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Dec 7, 2023
1 parent 3df9252 commit c79a399
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
2 changes: 2 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ interface TxBuilder {

TxBuilder drain_to(Script script);

TxBuilder enable_rbf();

[Throws=BdkError]
PartiallySignedTransaction finish([ByRef] Wallet wallet);
};
Expand Down
6 changes: 6 additions & 0 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,9 @@ impl From<BdkLocalUtxo> for LocalUtxo {
}
}
}

#[derive(Clone, Debug)]
pub enum RbfValue {
Default,
Value(u32),
}
49 changes: 24 additions & 25 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction};
use crate::descriptor::Descriptor;
use crate::types::Balance;
use crate::types::{Balance, RbfValue};
use crate::types::ScriptAmount;
use crate::Script;
use crate::{AddressIndex, AddressInfo, Network};
use std::collections::HashSet;

use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::bitcoin::{OutPoint as BdkOutPoint, Sequence};
use bdk::wallet::Update as BdkUpdate;
use bdk::{Error as BdkError, FeeRate};
use bdk::{SignOptions, Wallet as BdkWallet};

use bdk::wallet::tx_builder::ChangeSpendPolicy;

use std::collections::HashSet;
use std::sync::{Arc, Mutex, MutexGuard};

#[derive(Debug)]
Expand Down Expand Up @@ -302,7 +301,7 @@ pub struct TxBuilder {
pub(crate) fee_absolute: Option<u64>,
pub(crate) drain_wallet: bool,
pub(crate) drain_to: Option<BdkScriptBuf>,
// pub(crate) rbf: Option<RbfValue>,
pub(crate) rbf: Option<RbfValue>,
// pub(crate) data: Vec<u8>,
}

Expand All @@ -318,7 +317,7 @@ impl TxBuilder {
fee_absolute: None,
drain_wallet: false,
drain_to: None,
// rbf: None,
rbf: None,
// data: Vec::new(),
}
}
Expand Down Expand Up @@ -453,15 +452,15 @@ impl TxBuilder {
..self.clone()
})
}
//
// /// Enable signaling RBF. This will use the default `nsequence` value of `0xFFFFFFFD`.
// pub(crate) fn enable_rbf(&self) -> Arc<Self> {
// Arc::new(TxBuilder {
// rbf: Some(RbfValue::Default),
// ..self.clone()
// })
// }
//

/// Enable signaling RBF. This will use the default `nsequence` value of `0xFFFFFFFD`.
pub(crate) fn enable_rbf(&self) -> Arc<Self> {
Arc::new(TxBuilder {
rbf: Some(RbfValue::Default),
..self.clone()
})
}

// /// Enable signaling RBF with a specific nSequence value. This can cause conflicts if the wallet's descriptors contain an
// /// "older" (OP_CSV) operator and the given `nsequence` is lower than the CSV value. If the `nsequence` is higher than `0xFFFFFFFD`
// /// an error will be thrown, since it would not be a valid nSequence to signal RBF.
Expand Down Expand Up @@ -517,16 +516,16 @@ impl TxBuilder {
if let Some(script) = &self.drain_to {
tx_builder.drain_to(script.clone());
}
// if let Some(rbf) = &self.rbf {
// match *rbf {
// RbfValue::Default => {
// tx_builder.enable_rbf();
// }
// RbfValue::Value(nsequence) => {
// tx_builder.enable_rbf_with_sequence(Sequence(nsequence));
// }
// }
// }
if let Some(rbf) = &self.rbf {
match *rbf {
RbfValue::Default => {
tx_builder.enable_rbf();
}
RbfValue::Value(nsequence) => {
tx_builder.enable_rbf_with_sequence(Sequence(nsequence));
}
}
}
// if !&self.data.is_empty() {
// tx_builder.add_data(self.data.as_slice());
// }
Expand Down

0 comments on commit c79a399

Please sign in to comment.