File tree Expand file tree Collapse file tree 4 files changed +22
-8
lines changed Expand file tree Collapse file tree 4 files changed +22
-8
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,19 @@ impl PsbtParams {
175175 self
176176 }
177177
178+ /// Set the parameters for modifying the wallet's view of canonical transactions.
179+ ///
180+ /// The `params` can be used to resolve conflicts manually, or to assert that a particular
181+ /// transaction should be treated as canonical for the purpose of building the current PSBT.
182+ /// Refer to [`CanonicalizationParams`] for more.
183+ pub fn canonicalization_params (
184+ & mut self ,
185+ params : bdk_chain:: CanonicalizationParams ,
186+ ) -> & mut Self {
187+ self . canonical_params = params;
188+ self
189+ }
190+
178191 /// Set the definite descriptor used for generating the change output.
179192 pub fn change_descriptor ( & mut self , desc : DefiniteDescriptor ) -> & mut Self {
180193 self . change_descriptor = Some ( desc) ;
Original file line number Diff line number Diff line change @@ -2770,12 +2770,8 @@ impl Wallet {
27702770 } ) ;
27712771
27722772 // Get wallet txouts.
2773- let mut canon_params = params. canonical_params . clone ( ) ;
2774- canon_params
2775- . assume_canonical
2776- . extend ( params. utxos . iter ( ) . map ( |op| op. txid ) ) ;
27772773 let txouts = self
2778- . list_indexed_txouts ( canon_params )
2774+ . list_indexed_txouts ( params . canonical_params . clone ( ) )
27792775 . map ( |( _, txo) | ( txo. outpoint , txo) )
27802776 . collect ( ) ;
27812777
Original file line number Diff line number Diff line change @@ -147,7 +147,7 @@ fn test_create_psbt_cltv() {
147147#[ test]
148148fn test_create_psbt_csv ( ) {
149149 use bitcoin:: relative;
150- use bitcoin:: Sequence ;
150+ use bitcoin:: Sequence ;
151151
152152 let desc = get_test_single_sig_csv ( ) ;
153153 let mut wallet = Wallet :: create_single ( desc)
@@ -204,7 +204,9 @@ fn test_create_psbt_csv() {
204204 } ;
205205 insert_checkpoint ( & mut wallet, anchor. block_id ) ;
206206 let mut params = PsbtParams :: default ( ) ;
207- params. add_recipients ( [ ( addr. script_pubkey ( ) , Amount :: from_btc ( 0.42 ) . unwrap ( ) ) ] ) ;
207+ params
208+ . add_utxos ( & [ op] )
209+ . add_recipients ( [ ( addr. script_pubkey ( ) , Amount :: from_btc ( 0.42 ) . unwrap ( ) ) ] ) ;
208210 let ( psbt, _) = wallet. create_psbt ( params) . unwrap ( ) ;
209211 assert_eq ! ( psbt. unsigned_tx. input[ 0 ] . sequence, Sequence ( 6 ) ) ;
210212 }
Original file line number Diff line number Diff line change @@ -77,8 +77,11 @@ fn test_spend_non_canonical_txout() -> anyhow::Result<()> {
7777
7878 // Create tx2, spending the change of tx1
7979 let mut params = psbt:: PsbtParams :: default ( ) ;
80+ let canonical_params = bdk_chain:: CanonicalizationParams {
81+ assume_canonical : vec ! [ to_select_op. txid] ,
82+ } ;
8083 params
81- . add_utxos ( & [ to_select_op ] )
84+ . canonicalization_params ( canonical_params )
8285 . add_recipients ( [ ( recip, Amount :: from_btc ( 0.01 ) ?) ] ) ;
8386
8487 let psbt = wallet. create_psbt ( params) ?. 0 ;
You can’t perform that action at this time.
0 commit comments