@@ -199,7 +199,7 @@ pub(crate) struct ConstructedTransaction {
199
199
holder_is_initiator : bool ,
200
200
201
201
input_metadata : Vec < TxInMetadata > ,
202
- outputs : Vec < InteractiveTxOutput > ,
202
+ output_metadata : Vec < TxOutMetadata > ,
203
203
tx : Transaction ,
204
204
205
205
local_inputs_value_satoshis : u64 ,
@@ -217,6 +217,11 @@ pub(crate) struct TxInMetadata {
217
217
prev_output : TxOut ,
218
218
}
219
219
220
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
221
+ pub ( crate ) struct TxOutMetadata {
222
+ serial_id : SerialId ,
223
+ }
224
+
220
225
impl TxInMetadata {
221
226
pub ( super ) fn is_local ( & self , holder_is_initiator : bool ) -> bool {
222
227
!is_serial_id_valid_for_counterparty ( holder_is_initiator, self . serial_id )
@@ -227,15 +232,25 @@ impl TxInMetadata {
227
232
}
228
233
}
229
234
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
+
230
241
impl_writeable_tlv_based ! ( TxInMetadata , {
231
242
( 1 , serial_id, required) ,
232
243
( 3 , prev_output, required) ,
233
244
} ) ;
234
245
246
+ impl_writeable_tlv_based ! ( TxOutMetadata , {
247
+ ( 1 , serial_id, required) ,
248
+ } ) ;
249
+
235
250
impl_writeable_tlv_based ! ( ConstructedTransaction , {
236
251
( 1 , holder_is_initiator, required) ,
237
252
( 3 , input_metadata, required) ,
238
- ( 5 , outputs , required) ,
253
+ ( 5 , output_metadata , required) ,
239
254
( 7 , tx, required) ,
240
255
( 9 , local_inputs_value_satoshis, required) ,
241
256
( 11 , local_outputs_value_satoshis, required) ,
@@ -281,9 +296,10 @@ impl ConstructedTransaction {
281
296
282
297
let mut inputs: Vec < ( TxIn , TxInMetadata ) > =
283
298
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 ( ) ;
285
301
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 ) ;
287
303
288
304
let shared_input_index =
289
305
context. shared_funding_input . as_ref ( ) . and_then ( |shared_funding_input| {
@@ -296,7 +312,8 @@ impl ConstructedTransaction {
296
312
} ) ;
297
313
298
314
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 ( ) ;
300
317
301
318
let tx =
302
319
Transaction { version : Version :: TWO , lock_time : context. tx_locktime , input, output } ;
@@ -316,7 +333,7 @@ impl ConstructedTransaction {
316
333
remote_outputs_value_satoshis,
317
334
318
335
input_metadata,
319
- outputs ,
336
+ output_metadata ,
320
337
tx,
321
338
322
339
shared_input_index,
@@ -327,10 +344,6 @@ impl ConstructedTransaction {
327
344
& self . tx
328
345
}
329
346
330
- pub fn outputs ( & self ) -> impl Iterator < Item = & InteractiveTxOutput > {
331
- self . outputs . iter ( )
332
- }
333
-
334
347
pub fn input_metadata ( & self ) -> impl Iterator < Item = & TxInMetadata > {
335
348
self . input_metadata . iter ( )
336
349
}
@@ -559,15 +572,10 @@ impl InteractiveTxSigningSession {
559
572
560
573
fn local_outputs_count ( & self ) -> usize {
561
574
self . unsigned_tx
562
- . outputs
575
+ . output_metadata
563
576
. iter ( )
564
577
. 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 ) )
571
579
. count ( )
572
580
}
573
581
@@ -1771,12 +1779,6 @@ pub(crate) struct InteractiveTxOutput {
1771
1779
output : OutputOwned ,
1772
1780
}
1773
1781
1774
- impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1775
- ( 1 , serial_id, required) ,
1776
- ( 3 , added_by, required) ,
1777
- ( 5 , output, required) ,
1778
- } ) ;
1779
-
1780
1782
impl InteractiveTxOutput {
1781
1783
pub fn tx_out ( & self ) -> & TxOut {
1782
1784
self . output . tx_out ( )
@@ -1801,6 +1803,11 @@ impl InteractiveTxOutput {
1801
1803
pub fn script_pubkey ( & self ) -> & ScriptBuf {
1802
1804
& self . output . tx_out ( ) . script_pubkey
1803
1805
}
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
+ }
1804
1811
}
1805
1812
1806
1813
impl InteractiveTxInput {
@@ -2224,9 +2231,9 @@ mod tests {
2224
2231
use core:: ops:: Deref ;
2225
2232
2226
2233
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 ,
2230
2237
} ;
2231
2238
2232
2239
const TEST_FEERATE_SATS_PER_KW : u32 = FEERATE_FLOOR_SATS_PER_KW * 10 ;
@@ -3309,21 +3316,10 @@ mod tests {
3309
3316
} )
3310
3317
. collect ( ) ;
3311
3318
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
-
3323
3319
let unsigned_tx = ConstructedTransaction {
3324
3320
holder_is_initiator : true ,
3325
3321
input_metadata,
3326
- outputs ,
3322
+ output_metadata : vec ! [ ] , // N/A for test
3327
3323
tx : transaction. clone ( ) ,
3328
3324
local_inputs_value_satoshis : 0 , // N/A for test
3329
3325
local_outputs_value_satoshis : 0 , // N/A for test
0 commit comments