@@ -103,7 +103,10 @@ pub struct DelayedPaymentOutputDescriptor {
103103 pub channel_keys_id : [ u8 ; 32 ] ,
104104 /// The value of the channel which this output originated from, possibly indirectly.
105105 pub channel_value_satoshis : u64 ,
106+ /// Channel base key used to generate a witness data to spend this output.
107+ pub delayed_payment_basepoint : DelayedPaymentBasepoint
106108}
109+
107110impl DelayedPaymentOutputDescriptor {
108111 /// The maximum length a well-formed witness spending one of these should have.
109112 /// Note: If you have the grind_signatures feature enabled, this will be at least 1 byte
@@ -121,6 +124,7 @@ impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, {
121124 ( 8 , revocation_pubkey, required) ,
122125 ( 10 , channel_keys_id, required) ,
123126 ( 12 , channel_value_satoshis, required) ,
127+ ( 14 , delayed_payment_basepoint, required) ,
124128} ) ;
125129
126130pub ( crate ) const P2WPKH_WITNESS_WEIGHT : u64 = 1 /* num stack items */ +
@@ -305,7 +309,7 @@ impl SpendableOutputDescriptor {
305309 ///
306310 /// This is not exported to bindings users as there is no standard serialization for an input.
307311 /// See [`Self::create_spendable_outputs_psbt`] instead.
308- pub fn to_psbt_input < T : secp256k1:: Signing > ( & self , secp_ctx : & Secp256k1 < T > , delayed_payment_basepoint : Option < & DelayedPaymentBasepoint > ) -> bitcoin:: psbt:: Input {
312+ pub fn to_psbt_input < T : secp256k1:: Signing > ( & self , secp_ctx : & Secp256k1 < T > ) -> bitcoin:: psbt:: Input {
309313 match self {
310314 SpendableOutputDescriptor :: StaticOutput { output, .. } => {
311315 // Is a standard P2WPKH, no need for witness script
@@ -315,21 +319,21 @@ impl SpendableOutputDescriptor {
315319 }
316320 } ,
317321 SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) => {
318- let witness_script = delayed_payment_basepoint . map ( |basepoint| {
322+ let witness_script = {
319323 let payment_key = DelayedPaymentKey :: from_basepoint (
320324 secp_ctx,
321- basepoint ,
325+ & descriptor . delayed_payment_basepoint ,
322326 & descriptor. per_commitment_point ,
323327 ) ;
324328 get_revokeable_redeemscript (
325329 & descriptor. revocation_pubkey ,
326330 descriptor. to_self_delay ,
327331 & payment_key,
328332 )
329- } ) ;
333+ } ;
330334 bitcoin:: psbt:: Input {
331335 witness_utxo : Some ( descriptor. output . clone ( ) ) ,
332- witness_script : witness_script,
336+ witness_script : Some ( witness_script) ,
333337 ..Default :: default ( )
334338 }
335339 } ,
@@ -360,7 +364,7 @@ impl SpendableOutputDescriptor {
360364 /// does not match the one we can spend.
361365 ///
362366 /// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
363- pub fn create_spendable_outputs_psbt ( descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > , change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 , locktime : Option < LockTime > , delayed_payment_basepoint : Option < & DelayedPaymentBasepoint > ) -> Result < ( PartiallySignedTransaction , u64 ) , ( ) > {
367+ pub fn create_spendable_outputs_psbt ( descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > , change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 , locktime : Option < LockTime > ) -> Result < ( PartiallySignedTransaction , u64 ) , ( ) > {
364368 let secp_ctx = Secp256k1 :: new ( ) ;
365369 let mut input = Vec :: with_capacity ( descriptors. len ( ) ) ;
366370 let mut input_value = 0 ;
@@ -405,7 +409,7 @@ impl SpendableOutputDescriptor {
405409 { witness_weight -= 1 ; } // Guarantees a low R signature
406410 input_value += descriptor. output . value ;
407411
408- add_tweak = delayed_payment_basepoint . and_then ( |basepoint| Some ( derive_add_tweak ( & descriptor. per_commitment_point , & basepoint ) ) ) ;
412+ add_tweak = Some ( derive_add_tweak ( & descriptor. per_commitment_point , & descriptor . delayed_payment_basepoint ) ) ;
409413 } ,
410414 SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
411415 if !output_set. insert ( * outpoint) { return Err ( ( ) ) ; }
@@ -432,7 +436,7 @@ impl SpendableOutputDescriptor {
432436 let expected_max_weight =
433437 transaction_utils:: maybe_add_change_output ( & mut tx, input_value, witness_weight, feerate_sat_per_1000_weight, change_destination_script) ?;
434438
435- let psbt_inputs = descriptors. iter ( ) . map ( |d| d. to_psbt_input ( & secp_ctx, delayed_payment_basepoint ) ) . collect :: < Vec < _ > > ( ) ;
439+ let psbt_inputs = descriptors. iter ( ) . map ( |d| d. to_psbt_input ( & secp_ctx) ) . collect :: < Vec < _ > > ( ) ;
436440 let psbt = PartiallySignedTransaction {
437441 inputs : psbt_inputs,
438442 outputs : vec ! [ Default :: default ( ) ; tx. output. len( ) ] ,
@@ -1657,7 +1661,7 @@ impl KeysManager {
16571661 /// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
16581662 /// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
16591663 pub fn spend_spendable_outputs < C : Signing > ( & self , descriptors : & [ & SpendableOutputDescriptor ] , outputs : Vec < TxOut > , change_destination_script : ScriptBuf , feerate_sat_per_1000_weight : u32 , locktime : Option < LockTime > , secp_ctx : & Secp256k1 < C > ) -> Result < Transaction , ( ) > {
1660- let ( mut psbt, expected_max_weight) = SpendableOutputDescriptor :: create_spendable_outputs_psbt ( descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime, None ) ?;
1664+ let ( mut psbt, expected_max_weight) = SpendableOutputDescriptor :: create_spendable_outputs_psbt ( descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime) ?;
16611665 psbt = self . sign_spendable_outputs_psbt ( descriptors, psbt, secp_ctx) ?;
16621666
16631667 let spend_tx = psbt. extract_tx ( ) ;
0 commit comments