@@ -608,6 +608,17 @@ pub fn build_htlc_transaction(commitment_txid: &Txid, feerate_per_kw: u32, conte
608
608
}
609
609
}
610
610
611
+ /// Gets the witnessScript for the to_remote output when anchors are enabled.
612
+ #[ inline]
613
+ pub ( crate ) fn get_to_countersignatory_with_anchors_redeemscript ( payment_point : & PublicKey ) -> Script {
614
+ Builder :: new ( )
615
+ . push_slice ( & payment_point. serialize ( ) [ ..] )
616
+ . push_opcode ( opcodes:: all:: OP_CHECKSIGVERIFY )
617
+ . push_int ( 1 )
618
+ . push_opcode ( opcodes:: all:: OP_CSV )
619
+ . into_script ( )
620
+ }
621
+
611
622
/// Gets the witnessScript for an anchor output from the funding public key.
612
623
/// The witness in the spending input must be:
613
624
/// <BIP 143 funding_signature>
@@ -1130,7 +1141,11 @@ impl CommitmentTransaction {
1130
1141
let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
1131
1142
1132
1143
if to_countersignatory_value_sat > 0 {
1133
- let script = script_for_p2wpkh ( & countersignatory_pubkeys. payment_point ) ;
1144
+ let script = if opt_anchors {
1145
+ get_to_countersignatory_with_anchors_redeemscript ( & countersignatory_pubkeys. payment_point ) . to_v0_p2wsh ( )
1146
+ } else {
1147
+ get_p2wpkh_redeemscript ( & countersignatory_pubkeys. payment_point )
1148
+ } ;
1134
1149
txouts. push ( (
1135
1150
TxOut {
1136
1151
script_pubkey : script. clone ( ) ,
@@ -1424,7 +1439,7 @@ pub fn get_commitment_transaction_number_obscure_factor(
1424
1439
| ( ( res[ 31 ] as u64 ) << 0 * 8 )
1425
1440
}
1426
1441
1427
- fn script_for_p2wpkh ( key : & PublicKey ) -> Script {
1442
+ fn get_p2wpkh_redeemscript ( key : & PublicKey ) -> Script {
1428
1443
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_PUSHBYTES_0 )
1429
1444
. push_slice ( & WPubkeyHash :: hash ( & key. serialize ( ) ) [ ..] )
1430
1445
. into_script ( )
@@ -1435,7 +1450,7 @@ mod tests {
1435
1450
use super :: CounterpartyCommitmentSecrets ;
1436
1451
use :: { hex, chain} ;
1437
1452
use prelude:: * ;
1438
- use ln:: chan_utils:: { CommitmentTransaction , TxCreationKeys , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , HTLCOutputInCommitment } ;
1453
+ use ln:: chan_utils:: { get_to_countersignatory_with_anchors_redeemscript , get_p2wpkh_redeemscript , CommitmentTransaction , TxCreationKeys , ChannelTransactionParameters , CounterpartyChannelTransactionParameters , HTLCOutputInCommitment } ;
1439
1454
use bitcoin:: secp256k1:: { PublicKey , SecretKey , Secp256k1 } ;
1440
1455
use util:: test_utils;
1441
1456
use chain:: keysinterface:: { KeysInterface , BaseSign } ;
@@ -1478,6 +1493,7 @@ mod tests {
1478
1493
& mut htlcs_with_aux, & channel_parameters. as_holder_broadcastable ( )
1479
1494
) ;
1480
1495
assert_eq ! ( tx. built. transaction. output. len( ) , 2 ) ;
1496
+ assert_eq ! ( tx. built. transaction. output[ 1 ] . script_pubkey, get_p2wpkh_redeemscript( & counterparty_pubkeys. payment_point) ) ;
1481
1497
1482
1498
// Generate broadcaster and counterparty outputs as well as two anchors
1483
1499
let tx = CommitmentTransaction :: new_with_auxiliary_htlc_data (
@@ -1489,6 +1505,7 @@ mod tests {
1489
1505
& mut htlcs_with_aux, & channel_parameters. as_holder_broadcastable ( )
1490
1506
) ;
1491
1507
assert_eq ! ( tx. built. transaction. output. len( ) , 4 ) ;
1508
+ assert_eq ! ( tx. built. transaction. output[ 3 ] . script_pubkey, get_to_countersignatory_with_anchors_redeemscript( & counterparty_pubkeys. payment_point) . to_v0_p2wsh( ) ) ;
1492
1509
1493
1510
// Generate broadcaster output and anchor
1494
1511
let tx = CommitmentTransaction :: new_with_auxiliary_htlc_data (
0 commit comments