@@ -1232,6 +1232,33 @@ impl ChannelMonitor {
1232
1232
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1233
1233
let mut spendable_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1234
1234
1235
+ macro_rules! add_dynamic_output {
1236
+ ( $father_tx: expr, $vout: expr) => {
1237
+ if let Some ( ref per_commitment_point) = * per_commitment_point {
1238
+ if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1239
+ if let Ok ( local_delayedkey) = chan_utils:: derive_private_key( & self . secp_ctx, per_commitment_point, delayed_payment_base_key) {
1240
+ spendable_outputs. push( SpendableOutputDescriptor :: DynamicOutput {
1241
+ outpoint: BitcoinOutPoint { txid: $father_tx. txid( ) , vout: $vout } ,
1242
+ local_delayedkey,
1243
+ witness_script: chan_utils:: get_revokeable_redeemscript( & local_tx. revocation_key, self . our_to_self_delay, & local_tx. delayed_payment_key) ,
1244
+ to_self_delay: self . our_to_self_delay
1245
+ } ) ;
1246
+ }
1247
+ }
1248
+ }
1249
+ }
1250
+ }
1251
+
1252
+
1253
+ let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay . unwrap ( ) , & local_tx. delayed_payment_key ) ;
1254
+ let revokeable_p2wsh = redeemscript. to_v0_p2wsh ( ) ;
1255
+ for ( idx, output) in local_tx. tx . output . iter ( ) . enumerate ( ) {
1256
+ if output. script_pubkey == revokeable_p2wsh {
1257
+ add_dynamic_output ! ( local_tx. tx, idx as u32 ) ;
1258
+ break ;
1259
+ }
1260
+ }
1261
+
1235
1262
for & ( ref htlc, ref their_sig, ref our_sig) in local_tx. htlc_outputs . iter ( ) {
1236
1263
if htlc. offered {
1237
1264
let mut htlc_timeout_tx = chan_utils:: build_htlc_transaction ( & local_tx. txid , local_tx. feerate_per_kw , self . their_to_self_delay . unwrap ( ) , htlc, & local_tx. delayed_payment_key , & local_tx. revocation_key ) ;
@@ -1246,18 +1273,7 @@ impl ChannelMonitor {
1246
1273
htlc_timeout_tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ;
1247
1274
htlc_timeout_tx. input [ 0 ] . witness . push ( chan_utils:: get_htlc_redeemscript_with_explicit_keys ( htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key ) . into_bytes ( ) ) ;
1248
1275
1249
- if let Some ( ref per_commitment_point) = * per_commitment_point {
1250
- if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1251
- if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , per_commitment_point, delayed_payment_base_key) {
1252
- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutput {
1253
- outpoint : BitcoinOutPoint { txid : htlc_timeout_tx. txid ( ) , vout : 0 } ,
1254
- local_delayedkey,
1255
- witness_script : chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . our_to_self_delay , & local_tx. delayed_payment_key ) ,
1256
- to_self_delay : self . our_to_self_delay
1257
- } ) ;
1258
- }
1259
- }
1260
- }
1276
+ add_dynamic_output ! ( htlc_timeout_tx, 0 ) ;
1261
1277
res. push ( htlc_timeout_tx) ;
1262
1278
} else {
1263
1279
if let Some ( payment_preimage) = self . payment_preimages . get ( & htlc. payment_hash ) {
@@ -1273,18 +1289,7 @@ impl ChannelMonitor {
1273
1289
htlc_success_tx. input [ 0 ] . witness . push ( payment_preimage. to_vec ( ) ) ;
1274
1290
htlc_success_tx. input [ 0 ] . witness . push ( chan_utils:: get_htlc_redeemscript_with_explicit_keys ( htlc, & local_tx. a_htlc_key , & local_tx. b_htlc_key , & local_tx. revocation_key ) . into_bytes ( ) ) ;
1275
1291
1276
- if let Some ( ref per_commitment_point) = * per_commitment_point {
1277
- if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1278
- if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , per_commitment_point, delayed_payment_base_key) {
1279
- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutput {
1280
- outpoint : BitcoinOutPoint { txid : htlc_success_tx. txid ( ) , vout : 0 } ,
1281
- local_delayedkey,
1282
- witness_script : chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . our_to_self_delay , & local_tx. delayed_payment_key ) ,
1283
- to_self_delay : self . our_to_self_delay
1284
- } ) ;
1285
- }
1286
- }
1287
- }
1292
+ add_dynamic_output ! ( htlc_success_tx, 0 ) ;
1288
1293
res. push ( htlc_success_tx) ;
1289
1294
}
1290
1295
}
0 commit comments