@@ -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
} ,
@@ -360,7 +364,7 @@ impl SpendableOutputDescriptor {
360
364
/// does not match the one we can spend.
361
365
///
362
366
/// 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 ) , ( ) > {
364
368
let secp_ctx = Secp256k1 :: new ( ) ;
365
369
let mut input = Vec :: with_capacity ( descriptors. len ( ) ) ;
366
370
let mut input_value = 0 ;
@@ -405,7 +409,7 @@ impl SpendableOutputDescriptor {
405
409
{ witness_weight -= 1 ; } // Guarantees a low R signature
406
410
input_value += descriptor. output . value ;
407
411
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 ) ) ;
409
413
} ,
410
414
SpendableOutputDescriptor :: StaticOutput { ref outpoint, ref output, .. } => {
411
415
if !output_set. insert ( * outpoint) { return Err ( ( ) ) ; }
@@ -432,7 +436,7 @@ impl SpendableOutputDescriptor {
432
436
let expected_max_weight =
433
437
transaction_utils:: maybe_add_change_output ( & mut tx, input_value, witness_weight, feerate_sat_per_1000_weight, change_destination_script) ?;
434
438
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 < _ > > ( ) ;
436
440
let psbt = PartiallySignedTransaction {
437
441
inputs : psbt_inputs,
438
442
outputs : vec ! [ Default :: default ( ) ; tx. output. len( ) ] ,
@@ -1657,7 +1661,7 @@ impl KeysManager {
1657
1661
/// May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
1658
1662
/// this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
1659
1663
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) ?;
1661
1665
psbt = self . sign_spendable_outputs_psbt ( descriptors, psbt, secp_ctx) ?;
1662
1666
1663
1667
let spend_tx = psbt. extract_tx ( ) ;
0 commit comments