Merge bitcoindevkit/bdk#1395: Remove rand dependency from bdk
4bddb0de62feat(wallet): add back TxBuilder finish() and sort_tx() with thread_rng() (Steve Myers)45c0cae0a4fix(bdk): remove rand dependency (rustaceanrob) Pull request description: ### Description WIP towards removing `rand` fixes #871 The `rand` dependency was imported explicitly, but `rand` is also implicitly used through the `rand-std` feature flag on `bitcoin`. ### Notes to he reviewers **Updated:** `rand` was used primarily in two parts of `bdk`. Particularly in signing and in building a transaction. Signing: - Used implicitly in [`sign_schnorr`](https://docs.rs/bitcoin/latest/bitcoin/key/struct.Secp256k1.html#method.sign_schnorr), but nowhere else within `signer`. Transaction ordering: - Used to shuffle the inputs and outputs of a transaction, the default - Used in the single random draw __as a fallback__ to branch and bound during coin selection. Branch and bound is the default coin selection option. See conversation for proposed solutions. ### Changelog notice - Remove the `rand` dependency from `bdk` ### 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 #### New Features: * [x] I've added tests for the new feature * [x] I've added docs for the new feature #### Bugfixes: * [x] This pull request breaks the existing API * [x] I've added tests to reproduce the issue which are now passing * [x] I'm linking the issue being fixed by this PR ACKs for top commit: ValuedMammal: ACK4bddb0de62notmandatory: ACK4bddb0de62Tree-SHA512: 662d9bcb1e02f8195d73df16789b8c2aba8ccd7b37ba713ebb0bfd19c66163acbcb6f266b64f88347cbb1f96b88c8a150581012cbf818d1dc8b4437b3e53fc62
This commit is contained in:
@@ -24,6 +24,8 @@ use bitcoin::{
|
||||
absolute, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint, ScriptBuf,
|
||||
Sequence, Transaction, TxIn, TxOut, Txid, Weight,
|
||||
};
|
||||
use rand::rngs::StdRng;
|
||||
use rand::SeedableRng;
|
||||
|
||||
mod common;
|
||||
use common::*;
|
||||
@@ -907,14 +909,15 @@ fn test_create_tx_absolute_high_fee() {
|
||||
#[test]
|
||||
fn test_create_tx_add_change() {
|
||||
use bdk_wallet::wallet::tx_builder::TxOrdering;
|
||||
|
||||
let seed = [0; 32];
|
||||
let mut rng: StdRng = SeedableRng::from_seed(seed);
|
||||
let (mut wallet, _) = get_funded_wallet_wpkh();
|
||||
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))
|
||||
.ordering(TxOrdering::Untouched);
|
||||
let psbt = builder.finish().unwrap();
|
||||
.ordering(TxOrdering::Shuffle);
|
||||
let psbt = builder.finish_with_aux_rand(&mut rng).unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
|
||||
assert_eq!(psbt.unsigned_tx.output.len(), 2);
|
||||
|
||||
Reference in New Issue
Block a user