@@ -470,13 +470,9 @@ struct NegotiationContext {
470470 /// - For the initiator:
471471 /// The output intended to be the new funding output. This will be added alonside to the
472472 /// provided outputs.
473- /// The value is the holder's intended contribution to the shared funding output
474- /// (must be less or equal then the amount of the output).
475473 /// - For the acceptor:
476474 /// The output expected as new funding output. It should be added by the initiator node.
477- /// The value is the holder's intended contribution to the shared funding output
478- /// (must be less or equal then the amount of the output).
479- shared_funding_output : ( TxOut , u64 ) ,
475+ shared_funding_output : SharedOwnedOutput ,
480476 prevtx_outpoints : HashSet < OutPoint > ,
481477 /// The outputs added so far.
482478 outputs : HashMap < SerialId , InteractiveTxOutput > ,
@@ -513,7 +509,7 @@ fn is_serial_id_valid_for_counterparty(holder_is_initiator: bool, serial_id: Ser
513509impl NegotiationContext {
514510 fn new (
515511 holder_node_id : PublicKey , counterparty_node_id : PublicKey , holder_is_initiator : bool ,
516- shared_funding_output : ( TxOut , u64 ) , tx_locktime : AbsoluteLockTime ,
512+ shared_funding_output : SharedOwnedOutput , tx_locktime : AbsoluteLockTime ,
517513 feerate_sat_per_kw : u32 ,
518514 ) -> Self {
519515 NegotiationContext {
@@ -725,7 +721,7 @@ impl NegotiationContext {
725721 }
726722
727723 let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
728- let output = if txout == self . shared_funding_output . 0 {
724+ let output = if txout == self . shared_funding_output . tx_out {
729725 // this is the shared output
730726 if self . holder_is_initiator {
731727 return Err ( AbortReason :: DuplicateFundingOutput ) ;
@@ -734,7 +730,7 @@ impl NegotiationContext {
734730 if self . outputs . values ( ) . any ( |output| matches ! ( output. output, OutputOwned :: Shared ( _) ) ) {
735731 return Err ( AbortReason :: DuplicateFundingOutput ) ;
736732 }
737- OutputOwned :: Shared ( SharedOwnedOutput :: new ( txout , self . shared_funding_output . 1 ) )
733+ OutputOwned :: Shared ( self . shared_funding_output . clone ( ) )
738734 } else {
739735 OutputOwned :: Single ( txout)
740736 } ;
@@ -793,9 +789,9 @@ impl NegotiationContext {
793789
794790 fn sent_tx_add_output ( & mut self , msg : & msgs:: TxAddOutput ) -> Result < ( ) , AbortReason > {
795791 let txout = TxOut { value : Amount :: from_sat ( msg. sats ) , script_pubkey : msg. script . clone ( ) } ;
796- let output = if txout == self . shared_funding_output . 0 {
792+ let output = if txout == self . shared_funding_output . tx_out {
797793 // this is the shared output
798- OutputOwned :: Shared ( SharedOwnedOutput :: new ( txout , self . shared_funding_output . 1 ) )
794+ OutputOwned :: Shared ( self . shared_funding_output . clone ( ) )
799795 } else {
800796 OutputOwned :: Single ( txout)
801797 } ;
@@ -862,7 +858,10 @@ impl NegotiationContext {
862858
863859 let shared_funding_output = self . shared_funding_output . clone ( ) ;
864860 let constructed_tx = ConstructedTransaction :: new ( self ) ;
865- if !constructed_tx. outputs . iter ( ) . any ( |output| * output. tx_out ( ) == shared_funding_output. 0 )
861+ if !constructed_tx
862+ . outputs
863+ . iter ( )
864+ . any ( |output| * output. tx_out ( ) == shared_funding_output. tx_out )
866865 {
867866 return Err ( AbortReason :: MissingFundingOutput ) ;
868867 }
@@ -1077,7 +1076,8 @@ macro_rules! define_state_machine_transitions {
10771076impl StateMachine {
10781077 fn new (
10791078 holder_node_id : PublicKey , counterparty_node_id : PublicKey , feerate_sat_per_kw : u32 ,
1080- is_initiator : bool , tx_locktime : AbsoluteLockTime , shared_funding_output : ( TxOut , u64 ) ,
1079+ is_initiator : bool , tx_locktime : AbsoluteLockTime ,
1080+ shared_funding_output : SharedOwnedOutput ,
10811081 ) -> Self {
10821082 let context = NegotiationContext :: new (
10831083 holder_node_id,
@@ -1183,7 +1183,7 @@ impl_writeable_tlv_based_enum!(InteractiveTxInput,
11831183) ;
11841184
11851185#[ derive( Clone , Debug , Eq , PartialEq ) ]
1186- struct SharedOwnedOutput {
1186+ pub ( super ) struct SharedOwnedOutput {
11871187 tx_out : TxOut ,
11881188 local_owned : u64 ,
11891189}
@@ -1497,7 +1497,7 @@ where
14971497 pub is_initiator : bool ,
14981498 pub funding_tx_locktime : AbsoluteLockTime ,
14991499 pub inputs_to_contribute : Vec < ( TxIn , TransactionU16LenLimited ) > ,
1500- pub shared_funding_output : ( TxOut , u64 ) ,
1500+ pub shared_funding_output : SharedOwnedOutput ,
15011501 pub outputs_to_contribute : Vec < TxOut > ,
15021502}
15031503
@@ -1555,10 +1555,7 @@ impl InteractiveTxConstructor {
15551555 . collect ( ) ;
15561556 if is_initiator {
15571557 let serial_id = generate_holder_serial_id ( entropy_source, is_initiator) ;
1558- let output = OutputOwned :: Shared ( SharedOwnedOutput :: new (
1559- shared_funding_output. 0 ,
1560- shared_funding_output. 1 ,
1561- ) ) ;
1558+ let output = OutputOwned :: Shared ( shared_funding_output) ;
15621559 outputs_to_contribute. push ( ( serial_id, output) ) ;
15631560 }
15641561 // In the same manner and for the same rationale as the inputs above, we'll shuffle the outputs.
@@ -1744,8 +1741,8 @@ mod tests {
17441741 use crate :: ln:: interactivetxs:: {
17451742 calculate_change_output_value, generate_holder_serial_id, AbortReason ,
17461743 HandleTxCompleteValue , InteractiveTxConstructor , InteractiveTxConstructorArgs ,
1747- InteractiveTxMessageSend , MAX_INPUTS_OUTPUTS_COUNT , MAX_RECEIVED_TX_ADD_INPUT_COUNT ,
1748- MAX_RECEIVED_TX_ADD_OUTPUT_COUNT ,
1744+ InteractiveTxMessageSend , SharedOwnedOutput , MAX_INPUTS_OUTPUTS_COUNT ,
1745+ MAX_RECEIVED_TX_ADD_INPUT_COUNT , MAX_RECEIVED_TX_ADD_OUTPUT_COUNT ,
17491746 } ;
17501747 use crate :: ln:: types:: ChannelId ;
17511748 use crate :: sign:: EntropySource ;
@@ -1862,7 +1859,10 @@ mod tests {
18621859 is_initiator : true ,
18631860 funding_tx_locktime,
18641861 inputs_to_contribute : session. inputs_a ,
1865- shared_funding_output : ( session. shared_output_a . 0 , session. shared_output_a . 1 ) ,
1862+ shared_funding_output : SharedOwnedOutput :: new (
1863+ session. shared_output_a . 0 ,
1864+ session. shared_output_a . 1 ,
1865+ ) ,
18661866 outputs_to_contribute : session. outputs_a ,
18671867 } ) {
18681868 Ok ( r) => r,
@@ -1885,7 +1885,10 @@ mod tests {
18851885 is_initiator : false ,
18861886 funding_tx_locktime,
18871887 inputs_to_contribute : session. inputs_b ,
1888- shared_funding_output : ( session. shared_output_b . 0 , session. shared_output_b . 1 ) ,
1888+ shared_funding_output : SharedOwnedOutput :: new (
1889+ session. shared_output_b . 0 ,
1890+ session. shared_output_b . 1 ,
1891+ ) ,
18891892 outputs_to_contribute : session. outputs_b ,
18901893 } ) {
18911894 Ok ( r) => r,
0 commit comments