Skip to content

Commit

Permalink
refactor/ remove tx_builder default in favor of bitcoin Version struct
Browse files Browse the repository at this point in the history
  • Loading branch information
benalleng committed Jan 3, 2025
1 parent 7517b61 commit 0dc4e2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
8 changes: 4 additions & 4 deletions crates/wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,11 @@ impl Wallet {
external_requirements.merge(&internal_requirements.unwrap_or_default())?;

let version = match params.version {
Some(tx_builder::Version(0)) => return Err(CreateTxError::Version0),
Some(tx_builder::Version(1)) if requirements.csv.is_some() => {
Some(transaction::Version(0)) => return Err(CreateTxError::Version0),
Some(transaction::Version(1)) if requirements.csv.is_some() => {
return Err(CreateTxError::Version1Csv)
}
Some(tx_builder::Version(x)) => x,
Some(transaction::Version(x)) => x,
None => 2,
};

Expand Down Expand Up @@ -1692,7 +1692,7 @@ impl Wallet {

let params = TxParams {
// TODO: figure out what rbf option should be?
version: Some(tx_builder::Version(tx.version.0)),
version: Some(transaction::Version::non_standard(tx.version.0)),
recipients: tx
.output
.into_iter()
Expand Down
22 changes: 2 additions & 20 deletions crates/wallet/src/wallet/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ use alloc::sync::Arc;
use bitcoin::psbt::{self, Psbt};
use bitcoin::script::PushBytes;
use bitcoin::{
absolute, Amount, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut, Txid,
Weight,
absolute, transaction::Version, Amount, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction,
TxIn, TxOut, Txid, Weight,
};
use rand_core::RngCore;

Expand Down Expand Up @@ -796,18 +796,6 @@ impl TxOrdering {
}
}

/// Transaction version
///
/// Has a default value of `2`
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
pub(crate) struct Version(pub(crate) i32);

impl Default for Version {
fn default() -> Self {
Version(2)
}
}

/// Policy regarding the use of change outputs when creating a transaction
#[derive(Default, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Clone, Copy)]
pub enum ChangeSpendPolicy {
Expand Down Expand Up @@ -1064,10 +1052,4 @@ mod test {
assert_eq!(filtered.len(), 1);
assert_eq!(filtered[0].keychain, KeychainKind::Internal);
}

#[test]
fn test_default_tx_version_2() {
let version = Version::default();
assert_eq!(version.0, 2);
}
}

0 comments on commit 0dc4e2f

Please sign in to comment.