diff --git a/crates/esplora/src/blocking_ext.rs b/crates/esplora/src/blocking_ext.rs index 15036a99..5093b4ef 100644 --- a/crates/esplora/src/blocking_ext.rs +++ b/crates/esplora/src/blocking_ext.rs @@ -1,6 +1,5 @@ use std::collections::BTreeSet; use std::thread::JoinHandle; -use std::usize; use bdk_chain::collections::BTreeMap; use bdk_chain::spk_client::{FullScanRequest, FullScanResult, SyncRequest, SyncResult}; diff --git a/crates/wallet/Cargo.toml b/crates/wallet/Cargo.toml index 758ebf0f..9c141336 100644 --- a/crates/wallet/Cargo.toml +++ b/crates/wallet/Cargo.toml @@ -25,7 +25,7 @@ bip39 = { version = "2.0", optional = true } [features] default = ["std"] -std = ["bitcoin/std", "miniscript/std", "bdk_chain/std"] +std = ["bitcoin/std", "bitcoin/rand-std", "miniscript/std", "bdk_chain/std"] compiler = ["miniscript/compiler"] all-keys = ["keys-bip39"] keys-bip39 = ["bip39"] diff --git a/crates/wallet/README.md b/crates/wallet/README.md index 865a4fee..be780b6c 100644 --- a/crates/wallet/README.md +++ b/crates/wallet/README.md @@ -70,30 +70,28 @@ To persist `Wallet` state data use a data store crate that reads and writes [`bd ```rust,no_run use bdk_wallet::{bitcoin::Network, KeychainKind, wallet::{ChangeSet, Wallet}}; -fn main() { - // Open or create a new file store for wallet data. - let mut db = - bdk_file_store::Store::::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db") - .expect("create store"); +// Open or create a new file store for wallet data. +let mut db = + bdk_file_store::Store::::open_or_create_new(b"magic_bytes", "/tmp/my_wallet.db") + .expect("create store"); - // Create a wallet with initial wallet data read from the file store. - let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)"; - let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)"; - let changeset = db.aggregate_changesets().expect("changeset loaded"); - let mut wallet = - Wallet::new_or_load(descriptor, change_descriptor, changeset, Network::Testnet) - .expect("create or load wallet"); +// Create a wallet with initial wallet data read from the file store. +let descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/0/*)"; +let change_descriptor = "wpkh(tprv8ZgxMBicQKsPdcAqYBpzAFwU5yxBUo88ggoBqu1qPcHUfSbKK1sKMLmC7EAk438btHQrSdu3jGGQa6PA71nvH5nkDexhLteJqkM4dQmWF9g/84'/1'/0'/1/*)"; +let changeset = db.aggregate_changesets().expect("changeset loaded"); +let mut wallet = + Wallet::new_or_load(descriptor, change_descriptor, changeset, Network::Testnet) + .expect("create or load wallet"); - // Get a new address to receive bitcoin. - let receive_address = wallet.reveal_next_address(KeychainKind::External); - // Persist staged wallet data changes to the file store. - let staged_changeset = wallet.take_staged(); - if let Some(changeset) = staged_changeset { - db.append_changeset(&changeset) - .expect("must commit changes to database"); - } - println!("Your new receive address is: {}", receive_address.address); +// Get a new address to receive bitcoin. +let receive_address = wallet.reveal_next_address(KeychainKind::External); +// Persist staged wallet data changes to the file store. +let staged_changeset = wallet.take_staged(); +if let Some(changeset) = staged_changeset { + db.append_changeset(&changeset) + .expect("must commit changes to database"); } +println!("Your new receive address is: {}", receive_address.address); ``` @@ -154,7 +152,6 @@ fn main() { - @@ -174,7 +171,7 @@ fn main() { - + diff --git a/crates/wallet/examples/mnemonic_to_descriptors.rs b/crates/wallet/examples/mnemonic_to_descriptors.rs index ad1f1bad..76c53cf2 100644 --- a/crates/wallet/examples/mnemonic_to_descriptors.rs +++ b/crates/wallet/examples/mnemonic_to_descriptors.rs @@ -15,7 +15,6 @@ use bdk_wallet::descriptor::IntoWalletDescriptor; use bdk_wallet::keys::bip39::{Language, Mnemonic, WordCount}; use bdk_wallet::keys::{GeneratableKey, GeneratedKey}; use bdk_wallet::miniscript::Tap; -use rand::thread_rng; use std::str::FromStr; /// This example demonstrates how to generate a mnemonic phrase @@ -26,9 +25,8 @@ fn main() -> Result<(), anyhow::Error> { // In this example we are generating a 12 words mnemonic phrase // but it is also possible generate 15, 18, 21 and 24 words // using their respective `WordCount` variant. - let mut rng = thread_rng(); let mnemonic: GeneratedKey<_, Tap> = - Mnemonic::generate((WordCount::Words12, Language::English), &mut rng) + Mnemonic::generate((WordCount::Words12, Language::English)) .map_err(|_| anyhow!("Mnemonic generation error"))?; println!("Mnemonic phrase: {}", *mnemonic); diff --git a/crates/wallet/src/keys/bip39.rs b/crates/wallet/src/keys/bip39.rs index d1a8a4ba..7158505f 100644 --- a/crates/wallet/src/keys/bip39.rs +++ b/crates/wallet/src/keys/bip39.rs @@ -158,8 +158,6 @@ mod test { use bip39::{Language, Mnemonic}; - use rand::thread_rng; - use crate::keys::{any_network, GeneratableKey, GeneratedKey}; use super::WordCount; @@ -218,12 +216,12 @@ mod test { #[test] fn test_keys_generate_bip39_random() { - let mut rng = thread_rng(); let generated_mnemonic: GeneratedKey<_, miniscript::Segwitv0> = - Mnemonic::generate((WordCount::Words12, Language::English), &mut rng).unwrap(); + Mnemonic::generate((WordCount::Words12, Language::English)).unwrap(); assert_eq!(generated_mnemonic.valid_networks, any_network()); + let generated_mnemonic: GeneratedKey<_, miniscript::Segwitv0> = - Mnemonic::generate((WordCount::Words24, Language::English), &mut rng).unwrap(); + Mnemonic::generate((WordCount::Words24, Language::English)).unwrap(); assert_eq!(generated_mnemonic.valid_networks, any_network()); } } diff --git a/crates/wallet/src/keys/mod.rs b/crates/wallet/src/keys/mod.rs index 939f8d8a..907deb7b 100644 --- a/crates/wallet/src/keys/mod.rs +++ b/crates/wallet/src/keys/mod.rs @@ -633,8 +633,18 @@ pub trait GeneratableKey: Sized { entropy: Self::Entropy, ) -> Result, Self::Error>; - /// Generate a key given the options with a random entropy - fn generate( + /// Generate a key given the options with random entropy. + /// + /// Uses the thread-local random number generator. + #[cfg(feature = "std")] + fn generate(options: Self::Options) -> Result, Self::Error> { + Self::generate_with_aux_rand(options, &mut bitcoin::key::rand::thread_rng()) + } + + /// Generate a key given the options with random entropy. + /// + /// Uses a provided random number generator (rng). + fn generate_with_aux_rand( options: Self::Options, rng: &mut (impl CryptoRng + RngCore), ) -> Result, Self::Error> { @@ -660,10 +670,20 @@ where } /// Generate a key with the default options and a random entropy - fn generate_default( + /// + /// Uses the thread-local random number generator. + #[cfg(feature = "std")] + fn generate_default() -> Result, Self::Error> { + Self::generate_with_aux_rand(Default::default(), &mut bitcoin::key::rand::thread_rng()) + } + + /// Generate a key with the default options and a random entropy + /// + /// Uses a provided random number generator (rng). + fn generate_default_with_aux_rand( rng: &mut (impl CryptoRng + RngCore), ) -> Result, Self::Error> { - Self::generate(Default::default(), rng) + Self::generate_with_aux_rand(Default::default(), rng) } } diff --git a/crates/wallet/src/wallet/coin_selection.rs b/crates/wallet/src/wallet/coin_selection.rs index 6a7617fb..4016e05c 100644 --- a/crates/wallet/src/wallet/coin_selection.rs +++ b/crates/wallet/src/wallet/coin_selection.rs @@ -31,8 +31,6 @@ //! # use bdk_wallet::*; //! # use bdk_wallet::wallet::coin_selection::decide_change; //! # use anyhow::Error; -//! # use rand::{thread_rng, RngCore}; -//! //! #[derive(Debug)] //! struct AlwaysSpendEverything; //! @@ -94,7 +92,7 @@ //! let psbt = { //! let mut builder = wallet.build_tx().coin_selection(AlwaysSpendEverything); //! builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000)); -//! builder.finish_with_aux_rand(&mut thread_rng())? +//! builder.finish()? //! }; //! //! // inspect, sign, broadcast, ... diff --git a/crates/wallet/src/wallet/error.rs b/crates/wallet/src/wallet/error.rs index 4f250f34..b6c9375a 100644 --- a/crates/wallet/src/wallet/error.rs +++ b/crates/wallet/src/wallet/error.rs @@ -44,9 +44,9 @@ impl fmt::Display for MiniscriptPsbtError { impl std::error::Error for MiniscriptPsbtError {} #[derive(Debug)] -/// Error returned from [`TxBuilder::finish_with_aux_rand`] +/// Error returned from [`TxBuilder::finish`] /// -/// [`TxBuilder::finish_with_aux_rand`]: crate::wallet::tx_builder::TxBuilder::finish_with_aux_rand +/// [`TxBuilder::finish`]: crate::wallet::tx_builder::TxBuilder::finish pub enum CreateTxError { /// There was a problem with the descriptors passed in Descriptor(DescriptorError), diff --git a/crates/wallet/src/wallet/mod.rs b/crates/wallet/src/wallet/mod.rs index 0cc5b113..3a8361ca 100644 --- a/crates/wallet/src/wallet/mod.rs +++ b/crates/wallet/src/wallet/mod.rs @@ -1212,7 +1212,6 @@ impl Wallet { /// # use bdk_wallet::wallet::ChangeSet; /// # use bdk_wallet::wallet::error::CreateTxError; /// # use anyhow::Error; - /// # use rand::thread_rng; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let mut wallet = doctest_wallet!(); /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); @@ -1220,7 +1219,7 @@ impl Wallet { /// let mut builder = wallet.build_tx(); /// builder /// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000)); - /// builder.finish_with_aux_rand(&mut thread_rng())? + /// builder.finish()? /// }; /// /// // sign and broadcast ... @@ -1577,7 +1576,6 @@ impl Wallet { /// # use bdk_wallet::wallet::ChangeSet; /// # use bdk_wallet::wallet::error::CreateTxError; /// # use anyhow::Error; - /// # use rand::thread_rng; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let mut wallet = doctest_wallet!(); /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); @@ -1586,7 +1584,7 @@ impl Wallet { /// builder /// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000)) /// .enable_rbf(); - /// builder.finish_with_aux_rand(&mut thread_rng())? + /// builder.finish()? /// }; /// let _ = wallet.sign(&mut psbt, SignOptions::default())?; /// let tx = psbt.clone().extract_tx().expect("tx"); @@ -1595,7 +1593,7 @@ impl Wallet { /// let mut builder = wallet.build_fee_bump(tx.compute_txid())?; /// builder /// .fee_rate(FeeRate::from_sat_per_vb(5).expect("valid feerate")); - /// builder.finish_with_aux_rand(&mut thread_rng())? + /// builder.finish()? /// }; /// /// let _ = wallet.sign(&mut psbt, SignOptions::default())?; @@ -1755,14 +1753,13 @@ impl Wallet { /// # use bdk_wallet::*; /// # use bdk_wallet::wallet::ChangeSet; /// # use bdk_wallet::wallet::error::CreateTxError; - /// # use rand::thread_rng; /// # let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)"; /// # let mut wallet = doctest_wallet!(); /// # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); /// let mut psbt = { /// let mut builder = wallet.build_tx(); /// builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000)); - /// builder.finish_with_aux_rand(&mut thread_rng())? + /// builder.finish()? /// }; /// let finalized = wallet.sign(&mut psbt, SignOptions::default())?; /// assert!(finalized, "we should have signed all the inputs"); @@ -1807,6 +1804,7 @@ impl Wallet { { signer.sign_transaction(psbt, &sign_options, &self.secp)?; } + // attempt to finalize if sign_options.try_finalize { self.finalize_psbt(psbt, sign_options) diff --git a/crates/wallet/src/wallet/tx_builder.rs b/crates/wallet/src/wallet/tx_builder.rs index fbb478ad..0026025d 100644 --- a/crates/wallet/src/wallet/tx_builder.rs +++ b/crates/wallet/src/wallet/tx_builder.rs @@ -20,7 +20,6 @@ //! # use bdk_wallet::wallet::ChangeSet; //! # use bdk_wallet::wallet::error::CreateTxError; //! # use anyhow::Error; -//! # use rand::thread_rng; //! # let to_address = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); //! # let mut wallet = doctest_wallet!(); //! // create a TxBuilder from a wallet @@ -35,7 +34,7 @@ //! .do_not_spend_change() //! // Turn on RBF signaling //! .enable_rbf(); -//! let psbt = tx_builder.finish_with_aux_rand(&mut thread_rng())?; +//! let psbt = tx_builder.finish()?; //! # Ok::<(), anyhow::Error>(()) //! ``` @@ -57,7 +56,7 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo}; /// A transaction builder /// /// A `TxBuilder` is created by calling [`build_tx`] or [`build_fee_bump`] on a wallet. After -/// assigning it, you set options on it until finally calling [`finish_with_aux_rand`] to consume the builder and +/// assigning it, you set options on it until finally calling [`finish`] to consume the builder and /// generate the transaction. /// /// Each option setting method on `TxBuilder` takes and returns `&mut self` so you can chain calls @@ -71,7 +70,6 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo}; /// # use bdk_wallet::wallet::ChangeSet; /// # use bdk_wallet::wallet::error::CreateTxError; /// # use anyhow::Error; -/// # use rand::thread_rng; /// # let mut wallet = doctest_wallet!(); /// # let addr1 = Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt").unwrap().assume_checked(); /// # let addr2 = addr1.clone(); @@ -82,7 +80,7 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo}; /// .ordering(TxOrdering::Untouched) /// .add_recipient(addr1.script_pubkey(), Amount::from_sat(50_000)) /// .add_recipient(addr2.script_pubkey(), Amount::from_sat(50_000)); -/// builder.finish_with_aux_rand(&mut thread_rng())? +/// builder.finish()? /// }; /// /// // non-chaining @@ -92,7 +90,7 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo}; /// for addr in &[addr1, addr2] { /// builder.add_recipient(addr.script_pubkey(), Amount::from_sat(50_000)); /// } -/// builder.finish_with_aux_rand(&mut thread_rng())? +/// builder.finish()? /// }; /// /// assert_eq!(psbt1.unsigned_tx.output[..2], psbt2.unsigned_tx.output[..2]); @@ -106,7 +104,7 @@ use crate::{KeychainKind, LocalOutput, Utxo, WeightedUtxo}; /// /// [`build_tx`]: Wallet::build_tx /// [`build_fee_bump`]: Wallet::build_fee_bump -/// [`finish_with_aux_rand`]: Self::finish_with_aux_rand +/// [`finish`]: Self::finish /// [`coin_selection`]: Self::coin_selection #[derive(Debug)] pub struct TxBuilder<'a, Cs> { @@ -358,11 +356,11 @@ impl<'a, Cs> TxBuilder<'a, Cs> { /// 2. The data in `non_witness_utxo` does not match what is in `outpoint`. /// /// Note unless you set [`only_witness_utxo`] any non-taproot `psbt_input` you pass to this - /// method must have `non_witness_utxo` set otherwise you will get an error when [`finish_with_aux_rand`] + /// method must have `non_witness_utxo` set otherwise you will get an error when [`finish`] /// is called. /// /// [`only_witness_utxo`]: Self::only_witness_utxo - /// [`finish_with_aux_rand`]: Self::finish_with_aux_rand + /// [`finish`]: Self::finish /// [`max_weight_to_satisfy`]: miniscript::Descriptor::max_weight_to_satisfy pub fn add_foreign_utxo( &mut self, @@ -643,7 +641,6 @@ impl<'a, Cs> TxBuilder<'a, Cs> { /// # use bdk_wallet::wallet::ChangeSet; /// # use bdk_wallet::wallet::error::CreateTxError; /// # use anyhow::Error; - /// # use rand::thread_rng; /// # let to_address = /// Address::from_str("2N4eQYCbKUHCCTUjBJeHcJp9ok6J2GZsTDt") /// .unwrap() @@ -658,7 +655,7 @@ impl<'a, Cs> TxBuilder<'a, Cs> { /// .drain_to(to_address.script_pubkey()) /// .fee_rate(FeeRate::from_sat_per_vb(5).expect("valid feerate")) /// .enable_rbf(); - /// let psbt = tx_builder.finish_with_aux_rand(&mut thread_rng())?; + /// let psbt = tx_builder.finish()?; /// # Ok::<(), anyhow::Error>(()) /// ``` /// @@ -674,6 +671,23 @@ impl<'a, Cs> TxBuilder<'a, Cs> { impl<'a, Cs: CoinSelectionAlgorithm> TxBuilder<'a, Cs> { /// Finish building the transaction. /// + /// Uses the thread-local random number generator (rng). + /// + /// Returns a new [`Psbt`] per [`BIP174`]. + /// + /// [`BIP174`]: https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki + /// + /// **WARNING**: To avoid change address reuse you must persist the changes resulting from one + /// or more calls to this method before closing the wallet. See [`Wallet::reveal_next_address`]. + #[cfg(feature = "std")] + pub fn finish(self) -> Result { + self.finish_with_aux_rand(&mut bitcoin::key::rand::thread_rng()) + } + + /// Finish building the transaction. + /// + /// Uses a provided random number generator (rng). + /// /// Returns a new [`Psbt`] per [`BIP174`]. /// /// [`BIP174`]: https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki @@ -762,7 +776,17 @@ pub enum TxOrdering { } impl TxOrdering { - /// Sort transaction inputs and outputs by [`TxOrdering`] variant + /// Sort transaction inputs and outputs by [`TxOrdering`] variant. + /// + /// Uses the thread-local random number generator (rng). + #[cfg(feature = "std")] + pub fn sort_tx(self, tx: &mut Transaction) { + self.sort_tx_with_aux_rand(tx, &mut bitcoin::key::rand::thread_rng()) + } + + /// Sort transaction inputs and outputs by [`TxOrdering`] variant. + /// + /// Uses a provided random number generator (rng). pub fn sort_tx_with_aux_rand(self, tx: &mut Transaction, rng: &mut impl RngCore) { match self { TxOrdering::Untouched => {} @@ -852,16 +876,14 @@ mod test { use bitcoin::consensus::deserialize; use bitcoin::hex::FromHex; use bitcoin::TxOut; - use rand::thread_rng; use super::*; #[test] fn test_output_ordering_untouched() { let original_tx = ordering_test_tx!(); let mut tx = original_tx.clone(); - let mut rng = thread_rng(); - TxOrdering::Untouched.sort_tx_with_aux_rand(&mut tx, &mut rng); + TxOrdering::Untouched.sort_tx(&mut tx); assert_eq!(original_tx, tx); } @@ -870,11 +892,10 @@ mod test { fn test_output_ordering_shuffle() { let original_tx = ordering_test_tx!(); let mut tx = original_tx.clone(); - let mut rng = thread_rng(); (0..40) .find(|_| { - TxOrdering::Shuffle.sort_tx_with_aux_rand(&mut tx, &mut rng); + TxOrdering::Shuffle.sort_tx(&mut tx); original_tx.input != tx.input }) .expect("it should have moved the inputs at least once"); @@ -882,7 +903,7 @@ mod test { let mut tx = original_tx.clone(); (0..40) .find(|_| { - TxOrdering::Shuffle.sort_tx_with_aux_rand(&mut tx, &mut rng); + TxOrdering::Shuffle.sort_tx(&mut tx); original_tx.output != tx.output }) .expect("it should have moved the outputs at least once"); @@ -894,9 +915,8 @@ mod test { let original_tx = ordering_test_tx!(); let mut tx = original_tx; - let mut rng = thread_rng(); - TxOrdering::Bip69Lexicographic.sort_tx_with_aux_rand(&mut tx, &mut rng); + TxOrdering::Bip69Lexicographic.sort_tx(&mut tx); assert_eq!( tx.input[0].previous_output, diff --git a/crates/wallet/src/wallet/utils.rs b/crates/wallet/src/wallet/utils.rs index b79f1eb2..b3ec51cb 100644 --- a/crates/wallet/src/wallet/utils.rs +++ b/crates/wallet/src/wallet/utils.rs @@ -201,12 +201,14 @@ mod test { } #[test] + #[cfg(feature = "std")] fn test_shuffle_slice_empty_vec() { let mut test: Vec = vec![]; shuffle_slice(&mut test, &mut thread_rng()); } #[test] + #[cfg(feature = "std")] fn test_shuffle_slice_single_vec() { let mut test: Vec = vec![0]; shuffle_slice(&mut test, &mut thread_rng()); diff --git a/crates/wallet/tests/psbt.rs b/crates/wallet/tests/psbt.rs index e0b83810..155bb143 100644 --- a/crates/wallet/tests/psbt.rs +++ b/crates/wallet/tests/psbt.rs @@ -1,7 +1,6 @@ use bdk_wallet::bitcoin::{Amount, FeeRate, Psbt, TxIn}; use bdk_wallet::{psbt, KeychainKind, SignOptions}; use core::str::FromStr; -use rand::thread_rng; mod common; use common::*; @@ -16,7 +15,7 @@ fn test_psbt_malformed_psbt_input_legacy() { let send_to = wallet.peek_address(KeychainKind::External, 0); let mut builder = wallet.build_tx(); builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); psbt.inputs.push(psbt_bip.inputs[0].clone()); let options = SignOptions { trust_witness_utxo: true, @@ -33,7 +32,7 @@ fn test_psbt_malformed_psbt_input_segwit() { let send_to = wallet.peek_address(KeychainKind::External, 0); let mut builder = wallet.build_tx(); builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); psbt.inputs.push(psbt_bip.inputs[1].clone()); let options = SignOptions { trust_witness_utxo: true, @@ -49,7 +48,7 @@ fn test_psbt_malformed_tx_input() { let send_to = wallet.peek_address(KeychainKind::External, 0); let mut builder = wallet.build_tx(); builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); psbt.unsigned_tx.input.push(TxIn::default()); let options = SignOptions { trust_witness_utxo: true, @@ -65,7 +64,7 @@ fn test_psbt_sign_with_finalized() { let send_to = wallet.peek_address(KeychainKind::External, 0); let mut builder = wallet.build_tx(); builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); // add a finalized input psbt.inputs.push(psbt_bip.inputs[0].clone()); @@ -87,7 +86,7 @@ fn test_psbt_fee_rate_with_witness_utxo() { let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); builder.fee_rate(expected_fee_rate); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let fee_amount = psbt.fee_amount(); assert!(fee_amount.is_some()); @@ -112,7 +111,7 @@ fn test_psbt_fee_rate_with_nonwitness_utxo() { let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); builder.fee_rate(expected_fee_rate); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let fee_amount = psbt.fee_amount(); assert!(fee_amount.is_some()); let unfinalized_fee_rate = psbt.fee_rate().unwrap(); @@ -136,7 +135,7 @@ fn test_psbt_fee_rate_with_missing_txout() { let mut builder = wpkh_wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); builder.fee_rate(expected_fee_rate); - let mut wpkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut wpkh_psbt = builder.finish().unwrap(); wpkh_psbt.inputs[0].witness_utxo = None; wpkh_psbt.inputs[0].non_witness_utxo = None; @@ -150,7 +149,7 @@ fn test_psbt_fee_rate_with_missing_txout() { let mut builder = pkh_wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); builder.fee_rate(expected_fee_rate); - let mut pkh_psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut pkh_psbt = builder.finish().unwrap(); pkh_psbt.inputs[0].non_witness_utxo = None; assert!(pkh_psbt.fee_amount().is_none()); @@ -179,7 +178,7 @@ fn test_psbt_multiple_internalkey_signers() { let send_to = wallet.peek_address(KeychainKind::External, 0); let mut builder = wallet.build_tx(); builder.drain_to(send_to.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let unsigned_tx = psbt.unsigned_tx.clone(); // Adds a signer for the wrong internal key, bdk should not use this key to sign diff --git a/crates/wallet/tests/wallet.rs b/crates/wallet/tests/wallet.rs index 61e67859..2afc437e 100644 --- a/crates/wallet/tests/wallet.rs +++ b/crates/wallet/tests/wallet.rs @@ -25,7 +25,7 @@ use bitcoin::{ Sequence, Transaction, TxIn, TxOut, Txid, Weight, }; use rand::rngs::StdRng; -use rand::{thread_rng, SeedableRng}; +use rand::SeedableRng; mod common; use common::*; @@ -498,10 +498,7 @@ macro_rules! from_str { #[should_panic(expected = "NoRecipients")] fn test_create_tx_empty_recipients() { let (mut wallet, _) = get_funded_wallet_wpkh(); - wallet - .build_tx() - .finish_with_aux_rand(&mut thread_rng()) - .unwrap(); + wallet.build_tx().finish().unwrap(); } #[test] @@ -513,7 +510,7 @@ fn test_create_tx_manually_selected_empty_utxos() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .manually_selected_only(); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -524,10 +521,7 @@ fn test_create_tx_version_0() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .version(0); - assert!(matches!( - builder.finish_with_aux_rand(&mut thread_rng()), - Err(CreateTxError::Version0) - )); + assert!(matches!(builder.finish(), Err(CreateTxError::Version0))); } #[test] @@ -538,10 +532,7 @@ fn test_create_tx_version_1_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .version(1); - assert!(matches!( - builder.finish_with_aux_rand(&mut thread_rng()), - Err(CreateTxError::Version1Csv) - )); + assert!(matches!(builder.finish(), Err(CreateTxError::Version1Csv))); } #[test] @@ -552,7 +543,7 @@ fn test_create_tx_custom_version() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .version(42); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.version.0, 42); } @@ -564,7 +555,7 @@ fn test_create_tx_default_locktime_is_last_sync_height() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // Since we never synced the wallet we don't have a last_sync_height // we could use to try to prevent fee sniping. We default to 0. @@ -578,7 +569,7 @@ fn test_create_tx_fee_sniping_locktime_last_sync() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // If there's no current_height we're left with using the last sync height assert_eq!( @@ -593,7 +584,7 @@ fn test_create_tx_default_locktime_cltv() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 100_000); } @@ -607,7 +598,7 @@ fn test_create_tx_custom_locktime() { .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .current_height(630_001) .nlocktime(absolute::LockTime::from_height(630_000).unwrap()); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // When we explicitly specify a nlocktime // we don't try any fee sniping prevention trick @@ -623,7 +614,7 @@ fn test_create_tx_custom_locktime_compatible_with_cltv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .nlocktime(absolute::LockTime::from_height(630_000).unwrap()); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 630_000); } @@ -636,7 +627,7 @@ fn test_create_tx_custom_locktime_incompatible_with_cltv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .nlocktime(absolute::LockTime::from_height(50000).unwrap()); - assert!(matches!(builder.finish_with_aux_rand(&mut thread_rng()), + assert!(matches!(builder.finish(), Err(CreateTxError::LockTime { requested, required }) if requested.to_consensus_u32() == 50_000 && required.to_consensus_u32() == 100_000)); } @@ -647,7 +638,7 @@ fn test_create_tx_no_rbf_csv() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(6)); } @@ -660,7 +651,7 @@ fn test_create_tx_with_default_rbf_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // When CSV is enabled it takes precedence over the rbf value (unless forced by the user). // It will be set to the OP_CSV value, in this case 6 assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(6)); @@ -674,7 +665,7 @@ fn test_create_tx_with_custom_rbf_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf_with_sequence(Sequence(3)); - assert!(matches!(builder.finish_with_aux_rand(&mut thread_rng()), + assert!(matches!(builder.finish(), Err(CreateTxError::RbfSequenceCsv { rbf, csv }) if rbf.to_consensus_u32() == 3 && csv.to_consensus_u32() == 6)); } @@ -685,7 +676,7 @@ fn test_create_tx_no_rbf_cltv() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFE)); } @@ -698,10 +689,7 @@ fn test_create_tx_invalid_rbf_sequence() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf_with_sequence(Sequence(0xFFFFFFFE)); - assert!(matches!( - builder.finish_with_aux_rand(&mut thread_rng()), - Err(CreateTxError::RbfSequence) - )); + assert!(matches!(builder.finish(), Err(CreateTxError::RbfSequence))); } #[test] @@ -712,7 +700,7 @@ fn test_create_tx_custom_rbf_sequence() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf_with_sequence(Sequence(0xDEADBEEF)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xDEADBEEF)); } @@ -725,7 +713,7 @@ fn test_create_tx_change_policy() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .do_not_spend_change(); - assert!(builder.finish_with_aux_rand(&mut thread_rng()).is_ok()); + assert!(builder.finish().is_ok()); // wallet has no change, so setting `only_spend_change` // should cause tx building to fail @@ -734,7 +722,7 @@ fn test_create_tx_change_policy() { .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .only_spend_change(); assert!(matches!( - builder.finish_with_aux_rand(&mut thread_rng()), + builder.finish(), Err(CreateTxError::CoinSelection( coin_selection::Error::InsufficientFunds { .. } )), @@ -747,7 +735,7 @@ fn test_create_tx_default_sequence() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFE)); } @@ -767,7 +755,7 @@ fn test_create_tx_drain_wallet_and_drain_to() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(psbt.unsigned_tx.output.len(), 1); @@ -789,7 +777,7 @@ fn test_create_tx_drain_wallet_and_drain_to_and_with_recipient() { .add_recipient(addr.script_pubkey(), Amount::from_sat(20_000)) .drain_to(drain_addr.script_pubkey()) .drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); let outputs = psbt.unsigned_tx.output; @@ -819,7 +807,7 @@ fn test_create_tx_drain_to_and_utxos() { .drain_to(addr.script_pubkey()) .add_utxos(&utxos) .unwrap(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(psbt.unsigned_tx.output.len(), 1); @@ -836,7 +824,7 @@ fn test_create_tx_drain_to_no_drain_wallet_no_utxos() { let drain_addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(drain_addr.script_pubkey()); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -845,7 +833,7 @@ fn test_create_tx_default_fee_rate() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::BROADCAST_MIN, @add_signature); @@ -859,7 +847,7 @@ fn test_create_tx_custom_fee_rate() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .fee_rate(FeeRate::from_sat_per_vb_unchecked(5)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_fee_rate!(psbt, fee.unwrap_or(Amount::ZERO), FeeRate::from_sat_per_vb_unchecked(5), @add_signature); @@ -874,7 +862,7 @@ fn test_create_tx_absolute_fee() { .drain_to(addr.script_pubkey()) .drain_wallet() .fee_absolute(Amount::from_sat(100)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(fee.unwrap_or(Amount::ZERO), Amount::from_sat(100)); @@ -894,7 +882,7 @@ fn test_create_tx_absolute_zero_fee() { .drain_to(addr.script_pubkey()) .drain_wallet() .fee_absolute(Amount::ZERO); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(fee.unwrap_or(Amount::ZERO), Amount::ZERO); @@ -915,7 +903,7 @@ fn test_create_tx_absolute_high_fee() { .drain_to(addr.script_pubkey()) .drain_wallet() .fee_absolute(Amount::from_sat(60_000)); - let _ = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let _ = builder.finish().unwrap(); } #[test] @@ -946,7 +934,7 @@ fn test_create_tx_skip_change_dust() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(49_800)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(psbt.unsigned_tx.output.len(), 1); @@ -965,7 +953,7 @@ fn test_create_tx_drain_to_dust_amount() { .drain_to(addr.script_pubkey()) .drain_wallet() .fee_rate(FeeRate::from_sat_per_vb_unchecked(454)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -977,7 +965,7 @@ fn test_create_tx_ordering_respected() { .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) .add_recipient(addr.script_pubkey(), Amount::from_sat(10_000)) .ordering(bdk_wallet::wallet::tx_builder::TxOrdering::Bip69Lexicographic); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(psbt.unsigned_tx.output.len(), 3); @@ -995,7 +983,7 @@ fn test_create_tx_default_sighash() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.inputs[0].sighash_type, None); } @@ -1008,7 +996,7 @@ fn test_create_tx_custom_sighash() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) .sighash(EcdsaSighashType::Single.into()); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!( psbt.inputs[0].sighash_type, @@ -1025,7 +1013,7 @@ fn test_create_tx_input_hd_keypaths() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.inputs[0].bip32_derivation.len(), 1); assert_eq!( @@ -1047,7 +1035,7 @@ fn test_create_tx_output_hd_keypaths() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.outputs[0].bip32_derivation.len(), 1); let expected_derivation_path = format!("m/44'/0'/0'/0/{}", addr.index); @@ -1069,7 +1057,7 @@ fn test_create_tx_set_redeem_script_p2sh() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!( psbt.inputs[0].redeem_script, @@ -1092,7 +1080,7 @@ fn test_create_tx_set_witness_script_p2wsh() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.inputs[0].redeem_script, None); assert_eq!( @@ -1113,7 +1101,7 @@ fn test_create_tx_set_redeem_witness_script_p2wsh_p2sh() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let script = ScriptBuf::from_hex( "21032b0558078bec38694a84933d659303e2575dae7e91685911454115bfd64487e3ac", @@ -1131,7 +1119,7 @@ fn test_create_tx_non_witness_utxo() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert!(psbt.inputs[0].non_witness_utxo.is_some()); assert!(psbt.inputs[0].witness_utxo.is_none()); @@ -1147,7 +1135,7 @@ fn test_create_tx_only_witness_utxo() { .drain_to(addr.script_pubkey()) .only_witness_utxo() .drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert!(psbt.inputs[0].non_witness_utxo.is_none()); assert!(psbt.inputs[0].witness_utxo.is_some()); @@ -1160,7 +1148,7 @@ fn test_create_tx_shwpkh_has_witness_utxo() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert!(psbt.inputs[0].witness_utxo.is_some()); } @@ -1172,7 +1160,7 @@ fn test_create_tx_both_non_witness_utxo_and_witness_utxo_default() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert!(psbt.inputs[0].non_witness_utxo.is_some()); assert!(psbt.inputs[0].witness_utxo.is_some()); @@ -1210,7 +1198,7 @@ fn test_create_tx_add_utxo() { vout: 0, }) .unwrap(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); @@ -1261,7 +1249,7 @@ fn test_create_tx_manually_selected_insufficient() { }) .unwrap() .manually_selected_only(); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -1274,7 +1262,7 @@ fn test_create_tx_policy_path_required() { .assume_checked(); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -1309,7 +1297,7 @@ fn test_create_tx_policy_path_no_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) .policy_path(path, KeychainKind::External); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFF)); } @@ -1330,7 +1318,7 @@ fn test_create_tx_policy_path_use_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) .policy_path(path, KeychainKind::External); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(144)); } @@ -1351,7 +1339,7 @@ fn test_create_tx_policy_path_ignored_subtree_with_csv() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(30_000)) .policy_path(path, KeychainKind::External); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFE)); } @@ -1365,7 +1353,7 @@ fn test_create_tx_global_xpubs_with_origin() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .add_global_xpubs(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let key = bip32::Xpub::from_str("tpubDCKxNyM3bLgbEX13Mcd8mYxbVg9ajDkWXMh29hMWBurKfVmBfWAM96QVP3zaUcN51HvkZ3ar4VwP82kC8JZhhux8vFQoJintSpVBwpFvyU3").unwrap(); let fingerprint = bip32::Fingerprint::from_hex("73756c7f").unwrap(); @@ -1405,7 +1393,7 @@ fn test_add_foreign_utxo() { foreign_utxo_satisfaction.to_wu() as usize, ) .unwrap(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); wallet1.insert_txout(utxo.outpoint, utxo.txout); let fee = check_fee!(wallet1, psbt); let sent_received = @@ -1485,7 +1473,7 @@ fn test_calculate_fee_with_missing_foreign_utxo() { foreign_utxo_satisfaction.to_wu() as usize, ) .unwrap(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); wallet1.calculate_fee(&tx).unwrap(); } @@ -1584,7 +1572,7 @@ fn test_add_foreign_utxo_only_witness_utxo() { ) .unwrap(); assert!( - builder.finish_with_aux_rand(&mut thread_rng()).is_err(), + builder.finish().is_err(), "psbt_input with witness_utxo should fail with only witness_utxo" ); } @@ -1604,7 +1592,7 @@ fn test_add_foreign_utxo_only_witness_utxo() { ) .unwrap(); assert!( - builder.finish_with_aux_rand(&mut thread_rng()).is_ok(), + builder.finish().is_ok(), "psbt_input with just witness_utxo should succeed when `only_witness_utxo` is enabled" ); } @@ -1624,7 +1612,7 @@ fn test_add_foreign_utxo_only_witness_utxo() { ) .unwrap(); assert!( - builder.finish_with_aux_rand(&mut thread_rng()).is_ok(), + builder.finish().is_ok(), "psbt_input with non_witness_utxo should succeed by default" ); } @@ -1651,7 +1639,7 @@ fn test_create_tx_global_xpubs_origin_missing() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .add_global_xpubs(); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -1663,7 +1651,7 @@ fn test_create_tx_global_xpubs_master_without_origin() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .add_global_xpubs(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let key = bip32::Xpub::from_str("tpubD6NzVbkrYhZ4Y55A58Gv9RSNF5hy84b5AJqYy7sCcjFrkcLpPre8kmgfit6kY1Zs3BLgeypTDBZJM222guPpdz7Cup5yzaMu62u7mYGbwFL").unwrap(); let fingerprint = bip32::Fingerprint::from_hex("997a323b").unwrap(); @@ -1682,18 +1670,14 @@ fn test_bump_fee_irreplaceable_tx() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let txid = tx.compute_txid(); wallet .insert_tx(tx, ConfirmationTime::Unconfirmed { last_seen: 0 }) .unwrap(); - wallet - .build_fee_bump(txid) - .unwrap() - .finish_with_aux_rand(&mut thread_rng()) - .unwrap(); + wallet.build_fee_bump(txid).unwrap().finish().unwrap(); } #[test] @@ -1703,7 +1687,7 @@ fn test_bump_fee_confirmed_tx() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let txid = tx.compute_txid(); @@ -1718,11 +1702,7 @@ fn test_bump_fee_confirmed_tx() { ) .unwrap(); - wallet - .build_fee_bump(txid) - .unwrap() - .finish_with_aux_rand(&mut thread_rng()) - .unwrap(); + wallet.build_fee_bump(txid).unwrap().finish().unwrap(); } #[test] @@ -1733,7 +1713,7 @@ fn test_bump_fee_low_fee_rate() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let feerate = psbt.fee_rate().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); @@ -1745,7 +1725,7 @@ fn test_bump_fee_low_fee_rate() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_rate(FeeRate::BROADCAST_MIN); - let res = builder.finish_with_aux_rand(&mut thread_rng()); + let res = builder.finish(); assert_matches!( res, Err(CreateTxError::FeeRateTooLow { .. }), @@ -1767,7 +1747,7 @@ fn test_bump_fee_low_abs() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let txid = tx.compute_txid(); @@ -1778,7 +1758,7 @@ fn test_bump_fee_low_abs() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_absolute(Amount::from_sat(10)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -1790,7 +1770,7 @@ fn test_bump_fee_zero_abs() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let txid = tx.compute_txid(); @@ -1800,7 +1780,7 @@ fn test_bump_fee_zero_abs() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_absolute(Amount::ZERO); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -1813,7 +1793,7 @@ fn test_bump_fee_reduce_change() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let original_sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let original_fee = check_fee!(wallet, psbt); @@ -1827,7 +1807,7 @@ fn test_bump_fee_reduce_change() { let feerate = FeeRate::from_sat_per_kwu(625); // 2.5 sat/vb let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_rate(feerate).enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -1863,7 +1843,7 @@ fn test_bump_fee_reduce_change() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_absolute(Amount::from_sat(200)); builder.enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -1913,7 +1893,7 @@ fn test_bump_fee_reduce_single_recipient() { .drain_to(addr.script_pubkey()) .drain_wallet() .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.clone().extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); let original_fee = check_fee!(wallet, psbt); @@ -1932,7 +1912,7 @@ fn test_bump_fee_reduce_single_recipient() { .drain_to(addr.script_pubkey()) // drain wallet output amount will be re-calculated with new fee rate .drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -1961,7 +1941,7 @@ fn test_bump_fee_absolute_reduce_single_recipient() { .drain_to(addr.script_pubkey()) .drain_wallet() .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let original_fee = check_fee!(wallet, psbt); let tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); @@ -1979,7 +1959,7 @@ fn test_bump_fee_absolute_reduce_single_recipient() { .drain_to(addr.script_pubkey()) // drain wallet output amount will be re-calculated with new fee rate .drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = &psbt.unsigned_tx; let sent_received = wallet.sent_and_received(tx); let fee = check_fee!(wallet, psbt); @@ -2034,7 +2014,7 @@ fn test_bump_fee_drain_wallet() { .unwrap() .manually_selected_only() .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); @@ -2050,7 +2030,7 @@ fn test_bump_fee_drain_wallet() { builder .drain_wallet() .fee_rate(FeeRate::from_sat_per_vb_unchecked(5)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.extract_tx().expect("failed to extract tx")); assert_eq!(sent_received.0, Amount::from_sat(75_000)); @@ -2102,7 +2082,7 @@ fn test_bump_fee_remove_output_manually_selected_only() { .unwrap() .manually_selected_only() .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); let txid = tx.compute_txid(); @@ -2115,7 +2095,7 @@ fn test_bump_fee_remove_output_manually_selected_only() { builder .manually_selected_only() .fee_rate(FeeRate::from_sat_per_vb_unchecked(255)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -2148,7 +2128,7 @@ fn test_bump_fee_add_input() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let original_details = wallet.sent_and_received(&tx); let txid = tx.compute_txid(); @@ -2158,7 +2138,7 @@ fn test_bump_fee_add_input() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(50)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2205,7 +2185,7 @@ fn test_bump_fee_absolute_add_input() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); let txid = tx.compute_txid(); @@ -2215,7 +2195,7 @@ fn test_bump_fee_absolute_add_input() { let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_absolute(Amount::from_sat(6_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2268,7 +2248,7 @@ fn test_bump_fee_no_change_add_input_and_change() { .unwrap() .manually_selected_only() .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let original_sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let original_fee = check_fee!(wallet, psbt); @@ -2283,7 +2263,7 @@ fn test_bump_fee_no_change_add_input_and_change() { // the original output untouched. let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(50)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2332,7 +2312,7 @@ fn test_bump_fee_add_input_change_dust() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let original_sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let original_fee = check_fee!(wallet, psbt); @@ -2365,7 +2345,7 @@ fn test_bump_fee_add_input_change_dust() { // We use epsilon here to avoid asking for a slightly too high feerate let fee_abs = 50_000 + 25_000 - 45_000 - 10; builder.fee_rate(Amount::from_sat(fee_abs) / new_tx_weight); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2409,7 +2389,7 @@ fn test_bump_fee_force_add_input() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let mut tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); let txid = tx.compute_txid(); @@ -2426,7 +2406,7 @@ fn test_bump_fee_force_add_input() { .add_utxo(incoming_op) .unwrap() .fee_rate(FeeRate::from_sat_per_vb_unchecked(5)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2475,7 +2455,7 @@ fn test_bump_fee_absolute_force_add_input() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let mut tx = psbt.extract_tx().expect("failed to extract tx"); let original_sent_received = wallet.sent_and_received(&tx); let txid = tx.compute_txid(); @@ -2494,7 +2474,7 @@ fn test_bump_fee_absolute_force_add_input() { .add_utxo(incoming_op) .unwrap() .fee_absolute(Amount::from_sat(250)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); let fee = check_fee!(wallet, psbt); @@ -2549,7 +2529,7 @@ fn test_bump_fee_unconfirmed_inputs_only() { .drain_wallet() .drain_to(addr.script_pubkey()) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // Now we receive one transaction with 0 confirmations. We won't be able to use that for // fee bumping, as it's still unconfirmed! receive_output( @@ -2567,7 +2547,7 @@ fn test_bump_fee_unconfirmed_inputs_only() { .unwrap(); let mut builder = wallet.build_fee_bump(txid).unwrap(); builder.fee_rate(FeeRate::from_sat_per_vb_unchecked(25)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -2589,7 +2569,7 @@ fn test_bump_fee_unconfirmed_input() { .drain_wallet() .drain_to(addr.script_pubkey()) .enable_rbf(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let mut tx = psbt.extract_tx().expect("failed to extract tx"); let txid = tx.compute_txid(); for txin in &mut tx.input { @@ -2608,7 +2588,7 @@ fn test_bump_fee_unconfirmed_input() { .drain_to(addr.script_pubkey()) // drain wallet output amount will be re-calculated with new fee rate .drain_wallet(); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -2635,7 +2615,7 @@ fn test_fee_amount_negative_drain_val() { .unwrap() .enable_rbf() .fee_rate(fee_rate); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); assert_eq!(psbt.inputs.len(), 1); @@ -2648,7 +2628,7 @@ fn test_sign_single_xprv() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); assert!(finalized); @@ -2663,7 +2643,7 @@ fn test_sign_single_xprv_with_master_fingerprint_and_path() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); assert!(finalized); @@ -2678,7 +2658,7 @@ fn test_sign_single_xprv_bip44_path() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); assert!(finalized); @@ -2693,7 +2673,7 @@ fn test_sign_single_xprv_sh_wpkh() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); assert!(finalized); @@ -2709,7 +2689,7 @@ fn test_sign_single_wif() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, Default::default()).unwrap(); assert!(finalized); @@ -2724,7 +2704,7 @@ fn test_sign_single_xprv_no_hd_keypaths() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); psbt.inputs[0].bip32_derivation.clear(); assert_eq!(psbt.inputs[0].bip32_derivation.len(), 0); @@ -2748,7 +2728,7 @@ fn test_include_output_redeem_witness_script() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .include_output_redeem_witness_script(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); // p2sh-p2wsh transaction should contain both witness and redeem scripts assert!(psbt @@ -2767,7 +2747,7 @@ fn test_signing_only_one_of_multiple_inputs() { builder .add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)) .include_output_redeem_witness_script(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); // add another input to the psbt that is at least passable. let dud_input = bitcoin::psbt::Input { @@ -2811,7 +2791,7 @@ fn test_remove_partial_sigs_after_finalize_sign_option() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); assert!(wallet .sign( @@ -2841,7 +2821,7 @@ fn test_try_finalize_sign_option() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet .sign( @@ -2878,7 +2858,7 @@ fn test_sign_nonstandard_sighash() { .drain_to(addr.script_pubkey()) .sighash(sighash.into()) .drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let result = wallet.sign(&mut psbt, Default::default()); assert!( @@ -3108,7 +3088,7 @@ fn test_sending_to_bip350_bech32m_address() { .assume_checked(); let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000)); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -3194,7 +3174,7 @@ fn test_taproot_remove_tapfields_after_finalize_sign_option() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let finalized = wallet.sign(&mut psbt, SignOptions::default()).unwrap(); assert!(finalized); @@ -3221,7 +3201,7 @@ fn test_taproot_psbt_populate_tap_key_origins() { let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!( psbt.inputs[0] @@ -3264,7 +3244,7 @@ fn test_taproot_psbt_populate_tap_key_origins_repeated_key() { .drain_to(addr.script_pubkey()) .drain_wallet() .policy_path(path, KeychainKind::External); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let mut input_key_origins = psbt.inputs[0] .tap_key_origins @@ -3324,7 +3304,7 @@ fn test_taproot_psbt_input_tap_tree() { let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); assert_eq!( psbt.inputs[0].tap_merkle_root, @@ -3366,7 +3346,7 @@ fn test_taproot_sign_missing_witness_utxo() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let witness_utxo = psbt.inputs[0].witness_utxo.take(); let result = wallet.sign( @@ -3406,7 +3386,7 @@ fn test_taproot_sign_using_non_witness_utxo() { let addr = wallet.next_unused_address(KeychainKind::External); let mut builder = wallet.build_tx(); builder.drain_to(addr.script_pubkey()).drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); psbt.inputs[0].witness_utxo = None; psbt.inputs[0].non_witness_utxo = @@ -3453,7 +3433,7 @@ fn test_taproot_foreign_utxo() { foreign_utxo_satisfaction.to_wu() as usize, ) .unwrap(); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); let sent_received = wallet1.sent_and_received(&psbt.clone().extract_tx().expect("failed to extract tx")); wallet1.insert_txout(utxo.outpoint, utxo.txout); @@ -3479,7 +3459,7 @@ fn test_spend_from_wallet(mut wallet: Wallet) { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); assert!( wallet.sign(&mut psbt, Default::default()).unwrap(), @@ -3503,7 +3483,7 @@ fn test_taproot_no_key_spend() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); assert!( wallet @@ -3538,7 +3518,7 @@ fn test_taproot_script_spend_sign_all_leaves() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); assert!( wallet @@ -3569,7 +3549,7 @@ fn test_taproot_script_spend_sign_include_some_leaves() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let mut script_leaves: Vec<_> = psbt.inputs[0] .tap_scripts .clone() @@ -3609,7 +3589,7 @@ fn test_taproot_script_spend_sign_exclude_some_leaves() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let mut script_leaves: Vec<_> = psbt.inputs[0] .tap_scripts .clone() @@ -3647,7 +3627,7 @@ fn test_taproot_script_spend_sign_no_leaves() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); wallet .sign( @@ -3670,7 +3650,7 @@ fn test_taproot_sign_derive_index_from_psbt() { let mut builder = wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000)); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); // re-create the wallet with an empty db let wallet_empty = Wallet::new( @@ -3697,7 +3677,7 @@ fn test_taproot_sign_explicit_sighash_all() { .drain_to(addr.script_pubkey()) .sighash(TapSighashType::All.into()) .drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let result = wallet.sign(&mut psbt, Default::default()); assert!( @@ -3717,7 +3697,7 @@ fn test_taproot_sign_non_default_sighash() { .drain_to(addr.script_pubkey()) .sighash(sighash.into()) .drain_wallet(); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let witness_utxo = psbt.inputs[0].witness_utxo.take(); @@ -3835,7 +3815,7 @@ fn test_spend_coinbase() { .add_recipient(addr.script_pubkey(), balance.immature / 2) .current_height(confirmation_height); assert!(matches!( - builder.finish_with_aux_rand(&mut thread_rng()), + builder.finish(), Err(CreateTxError::CoinSelection( coin_selection::Error::InsufficientFunds { needed: _, @@ -3850,7 +3830,7 @@ fn test_spend_coinbase() { .add_recipient(addr.script_pubkey(), balance.immature / 2) .current_height(not_yet_mature_time); assert_matches!( - builder.finish_with_aux_rand(&mut thread_rng()), + builder.finish(), Err(CreateTxError::CoinSelection( coin_selection::Error::InsufficientFunds { needed: _, @@ -3879,7 +3859,7 @@ fn test_spend_coinbase() { builder .add_recipient(addr.script_pubkey(), balance.confirmed / 2) .current_height(maturity_time); - builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + builder.finish().unwrap(); } #[test] @@ -3893,7 +3873,7 @@ fn test_allow_dust_limit() { builder.add_recipient(addr.script_pubkey(), Amount::ZERO); assert_matches!( - builder.finish_with_aux_rand(&mut thread_rng()), + builder.finish(), Err(CreateTxError::OutputBelowDustLimit(0)) ); @@ -3903,7 +3883,7 @@ fn test_allow_dust_limit() { .allow_dust(true) .add_recipient(addr.script_pubkey(), Amount::ZERO); - assert!(builder.finish_with_aux_rand(&mut thread_rng()).is_ok()); + assert!(builder.finish().is_ok()); } #[test] @@ -3921,7 +3901,7 @@ fn test_fee_rate_sign_no_grinding_high_r() { .drain_wallet() .fee_rate(fee_rate) .add_data(&data); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); let (op_return_vout, _) = psbt .unsigned_tx @@ -3988,7 +3968,7 @@ fn test_fee_rate_sign_grinding_low_r() { .drain_to(addr.script_pubkey()) .drain_wallet() .fee_rate(fee_rate); - let mut psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let mut psbt = builder.finish().unwrap(); let fee = check_fee!(wallet, psbt); wallet @@ -4037,7 +4017,7 @@ fn test_tx_cancellation() { let mut builder = $wallet.build_tx(); builder.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000)); - let psbt = builder.finish_with_aux_rand(&mut thread_rng()).unwrap(); + let psbt = builder.finish().unwrap(); psbt }}; diff --git a/example-crates/wallet_electrum/Cargo.toml b/example-crates/wallet_electrum/Cargo.toml index 7ca7fdc6..2f562837 100644 --- a/example-crates/wallet_electrum/Cargo.toml +++ b/example-crates/wallet_electrum/Cargo.toml @@ -8,4 +8,3 @@ bdk_wallet = { path = "../../crates/wallet" } bdk_electrum = { path = "../../crates/electrum" } bdk_file_store = { path = "../../crates/file_store" } anyhow = "1" -rand = "0.8.0" diff --git a/example-crates/wallet_electrum/src/main.rs b/example-crates/wallet_electrum/src/main.rs index 65aced9d..2adf090a 100644 --- a/example-crates/wallet_electrum/src/main.rs +++ b/example-crates/wallet_electrum/src/main.rs @@ -14,7 +14,6 @@ use bdk_wallet::bitcoin::{Address, Amount}; use bdk_wallet::chain::collections::HashSet; use bdk_wallet::{bitcoin::Network, Wallet}; use bdk_wallet::{KeychainKind, SignOptions}; -use rand::thread_rng; fn main() -> Result<(), anyhow::Error> { let db_path = std::env::temp_dir().join("bdk-electrum-example"); @@ -97,7 +96,7 @@ fn main() -> Result<(), anyhow::Error> { .add_recipient(faucet_address.script_pubkey(), SEND_AMOUNT) .enable_rbf(); - let mut psbt = tx_builder.finish_with_aux_rand(&mut thread_rng())?; + let mut psbt = tx_builder.finish()?; let finalized = wallet.sign(&mut psbt, SignOptions::default())?; assert!(finalized); diff --git a/example-crates/wallet_esplora_async/Cargo.toml b/example-crates/wallet_esplora_async/Cargo.toml index 5c1745e4..2a71622c 100644 --- a/example-crates/wallet_esplora_async/Cargo.toml +++ b/example-crates/wallet_esplora_async/Cargo.toml @@ -11,4 +11,3 @@ bdk_esplora = { path = "../../crates/esplora", features = ["async-https"] } bdk_sqlite = { path = "../../crates/sqlite" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } anyhow = "1" -rand = "0.8.0" diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index 6b97af7f..0fd82b98 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -5,7 +5,6 @@ use bdk_wallet::{ bitcoin::{Address, Amount, Network, Script}, KeychainKind, SignOptions, Wallet, }; -use rand::thread_rng; use bdk_sqlite::{rusqlite::Connection, Store}; @@ -104,7 +103,7 @@ async fn main() -> Result<(), anyhow::Error> { .add_recipient(faucet_address.script_pubkey(), SEND_AMOUNT) .enable_rbf(); - let mut psbt = tx_builder.finish_with_aux_rand(&mut thread_rng())?; + let mut psbt = tx_builder.finish()?; let finalized = wallet.sign(&mut psbt, SignOptions::default())?; assert!(finalized); diff --git a/example-crates/wallet_esplora_blocking/Cargo.toml b/example-crates/wallet_esplora_blocking/Cargo.toml index 88f71cdb..857660ac 100644 --- a/example-crates/wallet_esplora_blocking/Cargo.toml +++ b/example-crates/wallet_esplora_blocking/Cargo.toml @@ -11,4 +11,3 @@ bdk_wallet = { path = "../../crates/wallet" } bdk_esplora = { path = "../../crates/esplora", features = ["blocking"] } bdk_file_store = { path = "../../crates/file_store" } anyhow = "1" -rand = "0.8.0" diff --git a/example-crates/wallet_esplora_blocking/src/main.rs b/example-crates/wallet_esplora_blocking/src/main.rs index 056ed59f..32211b04 100644 --- a/example-crates/wallet_esplora_blocking/src/main.rs +++ b/example-crates/wallet_esplora_blocking/src/main.rs @@ -11,7 +11,6 @@ use bdk_wallet::{ bitcoin::{Address, Amount, Network}, KeychainKind, SignOptions, Wallet, }; -use rand::thread_rng; fn main() -> Result<(), anyhow::Error> { let db_path = std::env::temp_dir().join("bdk-esplora-example"); @@ -81,7 +80,7 @@ fn main() -> Result<(), anyhow::Error> { .add_recipient(faucet_address.script_pubkey(), SEND_AMOUNT) .enable_rbf(); - let mut psbt = tx_builder.finish_with_aux_rand(&mut thread_rng())?; + let mut psbt = tx_builder.finish()?; let finalized = wallet.sign(&mut psbt, SignOptions::default())?; assert!(finalized);