feat: use Amount on TxBuilder::add_recipient
This commit is contained in:
9 files changed
+102
-102
No files matched your search
@@ -92,7 +92,7 @@
|
||||
//! .unwrap();
|
||||
//! let psbt = {
|
||||
//! let mut builder = wallet.build_tx().coin_selection(AlwaysSpendEverything);
|
||||
//! builder.add_recipient(to_address.script_pubkey(), 50_000);
|
||||
//! builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
|
||||
//! builder.finish()?
|
||||
//! };
|
||||
//!
|
||||
|
||||
@@ -1197,7 +1197,7 @@ impl Wallet {
|
||||
/// let psbt = {
|
||||
/// let mut builder = wallet.build_tx();
|
||||
/// builder
|
||||
/// .add_recipient(to_address.script_pubkey(), 50_000);
|
||||
/// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
|
||||
/// builder.finish()?
|
||||
/// };
|
||||
///
|
||||
@@ -1579,7 +1579,7 @@ impl Wallet {
|
||||
/// let mut psbt = {
|
||||
/// let mut builder = wallet.build_tx();
|
||||
/// builder
|
||||
/// .add_recipient(to_address.script_pubkey(), 50_000)
|
||||
/// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000))
|
||||
/// .enable_rbf();
|
||||
/// builder.finish()?
|
||||
/// };
|
||||
@@ -1752,7 +1752,7 @@ impl 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(), 50_000);
|
||||
/// builder.add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000));
|
||||
/// builder.finish()?
|
||||
/// };
|
||||
/// let finalized = wallet.sign(&mut psbt, SignOptions::default())?;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//!
|
||||
//! tx_builder
|
||||
//! // Create a transaction with one output to `to_address` of 50_000 satoshi
|
||||
//! .add_recipient(to_address.script_pubkey(), 50_000)
|
||||
//! .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000))
|
||||
//! // With a custom fee rate of 5.0 satoshi/vbyte
|
||||
//! .fee_rate(FeeRate::from_sat_per_vb(5).expect("valid feerate"))
|
||||
//! // Only spend non-change outputs
|
||||
@@ -47,7 +47,7 @@ use core::marker::PhantomData;
|
||||
|
||||
use bitcoin::psbt::{self, Psbt};
|
||||
use bitcoin::script::PushBytes;
|
||||
use bitcoin::{absolute, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction, Txid};
|
||||
use bitcoin::{absolute, Amount, FeeRate, OutPoint, ScriptBuf, Sequence, Transaction, Txid};
|
||||
|
||||
use super::coin_selection::{CoinSelectionAlgorithm, DefaultCoinSelectionAlgorithm};
|
||||
use super::{CreateTxError, Wallet};
|
||||
@@ -94,8 +94,8 @@ impl TxBuilderContext for BumpFee {}
|
||||
/// let mut builder = wallet.build_tx();
|
||||
/// builder
|
||||
/// .ordering(TxOrdering::Untouched)
|
||||
/// .add_recipient(addr1.script_pubkey(), 50_000)
|
||||
/// .add_recipient(addr2.script_pubkey(), 50_000);
|
||||
/// .add_recipient(addr1.script_pubkey(), Amount::from_sat(50_000))
|
||||
/// .add_recipient(addr2.script_pubkey(), Amount::from_sat(50_000));
|
||||
/// builder.finish()?
|
||||
/// };
|
||||
///
|
||||
@@ -104,7 +104,7 @@ impl TxBuilderContext for BumpFee {}
|
||||
/// let mut builder = wallet.build_tx();
|
||||
/// builder.ordering(TxOrdering::Untouched);
|
||||
/// for addr in &[addr1, addr2] {
|
||||
/// builder.add_recipient(addr.script_pubkey(), 50_000);
|
||||
/// builder.add_recipient(addr.script_pubkey(), Amount::from_sat(50_000));
|
||||
/// }
|
||||
/// builder.finish()?
|
||||
/// };
|
||||
@@ -274,7 +274,7 @@ impl<'a, Cs, Ctx> TxBuilder<'a, Cs, Ctx> {
|
||||
///
|
||||
/// let builder = wallet
|
||||
/// .build_tx()
|
||||
/// .add_recipient(to_address.script_pubkey(), 50_000)
|
||||
/// .add_recipient(to_address.script_pubkey(), Amount::from_sat(50_000))
|
||||
/// .policy_path(path, KeychainKind::External);
|
||||
///
|
||||
/// # Ok::<(), anyhow::Error>(())
|
||||
@@ -713,22 +713,26 @@ impl std::error::Error for AllowShrinkingError {}
|
||||
|
||||
impl<'a, Cs: CoinSelectionAlgorithm> TxBuilder<'a, Cs, CreateTx> {
|
||||
/// Replace the recipients already added with a new list
|
||||
pub fn set_recipients(&mut self, recipients: Vec<(ScriptBuf, u64)>) -> &mut Self {
|
||||
self.params.recipients = recipients;
|
||||
pub fn set_recipients(&mut self, recipients: Vec<(ScriptBuf, Amount)>) -> &mut Self {
|
||||
self.params.recipients = recipients
|
||||
.into_iter()
|
||||
.map(|(script, amount)| (script, amount.to_sat()))
|
||||
.collect();
|
||||
self
|
||||
}
|
||||
|
||||
// TODO: (@leonardo) Should this expect/use `bitcoin::Amount` instead ? Would it be a huge breaking change ?
|
||||
/// Add a recipient to the internal list
|
||||
pub fn add_recipient(&mut self, script_pubkey: ScriptBuf, amount: u64) -> &mut Self {
|
||||
self.params.recipients.push((script_pubkey, amount));
|
||||
pub fn add_recipient(&mut self, script_pubkey: ScriptBuf, amount: Amount) -> &mut Self {
|
||||
self.params
|
||||
.recipients
|
||||
.push((script_pubkey, amount.to_sat()));
|
||||
self
|
||||
}
|
||||
|
||||
/// Add data as an output, using OP_RETURN
|
||||
pub fn add_data<T: AsRef<PushBytes>>(&mut self, data: &T) -> &mut Self {
|
||||
let script = ScriptBuf::new_op_return(data);
|
||||
self.add_recipient(script, 0u64);
|
||||
self.add_recipient(script, Amount::ZERO);
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use bdk::bitcoin::{FeeRate, Psbt, TxIn};
|
||||
use bdk::bitcoin::{Amount, FeeRate, Psbt, TxIn};
|
||||
use bdk::{psbt, KeychainKind, SignOptions};
|
||||
use core::str::FromStr;
|
||||
mod common;
|
||||
@@ -14,7 +14,7 @@ fn test_psbt_malformed_psbt_input_legacy() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let send_to = wallet.peek_address(KeychainKind::External, 0);
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(send_to.script_pubkey(), 10_000);
|
||||
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
psbt.inputs.push(psbt_bip.inputs[0].clone());
|
||||
let options = SignOptions {
|
||||
@@ -31,7 +31,7 @@ fn test_psbt_malformed_psbt_input_segwit() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let send_to = wallet.peek_address(KeychainKind::External, 0);
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(send_to.script_pubkey(), 10_000);
|
||||
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
psbt.inputs.push(psbt_bip.inputs[1].clone());
|
||||
let options = SignOptions {
|
||||
@@ -47,7 +47,7 @@ fn test_psbt_malformed_tx_input() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let send_to = wallet.peek_address(KeychainKind::External, 0);
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(send_to.script_pubkey(), 10_000);
|
||||
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
psbt.unsigned_tx.input.push(TxIn::default());
|
||||
let options = SignOptions {
|
||||
@@ -63,7 +63,7 @@ fn test_psbt_sign_with_finalized() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let send_to = wallet.peek_address(KeychainKind::External, 0);
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(send_to.script_pubkey(), 10_000);
|
||||
builder.add_recipient(send_to.script_pubkey(), Amount::from_sat(10_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
// add a finalized input
|
||||
|
||||
+71
-71
@@ -200,7 +200,7 @@ fn test_get_funded_wallet_balance() {
|
||||
// The funded wallet contains a tx with a 76_000 sats input and two outputs, one spending 25_000
|
||||
// to a foreign address and one returning 50_000 back to the wallet as change. The remaining 1000
|
||||
// sats are the transaction fee.
|
||||
assert_eq!(wallet.get_balance().confirmed.to_sat(), 50_000);
|
||||
assert_eq!(wallet.get_balance().confirmed, Amount::from_sat(50_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -347,7 +347,7 @@ fn test_create_tx_manually_selected_empty_utxos() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.manually_selected_only();
|
||||
builder.finish().unwrap();
|
||||
}
|
||||
@@ -358,7 +358,7 @@ fn test_create_tx_version_0() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.version(0);
|
||||
assert!(matches!(builder.finish(), Err(CreateTxError::Version0)));
|
||||
}
|
||||
@@ -369,7 +369,7 @@ fn test_create_tx_version_1_csv() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.version(1);
|
||||
assert!(matches!(builder.finish(), Err(CreateTxError::Version1Csv)));
|
||||
}
|
||||
@@ -380,7 +380,7 @@ fn test_create_tx_custom_version() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.version(42);
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -393,7 +393,7 @@ fn test_create_tx_default_locktime_is_last_sync_height() {
|
||||
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
// Since we never synced the wallet we don't have a last_sync_height
|
||||
@@ -406,7 +406,7 @@ fn test_create_tx_fee_sniping_locktime_last_sync() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -422,7 +422,7 @@ fn test_create_tx_default_locktime_cltv() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_single_sig_cltv());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(psbt.unsigned_tx.lock_time.to_consensus_u32(), 100_000);
|
||||
@@ -434,7 +434,7 @@ fn test_create_tx_custom_locktime() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.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().unwrap();
|
||||
@@ -451,7 +451,7 @@ fn test_create_tx_custom_locktime_compatible_with_cltv() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.nlocktime(absolute::LockTime::from_height(630_000).unwrap());
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -464,7 +464,7 @@ fn test_create_tx_custom_locktime_incompatible_with_cltv() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.nlocktime(absolute::LockTime::from_height(50000).unwrap());
|
||||
assert!(matches!(builder.finish(),
|
||||
Err(CreateTxError::LockTime { requested, required })
|
||||
@@ -476,7 +476,7 @@ fn test_create_tx_no_rbf_csv() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_single_sig_csv());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(6));
|
||||
@@ -488,7 +488,7 @@ fn test_create_tx_with_default_rbf_csv() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
// When CSV is enabled it takes precedence over the rbf value (unless forced by the user).
|
||||
@@ -502,7 +502,7 @@ fn test_create_tx_with_custom_rbf_csv() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf_with_sequence(Sequence(3));
|
||||
assert!(matches!(builder.finish(),
|
||||
Err(CreateTxError::RbfSequenceCsv { rbf, csv })
|
||||
@@ -514,7 +514,7 @@ fn test_create_tx_no_rbf_cltv() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_single_sig_cltv());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFE));
|
||||
@@ -526,7 +526,7 @@ fn test_create_tx_invalid_rbf_sequence() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf_with_sequence(Sequence(0xFFFFFFFE));
|
||||
assert!(matches!(builder.finish(), Err(CreateTxError::RbfSequence)));
|
||||
}
|
||||
@@ -537,7 +537,7 @@ fn test_create_tx_custom_rbf_sequence() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf_with_sequence(Sequence(0xDEADBEEF));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -549,7 +549,7 @@ fn test_create_tx_default_sequence() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(psbt.unsigned_tx.input[0].sequence, Sequence(0xFFFFFFFE));
|
||||
@@ -561,7 +561,7 @@ fn test_create_tx_change_policy_no_internal() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.do_not_spend_change();
|
||||
assert!(matches!(
|
||||
builder.finish(),
|
||||
@@ -603,7 +603,7 @@ fn test_create_tx_drain_wallet_and_drain_to_and_with_recipient() {
|
||||
let drain_addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 20_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(20_000))
|
||||
.drain_to(drain_addr.script_pubkey())
|
||||
.drain_wallet();
|
||||
let psbt = builder.finish().unwrap();
|
||||
@@ -658,7 +658,7 @@ fn test_create_tx_default_fee_rate() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
|
||||
@@ -671,7 +671,7 @@ fn test_create_tx_custom_fee_rate() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.fee_rate(FeeRate::from_sat_per_vb_unchecked(5));
|
||||
let psbt = builder.finish().unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
@@ -740,7 +740,7 @@ fn test_create_tx_add_change() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.ordering(TxOrdering::Untouched);
|
||||
let psbt = builder.finish().unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
@@ -758,7 +758,7 @@ fn test_create_tx_skip_change_dust() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 49_800);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(49_800));
|
||||
let psbt = builder.finish().unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
|
||||
@@ -787,8 +787,8 @@ fn test_create_tx_ordering_respected() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), 10_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000))
|
||||
.ordering(bdk::wallet::tx_builder::TxOrdering::Bip69Lexicographic);
|
||||
let psbt = builder.finish().unwrap();
|
||||
let fee = check_fee!(wallet, psbt);
|
||||
@@ -807,7 +807,7 @@ fn test_create_tx_default_sighash() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 30_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(psbt.inputs[0].sighash_type, None);
|
||||
@@ -819,7 +819,7 @@ fn test_create_tx_custom_sighash() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.sighash(EcdsaSighashType::Single.into());
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1018,7 +1018,7 @@ fn test_create_tx_add_utxo() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.add_utxo(OutPoint {
|
||||
txid: small_output_tx.txid(),
|
||||
vout: 0,
|
||||
@@ -1069,7 +1069,7 @@ fn test_create_tx_manually_selected_insufficient() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.add_utxo(OutPoint {
|
||||
txid: small_output_tx.txid(),
|
||||
vout: 0,
|
||||
@@ -1088,7 +1088,7 @@ fn test_create_tx_policy_path_required() {
|
||||
.unwrap()
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 30_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000));
|
||||
builder.finish().unwrap();
|
||||
}
|
||||
|
||||
@@ -1123,7 +1123,7 @@ fn test_create_tx_policy_path_no_csv() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.policy_path(path, KeychainKind::External);
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1144,7 +1144,7 @@ fn test_create_tx_policy_path_use_csv() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.policy_path(path, KeychainKind::External);
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1165,7 +1165,7 @@ fn test_create_tx_policy_path_ignored_subtree_with_csv() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 30_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(30_000))
|
||||
.policy_path(path, KeychainKind::External);
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1181,7 +1181,7 @@ fn test_create_tx_global_xpubs_with_origin() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.add_global_xpubs();
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1215,7 +1215,7 @@ fn test_add_foreign_utxo() {
|
||||
|
||||
let mut builder = wallet1.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 60_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(60_000))
|
||||
.only_witness_utxo()
|
||||
.add_foreign_utxo(utxo.outpoint, psbt_input, foreign_utxo_satisfaction)
|
||||
.unwrap();
|
||||
@@ -1291,7 +1291,7 @@ fn test_calculate_fee_with_missing_foreign_utxo() {
|
||||
|
||||
let mut builder = wallet1.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 60_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(60_000))
|
||||
.only_witness_utxo()
|
||||
.add_foreign_utxo(utxo.outpoint, psbt_input, foreign_utxo_satisfaction)
|
||||
.unwrap();
|
||||
@@ -1375,7 +1375,7 @@ fn test_add_foreign_utxo_only_witness_utxo() {
|
||||
.unwrap();
|
||||
|
||||
let mut builder = wallet1.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 60_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(60_000));
|
||||
|
||||
{
|
||||
let mut builder = builder.clone();
|
||||
@@ -1444,7 +1444,7 @@ fn test_create_tx_global_xpubs_origin_missing() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.add_global_xpubs();
|
||||
builder.finish().unwrap();
|
||||
}
|
||||
@@ -1458,7 +1458,7 @@ fn test_create_tx_global_xpubs_master_without_origin() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.add_global_xpubs();
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1478,7 +1478,7 @@ fn test_bump_fee_irreplaceable_tx() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
let tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -1495,7 +1495,7 @@ fn test_bump_fee_confirmed_tx() {
|
||||
let (mut wallet, _) = get_funded_wallet(get_test_wpkh());
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
let tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -1520,7 +1520,7 @@ fn test_bump_fee_low_fee_rate() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let feerate = psbt.fee_rate().unwrap();
|
||||
@@ -1554,7 +1554,7 @@ fn test_bump_fee_low_abs() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1577,7 +1577,7 @@ fn test_bump_fee_zero_abs() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -1600,7 +1600,7 @@ fn test_bump_fee_reduce_change() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let original_sent_received =
|
||||
@@ -1932,7 +1932,7 @@ fn test_bump_fee_add_input() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -1989,7 +1989,7 @@ fn test_bump_fee_absolute_add_input() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -2117,7 +2117,7 @@ fn test_bump_fee_add_input_change_dust() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let original_sent_received =
|
||||
@@ -2194,7 +2194,7 @@ fn test_bump_fee_force_add_input() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let mut tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -2260,7 +2260,7 @@ fn test_bump_fee_absolute_force_add_input() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx().coin_selection(LargestFirstCoinSelection);
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.enable_rbf();
|
||||
let psbt = builder.finish().unwrap();
|
||||
let mut tx = psbt.extract_tx().expect("failed to extract tx");
|
||||
@@ -2410,7 +2410,7 @@ fn test_fee_amount_negative_drain_val() {
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(send_to.script_pubkey(), 8630)
|
||||
.add_recipient(send_to.script_pubkey(), Amount::from_sat(8630))
|
||||
.add_utxo(incoming_op)
|
||||
.unwrap()
|
||||
.enable_rbf()
|
||||
@@ -2524,7 +2524,7 @@ fn test_include_output_redeem_witness_script() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.include_output_redeem_witness_script();
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -2543,7 +2543,7 @@ fn test_signing_only_one_of_multiple_inputs() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 45_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000))
|
||||
.include_output_redeem_witness_script();
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -2888,7 +2888,7 @@ fn test_sending_to_bip350_bech32m_address() {
|
||||
.unwrap()
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 45_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(45_000));
|
||||
builder.finish().unwrap();
|
||||
}
|
||||
|
||||
@@ -3021,7 +3021,7 @@ fn test_taproot_psbt_populate_tap_key_origins() {
|
||||
let addr = wallet.reveal_next_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
assert_eq!(
|
||||
@@ -3061,7 +3061,7 @@ fn test_taproot_psbt_populate_tap_key_origins_repeated_key() {
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 25_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000))
|
||||
.policy_path(path, KeychainKind::External);
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
@@ -3245,7 +3245,7 @@ fn test_taproot_foreign_utxo() {
|
||||
|
||||
let mut builder = wallet1.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), 60_000)
|
||||
.add_recipient(addr.script_pubkey(), Amount::from_sat(60_000))
|
||||
.add_foreign_utxo(utxo.outpoint, psbt_input, foreign_utxo_satisfaction)
|
||||
.unwrap();
|
||||
let psbt = builder.finish().unwrap();
|
||||
@@ -3273,7 +3273,7 @@ fn test_spend_from_wallet(mut wallet: Wallet) {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -3297,7 +3297,7 @@ fn test_taproot_no_key_spend() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -3332,7 +3332,7 @@ fn test_taproot_script_spend_sign_all_leaves() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
assert!(
|
||||
@@ -3363,7 +3363,7 @@ fn test_taproot_script_spend_sign_include_some_leaves() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
let mut script_leaves: Vec<_> = psbt.inputs[0]
|
||||
.tap_scripts
|
||||
@@ -3403,7 +3403,7 @@ fn test_taproot_script_spend_sign_exclude_some_leaves() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
let mut script_leaves: Vec<_> = psbt.inputs[0]
|
||||
.tap_scripts
|
||||
@@ -3441,7 +3441,7 @@ fn test_taproot_script_spend_sign_no_leaves() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
wallet
|
||||
@@ -3464,7 +3464,7 @@ fn test_taproot_sign_derive_index_from_psbt() {
|
||||
let addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 25_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(25_000));
|
||||
let mut psbt = builder.finish().unwrap();
|
||||
|
||||
// re-create the wallet with an empty db
|
||||
@@ -3624,7 +3624,7 @@ fn test_spend_coinbase() {
|
||||
.assume_checked();
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), balance.immature.to_sat() / 2)
|
||||
.add_recipient(addr.script_pubkey(), balance.immature / 2)
|
||||
.current_height(confirmation_height);
|
||||
assert!(matches!(
|
||||
builder.finish(),
|
||||
@@ -3639,7 +3639,7 @@ fn test_spend_coinbase() {
|
||||
// Still unspendable...
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), balance.immature.to_sat() / 2)
|
||||
.add_recipient(addr.script_pubkey(), balance.immature / 2)
|
||||
.current_height(not_yet_mature_time);
|
||||
assert_matches!(
|
||||
builder.finish(),
|
||||
@@ -3669,7 +3669,7 @@ fn test_spend_coinbase() {
|
||||
);
|
||||
let mut builder = wallet.build_tx();
|
||||
builder
|
||||
.add_recipient(addr.script_pubkey(), balance.confirmed.to_sat() / 2)
|
||||
.add_recipient(addr.script_pubkey(), balance.confirmed / 2)
|
||||
.current_height(maturity_time);
|
||||
builder.finish().unwrap();
|
||||
}
|
||||
@@ -3682,7 +3682,7 @@ fn test_allow_dust_limit() {
|
||||
|
||||
let mut builder = wallet.build_tx();
|
||||
|
||||
builder.add_recipient(addr.script_pubkey(), 0);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::ZERO);
|
||||
|
||||
assert_matches!(
|
||||
builder.finish(),
|
||||
@@ -3693,7 +3693,7 @@ fn test_allow_dust_limit() {
|
||||
|
||||
builder
|
||||
.allow_dust(true)
|
||||
.add_recipient(addr.script_pubkey(), 0);
|
||||
.add_recipient(addr.script_pubkey(), Amount::ZERO);
|
||||
|
||||
assert!(builder.finish().is_ok());
|
||||
}
|
||||
@@ -3821,7 +3821,7 @@ fn test_tx_cancellation() {
|
||||
.unwrap()
|
||||
.assume_checked();
|
||||
let mut builder = $wallet.build_tx();
|
||||
builder.add_recipient(addr.script_pubkey(), 10_000);
|
||||
builder.add_recipient(addr.script_pubkey(), Amount::from_sat(10_000));
|
||||
|
||||
let psbt = builder.finish().unwrap();
|
||||
|
||||
|
||||
Reference in new issue
Block a user