@@ -1374,6 +1374,8 @@ pub struct CommitmentTransaction {
13741374 built : BuiltCommitmentTransaction ,
13751375 // delayed spk
13761376 revokeable_spk : ScriptBuf ,
1377+ // to_remote spk
1378+ to_remote_spk : ScriptBuf ,
13771379}
13781380
13791381impl Eq for CommitmentTransaction { }
@@ -1386,7 +1388,8 @@ impl PartialEq for CommitmentTransaction {
13861388 self . htlcs == o. htlcs &&
13871389 self . channel_type_features == o. channel_type_features &&
13881390 self . keys == o. keys &&
1389- self . revokeable_spk == o. revokeable_spk ;
1391+ self . revokeable_spk == o. revokeable_spk &&
1392+ self . to_remote_spk == o. to_remote_spk ;
13901393 if eq {
13911394 debug_assert_eq ! ( self . built. transaction, o. built. transaction) ;
13921395 debug_assert_eq ! ( self . built. txid, o. built. txid) ;
@@ -1410,6 +1413,7 @@ impl Writeable for CommitmentTransaction {
14101413 ( 14 , legacy_deserialization_prevention_marker, option) ,
14111414 ( 15 , self . channel_type_features, required) ,
14121415 ( 16 , self . revokeable_spk, required) ,
1416+ ( 18 , self . to_remote_spk, required) ,
14131417 } ) ;
14141418 Ok ( ( ) )
14151419 }
@@ -1429,6 +1433,7 @@ impl Readable for CommitmentTransaction {
14291433 ( 14 , _legacy_deserialization_prevention_marker, ( option, explicit_type: ( ) ) ) ,
14301434 ( 15 , channel_type_features, option) ,
14311435 ( 16 , revokeable_spk, required) ,
1436+ ( 18 , to_remote_spk, required) ,
14321437 } ) ;
14331438
14341439 let mut additional_features = ChannelTypeFeatures :: empty ( ) ;
@@ -1446,6 +1451,7 @@ impl Readable for CommitmentTransaction {
14461451 htlcs,
14471452 channel_type_features : channel_type_features. unwrap_or ( ChannelTypeFeatures :: only_static_remote_key ( ) ) ,
14481453 revokeable_spk : revokeable_spk. 0 . unwrap ( ) ,
1454+ to_remote_spk : to_remote_spk. 0 . unwrap ( ) ,
14491455 } )
14501456 }
14511457}
@@ -1466,7 +1472,7 @@ impl CommitmentTransaction {
14661472 let to_countersignatory_value_sat = Amount :: from_sat ( to_countersignatory_value_sat) ;
14671473
14681474 // Sort outputs and populate output indices while keeping track of the auxiliary data
1469- let ( outputs, htlcs, revokeable_spk) = Self :: internal_build_outputs ( & keys. per_commitment_point , to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number) . unwrap ( ) ;
1475+ let ( outputs, htlcs, revokeable_spk, to_remote_spk ) = Self :: internal_build_outputs ( & keys. per_commitment_point , to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number) . unwrap ( ) ;
14701476
14711477 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( commitment_number, channel_parameters) ;
14721478 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
@@ -1485,6 +1491,7 @@ impl CommitmentTransaction {
14851491 txid
14861492 } ,
14871493 revokeable_spk,
1494+ to_remote_spk,
14881495 }
14891496 }
14901497
@@ -1500,7 +1507,7 @@ impl CommitmentTransaction {
15001507 let ( obscured_commitment_transaction_number, txins) = Self :: internal_build_inputs ( self . commitment_number , channel_parameters) ;
15011508
15021509 let mut htlcs_with_aux = self . htlcs . iter ( ) . map ( |h| ( h. clone ( ) , ( ) ) ) . collect ( ) ;
1503- let ( outputs, _, _) = Self :: internal_build_outputs ( per_commitment_point, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self . commitment_number ) ?;
1510+ let ( outputs, _, _, _ ) = Self :: internal_build_outputs ( per_commitment_point, self . to_broadcaster_value_sat , self . to_countersignatory_value_sat , & mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self . commitment_number ) ?;
15041511
15051512 let transaction = Self :: make_transaction ( obscured_commitment_transaction_number, txins, outputs) ;
15061513 let txid = transaction. compute_txid ( ) ;
@@ -1524,13 +1531,14 @@ impl CommitmentTransaction {
15241531 // - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15251532 // caller needs to have sorted together with the HTLCs so it can keep track of the output index
15261533 // - building of a bitcoin transaction during a verify() call, in which case T is just ()
1527- fn internal_build_outputs < T , Signer : ChannelSigner > ( per_commitment_point : & PublicKey , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool , commitment_number : u64 ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > , ScriptBuf ) , ( ) > {
1534+ fn internal_build_outputs < T , Signer : ChannelSigner > ( per_commitment_point : & PublicKey , to_broadcaster_value_sat : Amount , to_countersignatory_value_sat : Amount , htlcs_with_aux : & mut Vec < ( HTLCOutputInCommitment , T ) > , signer : & Signer , secp_ctx : & Secp256k1 < secp256k1:: All > , is_holder_tx : bool , commitment_number : u64 ) -> Result < ( Vec < TxOut > , Vec < HTLCOutputInCommitment > , ScriptBuf , ScriptBuf ) , ( ) > {
15281535 let mut txouts: Vec < ( TxOut , Option < & mut HTLCOutputInCommitment > ) > = Vec :: new ( ) ;
15291536
1537+ let to_remote_spk = signer. get_counterparty_payment_script ( is_holder_tx) ;
15301538 if to_countersignatory_value_sat > Amount :: ZERO {
15311539 txouts. push ( (
15321540 TxOut {
1533- script_pubkey : signer . get_counterparty_payment_script ( is_holder_tx ) ,
1541+ script_pubkey : to_remote_spk . clone ( ) ,
15341542 value : to_countersignatory_value_sat,
15351543 } ,
15361544 None ,
@@ -1593,7 +1601,7 @@ impl CommitmentTransaction {
15931601 }
15941602 outputs. push ( out. 0 ) ;
15951603 }
1596- Ok ( ( outputs, htlcs, revokeable_spk) )
1604+ Ok ( ( outputs, htlcs, revokeable_spk, to_remote_spk ) )
15971605 }
15981606
15991607 fn internal_build_inputs ( commitment_number : u64 , channel_parameters : & DirectedChannelTransactionParameters ) -> ( u64 , Vec < TxIn > ) {
@@ -1762,6 +1770,11 @@ impl<'a> TrustedCommitmentTransaction<'a> {
17621770 self . inner . revokeable_spk . clone ( )
17631771 }
17641772
1773+ /// To remote spk
1774+ pub fn to_remote_spk ( & self ) -> ScriptBuf {
1775+ self . inner . to_remote_spk . clone ( )
1776+ }
1777+
17651778 /// Helper method to build an unsigned justice transaction spending the revokeable
17661779 /// `to_local` output to a destination script. Fee estimation accounts for the expected
17671780 /// revocation witness data that will be added when signed.
0 commit comments