@@ -103,7 +103,10 @@ pub struct DelayedPaymentOutputDescriptor {
103
103
pub channel_keys_id : [ u8 ; 32 ] ,
104
104
/// The value of the channel which this output originated from, possibly indirectly.
105
105
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
106
108
}
109
+
107
110
impl DelayedPaymentOutputDescriptor {
108
111
/// The maximum length a well-formed witness spending one of these should have.
109
112
/// 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, {
121
124
( 8 , revocation_pubkey, required) ,
122
125
( 10 , channel_keys_id, required) ,
123
126
( 12 , channel_value_satoshis, required) ,
127
+ ( 14 , delayed_payment_basepoint, required) ,
124
128
} ) ;
125
129
126
130
pub ( crate ) const P2WPKH_WITNESS_WEIGHT : u64 = 1 /* num stack items */ +
@@ -305,7 +309,7 @@ impl SpendableOutputDescriptor {
305
309
///
306
310
/// This is not exported to bindings users as there is no standard serialization for an input.
307
311
/// 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 {
309
313
match self {
310
314
SpendableOutputDescriptor :: StaticOutput { output, .. } => {
311
315
// Is a standard P2WPKH, no need for witness script
@@ -315,21 +319,21 @@ impl SpendableOutputDescriptor {
315
319
}
316
320
} ,
317
321
SpendableOutputDescriptor :: DelayedPaymentOutput ( descriptor) => {
318
- let witness_script = delayed_payment_basepoint . map ( |basepoint| {
322
+ let witness_script = {
319
323
let payment_key = DelayedPaymentKey :: from_basepoint (
320
324
secp_ctx,
321
- basepoint ,
325
+ & descriptor . delayed_payment_basepoint ,
322
326
& descriptor. per_commitment_point ,
323
327
) ;
324
328
get_revokeable_redeemscript (
325
329
& descriptor. revocation_pubkey ,
326
330
descriptor. to_self_delay ,
327
331
& payment_key,
328
332
)
329
- } ) ;
333
+ } ;
330
334
bitcoin:: psbt:: Input {
331
335
witness_utxo : Some ( descriptor. output . clone ( ) ) ,
332
- witness_script : witness_script,
336
+ witness_script : Some ( witness_script) ,
333
337
..Default :: default ( )
334
338
}
335
339
} ,
@@ -359,7 +363,7 @@ impl SpendableOutputDescriptor {
359
363
/// does not match the one we can spend.
360
364
///
361
365
/// We do not enforce that outputs meet the dust limit or that any output scripts are standard.
362
- 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 ) , ( ) > {
366
+ 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 ) , ( ) > {
363
367
let secp_ctx = Secp256k1 :: new ( ) ;
364
368
let mut input = Vec :: with_capacity ( descriptors. len ( ) ) ;
365
369
let mut input_value = 0 ;
@@ -404,7 +408,7 @@ impl SpendableOutputDescriptor {
404
408
{ witness_weight -= 1 ; } // Guarantees a low R signature
405
409
input_value += descriptor. output . value ;
406
410
407
- add_tweak = delayed_payment_basepoint . and_then ( |basepoint| Some ( derive_add_tweak ( & descriptor. per_commitment_point , & basepoint ) ) ) ;
411
+ add_tweak = Some ( derive_add_tweak ( & descriptor. per_commitment_point , & descriptor . delayed_payment_basepoint ) ) ;
408
412
} ,
409
413
SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
410
414
if !output_set. insert ( * outpoint) { return Err ( ( ) ) ; }
@@ -431,7 +435,7 @@ impl SpendableOutputDescriptor {
431
435
let expected_max_weight =
432
436
transaction_utils:: maybe_add_change_output ( & mut tx, input_value, witness_weight, feerate_sat_per_1000_weight, change_destination_script) ?;
433
437
434
- let psbt_inputs = descriptors. iter ( ) . map ( |d| d. to_psbt_input ( & secp_ctx, delayed_payment_basepoint ) ) . collect :: < Vec < _ > > ( ) ;
438
+ let psbt_inputs = descriptors. iter ( ) . map ( |d| d. to_psbt_input ( & secp_ctx) ) . collect :: < Vec < _ > > ( ) ;
435
439
let psbt = PartiallySignedTransaction {
436
440
inputs : psbt_inputs,
437
441
outputs : vec ! [ Default :: default ( ) ; tx. output. len( ) ] ,
@@ -1656,7 +1660,7 @@ impl KeysManager {
1656
1660
/// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
1657
1661
/// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
1658
1662
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 , ( ) > {
1659
- let ( mut psbt, expected_max_weight) = SpendableOutputDescriptor :: create_spendable_outputs_psbt ( descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime, None ) ?;
1663
+ let ( mut psbt, expected_max_weight) = SpendableOutputDescriptor :: create_spendable_outputs_psbt ( descriptors, outputs, change_destination_script, feerate_sat_per_1000_weight, locktime) ?;
1660
1664
psbt = self . sign_spendable_outputs_psbt ( descriptors, psbt, secp_ctx) ?;
1661
1665
1662
1666
let spend_tx = psbt. extract_tx ( ) ;
0 commit comments