@@ -1223,6 +1223,33 @@ impl ChannelMonitor {
1223
1223
let mut res = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1224
1224
let mut spendable_outputs = Vec :: with_capacity ( local_tx. htlc_outputs . len ( ) ) ;
1225
1225
1226
+ macro_rules! add_dynamic_output {
1227
+ ( $father_tx: expr, $vout: expr) => {
1228
+ if let Some ( ref per_commitment_point) = * per_commitment_point {
1229
+ if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1230
+ if let Ok ( local_delayedkey) = chan_utils:: derive_private_key( & self . secp_ctx, per_commitment_point, delayed_payment_base_key) {
1231
+ spendable_outputs. push( SpendableOutputDescriptor :: DynamicOutput {
1232
+ outpoint: BitcoinOutPoint { txid: $father_tx. txid( ) , vout: $vout } ,
1233
+ local_delayedkey,
1234
+ witness_script: chan_utils:: get_revokeable_redeemscript( & local_tx. revocation_key, self . our_to_self_delay, & local_tx. delayed_payment_key) ,
1235
+ to_self_delay: self . our_to_self_delay
1236
+ } ) ;
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1241
+ }
1242
+
1243
+
1244
+ let redeemscript = chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . their_to_self_delay . unwrap ( ) , & local_tx. delayed_payment_key ) ;
1245
+ let revokeable_p2wsh = redeemscript. to_v0_p2wsh ( ) ;
1246
+ for ( idx, output) in local_tx. tx . output . iter ( ) . enumerate ( ) {
1247
+ if output. script_pubkey == revokeable_p2wsh {
1248
+ add_dynamic_output ! ( local_tx. tx, idx as u32 ) ;
1249
+ break ;
1250
+ }
1251
+ }
1252
+
1226
1253
for & ( ref htlc, ref their_sig, ref our_sig) in local_tx. htlc_outputs . iter ( ) {
1227
1254
if htlc. offered {
1228
1255
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 ) ;
@@ -1237,18 +1264,7 @@ impl ChannelMonitor {
1237
1264
htlc_timeout_tx. input [ 0 ] . witness . push ( Vec :: new ( ) ) ;
1238
1265
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 ( ) ) ;
1239
1266
1240
- if let Some ( ref per_commitment_point) = * per_commitment_point {
1241
- if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1242
- if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , per_commitment_point, delayed_payment_base_key) {
1243
- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutput {
1244
- outpoint : BitcoinOutPoint { txid : htlc_timeout_tx. txid ( ) , vout : 0 } ,
1245
- local_delayedkey,
1246
- witness_script : chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . our_to_self_delay , & local_tx. delayed_payment_key ) ,
1247
- to_self_delay : self . our_to_self_delay
1248
- } ) ;
1249
- }
1250
- }
1251
- }
1267
+ add_dynamic_output ! ( htlc_timeout_tx, 0 ) ;
1252
1268
res. push ( htlc_timeout_tx) ;
1253
1269
} else {
1254
1270
if let Some ( payment_preimage) = self . payment_preimages . get ( & htlc. payment_hash ) {
@@ -1264,18 +1280,7 @@ impl ChannelMonitor {
1264
1280
htlc_success_tx. input [ 0 ] . witness . push ( payment_preimage. to_vec ( ) ) ;
1265
1281
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 ( ) ) ;
1266
1282
1267
- if let Some ( ref per_commitment_point) = * per_commitment_point {
1268
- if let Some ( ref delayed_payment_base_key) = * delayed_payment_base_key {
1269
- if let Ok ( local_delayedkey) = chan_utils:: derive_private_key ( & self . secp_ctx , per_commitment_point, delayed_payment_base_key) {
1270
- spendable_outputs. push ( SpendableOutputDescriptor :: DynamicOutput {
1271
- outpoint : BitcoinOutPoint { txid : htlc_success_tx. txid ( ) , vout : 0 } ,
1272
- local_delayedkey,
1273
- witness_script : chan_utils:: get_revokeable_redeemscript ( & local_tx. revocation_key , self . our_to_self_delay , & local_tx. delayed_payment_key ) ,
1274
- to_self_delay : self . our_to_self_delay
1275
- } ) ;
1276
- }
1277
- }
1278
- }
1283
+ add_dynamic_output ! ( htlc_success_tx, 0 ) ;
1279
1284
res. push ( htlc_success_tx) ;
1280
1285
}
1281
1286
}
0 commit comments