@@ -199,7 +199,7 @@ pub(crate) struct ConstructedTransaction {
199199 holder_is_initiator : bool ,
200200
201201 input_metadata : Vec < TxInMetadata > ,
202- outputs : Vec < InteractiveTxOutput > ,
202+ output_metadata : Vec < TxOutMetadata > ,
203203 tx : Transaction ,
204204
205205 local_inputs_value_satoshis : u64 ,
@@ -217,6 +217,11 @@ pub(crate) struct TxInMetadata {
217217 prev_output : TxOut ,
218218}
219219
220+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
221+ pub ( crate ) struct TxOutMetadata {
222+ serial_id : SerialId ,
223+ }
224+
220225impl TxInMetadata {
221226 pub ( super ) fn is_local ( & self , holder_is_initiator : bool ) -> bool {
222227 !is_serial_id_valid_for_counterparty ( holder_is_initiator, self . serial_id )
@@ -227,15 +232,25 @@ impl TxInMetadata {
227232 }
228233}
229234
235+ impl TxOutMetadata {
236+ pub ( super ) fn is_local ( & self , holder_is_initiator : bool ) -> bool {
237+ !is_serial_id_valid_for_counterparty ( holder_is_initiator, self . serial_id )
238+ }
239+ }
240+
230241impl_writeable_tlv_based ! ( TxInMetadata , {
231242 ( 1 , serial_id, required) ,
232243 ( 3 , prev_output, required) ,
233244} ) ;
234245
246+ impl_writeable_tlv_based ! ( TxOutMetadata , {
247+ ( 1 , serial_id, required) ,
248+ } ) ;
249+
235250impl_writeable_tlv_based ! ( ConstructedTransaction , {
236251 ( 1 , holder_is_initiator, required) ,
237252 ( 3 , input_metadata, required) ,
238- ( 5 , outputs , required) ,
253+ ( 5 , output_metadata , required) ,
239254 ( 7 , tx, required) ,
240255 ( 9 , local_inputs_value_satoshis, required) ,
241256 ( 11 , local_outputs_value_satoshis, required) ,
@@ -281,9 +296,10 @@ impl ConstructedTransaction {
281296
282297 let mut inputs: Vec < ( TxIn , TxInMetadata ) > =
283298 context. inputs . into_values ( ) . map ( |input| input. into_txin_and_metadata ( ) ) . collect ( ) ;
284- let mut outputs: Vec < InteractiveTxOutput > = context. outputs . into_values ( ) . collect ( ) ;
299+ let mut outputs: Vec < ( TxOut , TxOutMetadata ) > =
300+ context. outputs . into_values ( ) . map ( |output| output. into_txout_and_metadata ( ) ) . collect ( ) ;
285301 inputs. sort_unstable_by_key ( |( _, input) | input. serial_id ) ;
286- outputs. sort_unstable_by_key ( |output| output. serial_id ) ;
302+ outputs. sort_unstable_by_key ( |( _ , output) | output. serial_id ) ;
287303
288304 let shared_input_index =
289305 context. shared_funding_input . as_ref ( ) . and_then ( |shared_funding_input| {
@@ -296,7 +312,8 @@ impl ConstructedTransaction {
296312 } ) ;
297313
298314 let ( input, input_metadata) : ( Vec < TxIn > , Vec < TxInMetadata > ) = inputs. into_iter ( ) . unzip ( ) ;
299- let output = outputs. iter ( ) . map ( |output| output. tx_out ( ) . clone ( ) ) . collect ( ) ;
315+ let ( output, output_metadata) : ( Vec < TxOut > , Vec < TxOutMetadata > ) =
316+ outputs. into_iter ( ) . unzip ( ) ;
300317
301318 let tx =
302319 Transaction { version : Version :: TWO , lock_time : context. tx_locktime , input, output } ;
@@ -316,7 +333,7 @@ impl ConstructedTransaction {
316333 remote_outputs_value_satoshis,
317334
318335 input_metadata,
319- outputs ,
336+ output_metadata ,
320337 tx,
321338
322339 shared_input_index,
@@ -327,10 +344,6 @@ impl ConstructedTransaction {
327344 & self . tx
328345 }
329346
330- pub fn outputs ( & self ) -> impl Iterator < Item = & InteractiveTxOutput > {
331- self . outputs . iter ( )
332- }
333-
334347 pub fn input_metadata ( & self ) -> impl Iterator < Item = & TxInMetadata > {
335348 self . input_metadata . iter ( )
336349 }
@@ -559,15 +572,10 @@ impl InteractiveTxSigningSession {
559572
560573 fn local_outputs_count ( & self ) -> usize {
561574 self . unsigned_tx
562- . outputs
575+ . output_metadata
563576 . iter ( )
564577 . enumerate ( )
565- . filter ( |( _, output) | {
566- !is_serial_id_valid_for_counterparty (
567- self . unsigned_tx . holder_is_initiator ,
568- output. serial_id ,
569- )
570- } )
578+ . filter ( |( _, output) | output. is_local ( self . unsigned_tx . holder_is_initiator ) )
571579 . count ( )
572580 }
573581
@@ -1771,12 +1779,6 @@ pub(crate) struct InteractiveTxOutput {
17711779 output : OutputOwned ,
17721780}
17731781
1774- impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1775- ( 1 , serial_id, required) ,
1776- ( 3 , added_by, required) ,
1777- ( 5 , output, required) ,
1778- } ) ;
1779-
17801782impl InteractiveTxOutput {
17811783 pub fn tx_out ( & self ) -> & TxOut {
17821784 self . output . tx_out ( )
@@ -1801,6 +1803,11 @@ impl InteractiveTxOutput {
18011803 pub fn script_pubkey ( & self ) -> & ScriptBuf {
18021804 & self . output . tx_out ( ) . script_pubkey
18031805 }
1806+
1807+ fn into_txout_and_metadata ( self ) -> ( TxOut , TxOutMetadata ) {
1808+ let txout = self . output . into_tx_out ( ) ;
1809+ ( txout, TxOutMetadata { serial_id : self . serial_id } )
1810+ }
18041811}
18051812
18061813impl InteractiveTxInput {
@@ -2224,9 +2231,9 @@ mod tests {
22242231 use core:: ops:: Deref ;
22252232
22262233 use super :: {
2227- get_output_weight, AddingRole , ConstructedTransaction , InteractiveTxOutput ,
2228- InteractiveTxSigningSession , OutputOwned , TxInMetadata , P2TR_INPUT_WEIGHT_LOWER_BOUND ,
2229- P2WPKH_INPUT_WEIGHT_LOWER_BOUND , P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2234+ get_output_weight, ConstructedTransaction , InteractiveTxSigningSession , TxInMetadata ,
2235+ P2TR_INPUT_WEIGHT_LOWER_BOUND , P2WPKH_INPUT_WEIGHT_LOWER_BOUND ,
2236+ P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
22302237 } ;
22312238
22322239 const TEST_FEERATE_SATS_PER_KW : u32 = FEERATE_FLOOR_SATS_PER_KW * 10 ;
@@ -3309,21 +3316,10 @@ mod tests {
33093316 } )
33103317 . collect ( ) ;
33113318
3312- let outputs: Vec < InteractiveTxOutput > = transaction
3313- . output
3314- . iter ( )
3315- . cloned ( )
3316- . map ( |txout| InteractiveTxOutput {
3317- serial_id : 0 , // N/A for test
3318- added_by : AddingRole :: Local ,
3319- output : OutputOwned :: Single ( txout) ,
3320- } )
3321- . collect ( ) ;
3322-
33233319 let unsigned_tx = ConstructedTransaction {
33243320 holder_is_initiator : true ,
33253321 input_metadata,
3326- outputs ,
3322+ output_metadata : vec ! [ ] , // N/A for test
33273323 tx : transaction. clone ( ) ,
33283324 local_inputs_value_satoshis : 0 , // N/A for test
33293325 local_outputs_value_satoshis : 0 , // N/A for test
0 commit comments