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

deps: bump bdk to beta_5 #600

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class LiveTxBuilderTest {
.setRecipients(allRecipients)
.feeRate(FeeRate.fromSatPerVb(4uL))
.changePolicy(ChangeSpendPolicy.CHANGE_FORBIDDEN)
.enableRbf()
.finish(wallet)

wallet.sign(psbt)
Expand Down
28 changes: 14 additions & 14 deletions bdk-ffi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions bdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ path = "uniffi-bindgen.rs"
default = ["uniffi/cli"]

[dependencies]
bdk_wallet = { version = "1.0.0-beta.4", features = ["all-keys", "keys-bip39", "rusqlite"] }
bdk_core = { version = "0.2.0" }
bdk_esplora = { version = "0.18.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_electrum = { version = "0.18.0", default-features = false, features = ["use-rustls-ring"] }
bdk_bitcoind_rpc = { version = "0.15.0" }
bdk_wallet = { version = "=1.0.0-beta.5", features = ["all-keys", "keys-bip39", "rusqlite"] }
bdk_core = { version = "0.3.0" }
bdk_esplora = { version = "0.19.0", default-features = false, features = ["std", "blocking", "blocking-https-rustls"] }
bdk_electrum = { version = "0.19.0", default-features = false, features = ["use-rustls-ring"] }
bdk_bitcoind_rpc = { version = "0.16.0" }
bitcoin-ffi = { git = "https://github.com/bitcoindevkit/bitcoin-ffi", tag = "v0.1.2" }

uniffi = { version = "=0.28.0" }
Expand Down
11 changes: 3 additions & 8 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ interface CreateTxError {
Version0();
Version1Csv();
LockTime(string requested, string required);
RbfSequence();
RbfSequenceCsv(string rbf, string csv);
RbfSequenceCsv(string sequence, string csv);
FeeTooLow(string required);
FeeRateTooLow(string required);
NoUtxosSelected();
Expand Down Expand Up @@ -462,9 +461,7 @@ interface TxBuilder {

TxBuilder drain_to([ByRef] Script script);

TxBuilder enable_rbf();

TxBuilder enable_rbf_with_sequence(u32 nsequence);
TxBuilder set_exact_sequence(u32 nsequence);

[Throws=CreateTxError]
Psbt finish([ByRef] Wallet wallet);
Expand All @@ -473,9 +470,7 @@ interface TxBuilder {
interface BumpFeeTxBuilder {
constructor(string txid, FeeRate fee_rate);

BumpFeeTxBuilder enable_rbf();

BumpFeeTxBuilder enable_rbf_with_sequence(u32 nsequence);
BumpFeeTxBuilder set_exact_sequence(u32 nsequence);

[Throws=CreateTxError]
Psbt finish([ByRef] Wallet wallet);
Expand Down
12 changes: 4 additions & 8 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,8 @@ pub enum CreateTxError {
#[error("lock time conflict: requested {requested}, but required {required}")]
LockTime { requested: String, required: String },

#[error("transaction requires rbf sequence number")]
RbfSequence,

#[error("rbf sequence: {rbf}, csv sequence: {csv}")]
RbfSequenceCsv { rbf: String, csv: String },
#[error("rbf sequence: {sequence}, csv sequence: {csv}")]
RbfSequenceCsv { sequence: String, csv: String },

#[error("fee too low: required {required}")]
FeeTooLow { required: String },
Expand Down Expand Up @@ -793,9 +790,8 @@ impl From<BdkCreateTxError> for CreateTxError {
requested: requested.to_string(),
required: required.to_string(),
},
BdkCreateTxError::RbfSequence => CreateTxError::RbfSequence,
BdkCreateTxError::RbfSequenceCsv { rbf, csv } => CreateTxError::RbfSequenceCsv {
rbf: rbf.to_string(),
BdkCreateTxError::RbfSequenceCsv { sequence, csv } => CreateTxError::RbfSequenceCsv {
sequence: sequence.to_string(),
csv: csv.to_string(),
},
BdkCreateTxError::FeeTooLow { required } => CreateTxError::FeeTooLow {
Expand Down
59 changes: 15 additions & 44 deletions bdk-ffi/src/tx_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::bitcoin::Psbt;
use crate::error::CreateTxError;
use crate::types::{RbfValue, ScriptAmount};
use crate::types::ScriptAmount;
use crate::wallet::Wallet;

use bitcoin_ffi::{Amount, FeeRate, Script};
Expand All @@ -27,8 +27,7 @@ pub struct TxBuilder {
pub(crate) fee_absolute: Option<Arc<Amount>>,
pub(crate) drain_wallet: bool,
pub(crate) drain_to: Option<BdkScriptBuf>,
pub(crate) rbf: Option<RbfValue>,
// pub(crate) data: Vec<u8>,
pub(crate) sequence: Option<u32>,
}

impl TxBuilder {
Expand All @@ -44,8 +43,7 @@ impl TxBuilder {
fee_absolute: None,
drain_wallet: false,
drain_to: None,
rbf: None,
// data: Vec::new(),
sequence: None,
}
}

Expand Down Expand Up @@ -162,16 +160,9 @@ impl TxBuilder {
})
}

pub(crate) fn enable_rbf(&self) -> Arc<Self> {
pub(crate) fn set_exact_sequence(&self, nsequence: u32) -> Arc<Self> {
Arc::new(TxBuilder {
rbf: Some(RbfValue::Default),
..self.clone()
})
}

pub(crate) fn enable_rbf_with_sequence(&self, nsequence: u32) -> Arc<Self> {
Arc::new(TxBuilder {
rbf: Some(RbfValue::Value(nsequence)),
sequence: Some(nsequence),
..self.clone()
})
}
Expand Down Expand Up @@ -211,15 +202,8 @@ 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(sequence) = self.sequence {
tx_builder.set_exact_sequence(Sequence(sequence));
}

let psbt = tx_builder.finish().map_err(CreateTxError::from)?;
Expand All @@ -232,28 +216,21 @@ impl TxBuilder {
pub(crate) struct BumpFeeTxBuilder {
pub(crate) txid: String,
pub(crate) fee_rate: Arc<FeeRate>,
pub(crate) rbf: Option<RbfValue>,
pub(crate) sequence: Option<u32>,
}

impl BumpFeeTxBuilder {
pub(crate) fn new(txid: String, fee_rate: Arc<FeeRate>) -> Self {
Self {
txid,
fee_rate,
rbf: None,
sequence: None,
}
}

pub(crate) fn enable_rbf(&self) -> Arc<Self> {
Arc::new(Self {
rbf: Some(RbfValue::Default),
..self.clone()
})
}

pub(crate) fn enable_rbf_with_sequence(&self, nsequence: u32) -> Arc<Self> {
Arc::new(Self {
rbf: Some(RbfValue::Value(nsequence)),
pub(crate) fn set_exact_sequence(&self, nsequence: u32) -> Arc<Self> {
Arc::new(BumpFeeTxBuilder {
sequence: Some(nsequence),
..self.clone()
})
}
Expand All @@ -265,16 +242,10 @@ impl BumpFeeTxBuilder {
let mut wallet = wallet.get_wallet();
let mut tx_builder = wallet.build_fee_bump(txid).map_err(CreateTxError::from)?;
tx_builder.fee_rate(self.fee_rate.0);
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(sequence) = self.sequence {
tx_builder.set_exact_sequence(Sequence(sequence));
}

let psbt: BdkPsbt = tx_builder.finish()?;

Ok(Arc::new(psbt.into()))
Expand Down
6 changes: 0 additions & 6 deletions bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,3 @@ pub struct SentAndReceivedValues {
pub sent: Arc<Amount>,
pub received: Arc<Amount>,
}

#[derive(Clone, Debug)]
pub enum RbfValue {
Default,
Value(u32),
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class LiveTxBuilderTest {
.setRecipients(allRecipients)
.feeRate(FeeRate.fromSatPerVb(4uL))
.changePolicy(ChangeSpendPolicy.CHANGE_FORBIDDEN)
.enableRbf()
.finish(wallet)

wallet.sign(psbt)
Expand Down
2 changes: 1 addition & 1 deletion bdk-python/tests/test_live_tx_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def complex_tx_builder(self):
ScriptAmount(recipient2.script_pubkey, 4200)
)

psbt: Psbt = TxBuilder().set_recipients(all_recipients).fee_rate(fee_rate=FeeRate.from_sat_per_vb(2)).enable_rbf().finish(wallet)
psbt: Psbt = TxBuilder().set_recipients(all_recipients).fee_rate(fee_rate=FeeRate.from_sat_per_vb(2)).finish(wallet)
wallet.sign(psbt)

self.assertTrue(psbt.serialize().startswith("cHNi"), "The PSBT should start with cHNi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ final class LiveTxBuilderTests: XCTestCase {
let psbt: Psbt = try TxBuilder()
.setRecipients(recipients: allRecipients)
.feeRate(feeRate: FeeRate.fromSatPerVb(satPerVb: 4))
.enableRbf()
.finish(wallet: wallet)

let _ = try! wallet.sign(psbt: psbt)
Expand Down
Loading