@@ -336,6 +336,41 @@ where
336
336
337
337
Ok ( ( ) )
338
338
}
339
+
340
+ pub ( crate ) fn create_funding_transaction (
341
+ & self , output_script : & Script , value_sats : u64 , confirmation_target : ConfirmationTarget ,
342
+ ) -> Result < Transaction , Error > {
343
+ let num_blocks = num_blocks_from_conf_target ( confirmation_target) ;
344
+ let fee_rate = self . blockchain . estimate_fee ( num_blocks) ?;
345
+
346
+ let locked_wallet = self . wallet . lock ( ) . unwrap ( ) ;
347
+ let mut tx_builder = locked_wallet. build_tx ( ) ;
348
+
349
+ tx_builder. add_recipient ( output_script. clone ( ) , value_sats) . fee_rate ( fee_rate) . enable_rbf ( ) ;
350
+
351
+ let ( mut psbt, _) = tx_builder. finish ( ) ?;
352
+ log_trace ! ( self . logger, "Created funding PSBT: {:?}" , psbt) ;
353
+
354
+ // We double-check that no inputs try to spend non-witness outputs. As we use a SegWit
355
+ // wallet descriptor this technically shouldn't ever happen, but better safe than sorry.
356
+ for input in & psbt. inputs {
357
+ if input. witness_utxo . is_none ( ) {
358
+ log_error ! ( self . logger, "Tried to spend a non-witness funding output. This must not ever happen. Panicking!" ) ;
359
+ panic ! ( "Tried to spend a non-witness funding output. This must not ever happen." ) ;
360
+ }
361
+ }
362
+
363
+ if !locked_wallet. sign ( & mut psbt, SignOptions :: default ( ) ) ? {
364
+ return Err ( Error :: FundingTxCreationFailed ) ;
365
+ }
366
+
367
+ Ok ( psbt. extract_tx ( ) )
368
+ }
369
+
370
+ pub ( crate ) fn get_new_address ( & self ) -> Result < bitcoin:: Address , Error > {
371
+ let address_info = self . wallet . lock ( ) . unwrap ( ) . get_address ( AddressIndex :: New ) ?;
372
+ Ok ( address_info. address )
373
+ }
339
374
}
340
375
341
376
struct ConfirmedTx {
0 commit comments