Skip to content

Commit a5335a1

Browse files
committed
Merge #1789: Change default tx to version 2
2219b7c fix(tx_builder): change default tx to version 2 (benalleng) Pull request description: <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### Description Changes the default version number to version 2 to enchance privacy for the type of wallet used Fixes #1676 ### Changelog notice - Changed the default transaction version number in the transaction builder. - Updated the test to test for the default transaction number. ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: notmandatory: ACK 2219b7c Tree-SHA512: 76a2d394318eea94a99c033c3df14d64dbcf96c0f91dba91d2e337b9ecf78302af3d535ab11a74ed7372a521d3bc14c3455b7c8266d79d2995cc7c5da363b426
2 parents b2876d8 + 2219b7c commit a5335a1

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,13 +1284,12 @@ impl Wallet {
12841284
external_requirements.merge(&internal_requirements.unwrap_or_default())?;
12851285

12861286
let version = match params.version {
1287-
Some(tx_builder::Version(0)) => return Err(CreateTxError::Version0),
1288-
Some(tx_builder::Version(1)) if requirements.csv.is_some() => {
1287+
Some(transaction::Version(0)) => return Err(CreateTxError::Version0),
1288+
Some(transaction::Version::ONE) if requirements.csv.is_some() => {
12891289
return Err(CreateTxError::Version1Csv)
12901290
}
1291-
Some(tx_builder::Version(x)) => x,
1292-
None if requirements.csv.is_some() => 2,
1293-
None => 1,
1291+
Some(v) => v,
1292+
None => transaction::Version::TWO,
12941293
};
12951294

12961295
// We use a match here instead of a unwrap_or_else as it's way more readable :)
@@ -1388,7 +1387,7 @@ impl Wallet {
13881387
};
13891388

13901389
let mut tx = Transaction {
1391-
version: transaction::Version::non_standard(version),
1390+
version,
13921391
lock_time,
13931392
input: vec![],
13941393
output: vec![],
@@ -1693,7 +1692,7 @@ impl Wallet {
16931692

16941693
let params = TxParams {
16951694
// TODO: figure out what rbf option should be?
1696-
version: Some(tx_builder::Version(tx.version.0)),
1695+
version: Some(tx.version),
16971696
recipients: tx
16981697
.output
16991698
.into_iter()
@@ -2584,7 +2583,7 @@ macro_rules! doctest_wallet {
25842583
.unwrap();
25852584
let address = wallet.peek_address(KeychainKind::External, 0).address;
25862585
let tx = Transaction {
2587-
version: transaction::Version::ONE,
2586+
version: transaction::Version::TWO,
25882587
lock_time: absolute::LockTime::ZERO,
25892588
input: vec![],
25902589
output: vec![TxOut {

crates/wallet/src/wallet/tx_builder.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ use alloc::sync::Arc;
4444
use bitcoin::psbt::{self, Psbt};
4545
use bitcoin::script::PushBytes;
4646
use bitcoin::{
47-
absolute, Amount, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid,
48-
Weight,
47+
absolute, transaction::Version, Amount, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction,
48+
TxIn, TxOut, Txid, Weight,
4949
};
5050
use rand_core::RngCore;
5151

@@ -796,18 +796,6 @@ impl TxOrdering {
796796
}
797797
}
798798

799-
/// Transaction version
800-
///
801-
/// Has a default value of `1`
802-
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
803-
pub(crate) struct Version(pub(crate) i32);
804-
805-
impl Default for Version {
806-
fn default() -> Self {
807-
Version(1)
808-
}
809-
}
810-
811799
/// Policy regarding the use of change outputs when creating a transaction
812800
#[derive(Default, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
813801
pub enum ChangeSpendPolicy {
@@ -1064,10 +1052,4 @@ mod test {
10641052
assert_eq!(filtered.len(), 1);
10651053
assert_eq!(filtered[0].keychain, KeychainKind::Internal);
10661054
}
1067-
1068-
#[test]
1069-
fn test_default_tx_version_1() {
1070-
let version = Version::default();
1071-
assert_eq!(version.0, 1);
1072-
}
10731055
}

crates/wallet/tests/wallet.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,7 @@ fn test_spend_from_wallet(mut wallet: Wallet) {
35313531
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
35323532
let mut psbt = builder.finish().unwrap();
35333533

3534+
assert_eq!(psbt.unsigned_tx.version.0, 2);
35343535
assert!(
35353536
wallet.sign(&mut psbt, Default::default()).unwrap(),
35363537
"Unable to finalize tx"

0 commit comments

Comments
 (0)