2929//!
3030//! tx_builder
3131//! // Create a transaction with one output to `to_address` of 50_000 satoshi
32- //! .add_recipient(to_address.script_pubkey(), 50_000)
32+ //! .add_recipient(to_address.script_pubkey(), Amount::from_sat( 50_000) )
3333//! // With a custom fee rate of 5.0 satoshi/vbyte
3434//! .fee_rate(FeeRate::from_sat_per_vb(5).expect("valid feerate"))
3535//! // Only spend non-change outputs
@@ -47,7 +47,7 @@ use core::marker::PhantomData;
4747
4848use bitcoin:: psbt:: { self , Psbt } ;
4949use bitcoin:: script:: PushBytes ;
50- use bitcoin:: { absolute, FeeRate , OutPoint , ScriptBuf , Sequence , Transaction , Txid } ;
50+ use bitcoin:: { absolute, Amount , FeeRate , OutPoint , ScriptBuf , Sequence , Transaction , Txid } ;
5151
5252use super :: coin_selection:: { CoinSelectionAlgorithm , DefaultCoinSelectionAlgorithm } ;
5353use super :: { CreateTxError , Wallet } ;
@@ -94,8 +94,8 @@ impl TxBuilderContext for BumpFee {}
9494/// let mut builder = wallet.build_tx();
9595/// builder
9696/// .ordering(TxOrdering::Untouched)
97- /// .add_recipient(addr1.script_pubkey(), 50_000)
98- /// .add_recipient(addr2.script_pubkey(), 50_000);
97+ /// .add_recipient(addr1.script_pubkey(), Amount::from_sat( 50_000) )
98+ /// .add_recipient(addr2.script_pubkey(), Amount::from_sat( 50_000) );
9999/// builder.finish()?
100100/// };
101101///
@@ -104,7 +104,7 @@ impl TxBuilderContext for BumpFee {}
104104/// let mut builder = wallet.build_tx();
105105/// builder.ordering(TxOrdering::Untouched);
106106/// for addr in &[addr1, addr2] {
107- /// builder.add_recipient(addr.script_pubkey(), 50_000);
107+ /// builder.add_recipient(addr.script_pubkey(), Amount::from_sat( 50_000) );
108108/// }
109109/// builder.finish()?
110110/// };
@@ -274,7 +274,7 @@ impl<'a, Cs, Ctx> TxBuilder<'a, Cs, Ctx> {
274274 ///
275275 /// let builder = wallet
276276 /// .build_tx()
277- /// .add_recipient(to_address.script_pubkey(), 50_000)
277+ /// .add_recipient(to_address.script_pubkey(), Amount::from_sat( 50_000) )
278278 /// .policy_path(path, KeychainKind::External);
279279 ///
280280 /// # Ok::<(), anyhow::Error>(())
@@ -713,22 +713,26 @@ impl std::error::Error for AllowShrinkingError {}
713713
714714impl < ' a , Cs : CoinSelectionAlgorithm > TxBuilder < ' a , Cs , CreateTx > {
715715 /// Replace the recipients already added with a new list
716- pub fn set_recipients ( & mut self , recipients : Vec < ( ScriptBuf , u64 ) > ) -> & mut Self {
717- self . params . recipients = recipients;
716+ pub fn set_recipients ( & mut self , recipients : Vec < ( ScriptBuf , Amount ) > ) -> & mut Self {
717+ self . params . recipients = recipients
718+ . into_iter ( )
719+ . map ( |( script, amount) | ( script, amount. to_sat ( ) ) )
720+ . collect ( ) ;
718721 self
719722 }
720723
721- // TODO: (@leonardo) Should this expect/use `bitcoin::Amount` instead ? Would it be a huge breaking change ?
722724 /// Add a recipient to the internal list
723- pub fn add_recipient ( & mut self , script_pubkey : ScriptBuf , amount : u64 ) -> & mut Self {
724- self . params . recipients . push ( ( script_pubkey, amount) ) ;
725+ pub fn add_recipient ( & mut self , script_pubkey : ScriptBuf , amount : Amount ) -> & mut Self {
726+ self . params
727+ . recipients
728+ . push ( ( script_pubkey, amount. to_sat ( ) ) ) ;
725729 self
726730 }
727731
728732 /// Add data as an output, using OP_RETURN
729733 pub fn add_data < T : AsRef < PushBytes > > ( & mut self , data : & T ) -> & mut Self {
730734 let script = ScriptBuf :: new_op_return ( data) ;
731- self . add_recipient ( script, 0u64 ) ;
735+ self . add_recipient ( script, Amount :: ZERO ) ;
732736 self
733737 }
734738
0 commit comments