@@ -199,7 +199,7 @@ pub(crate) struct ConstructedTransaction {
199
199
holder_is_initiator : bool ,
200
200
201
201
inputs : Vec < NegotiatedTxInput > ,
202
- outputs : Vec < InteractiveTxOutput > ,
202
+ outputs : Vec < NegotiatedTxOutput > ,
203
203
tx : Transaction ,
204
204
205
205
local_inputs_value_satoshis : u64 ,
@@ -217,6 +217,11 @@ pub(crate) struct NegotiatedTxInput {
217
217
prev_output : TxOut ,
218
218
}
219
219
220
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
221
+ pub ( crate ) struct NegotiatedTxOutput {
222
+ serial_id : SerialId ,
223
+ }
224
+
220
225
impl NegotiatedTxInput {
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,11 +232,21 @@ impl NegotiatedTxInput {
227
232
}
228
233
}
229
234
235
+ impl NegotiatedTxOutput {
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 ! ( NegotiatedTxInput , {
231
242
( 1 , serial_id, required) ,
232
243
( 3 , prev_output, required) ,
233
244
} ) ;
234
245
246
+ impl_writeable_tlv_based ! ( NegotiatedTxOutput , {
247
+ ( 1 , serial_id, required) ,
248
+ } ) ;
249
+
235
250
impl_writeable_tlv_based ! ( ConstructedTransaction , {
236
251
( 1 , holder_is_initiator, required) ,
237
252
( 3 , inputs, required) ,
@@ -282,9 +297,10 @@ impl ConstructedTransaction {
282
297
283
298
let mut inputs: Vec < ( TxIn , NegotiatedTxInput ) > =
284
299
context. inputs . into_values ( ) . map ( |input| input. into_txin_and_negotiated_input ( ) ) . collect ( ) ;
285
- let mut outputs: Vec < InteractiveTxOutput > = context. outputs . into_values ( ) . collect ( ) ;
300
+ let mut outputs: Vec < ( TxOut , NegotiatedTxOutput ) > =
301
+ context. outputs . into_values ( ) . map ( |output| output. into_txout_and_negotiated_output ( ) ) . collect ( ) ;
286
302
inputs. sort_unstable_by_key ( |( _, input) | input. serial_id ) ;
287
- outputs. sort_unstable_by_key ( |output| output. serial_id ) ;
303
+ outputs. sort_unstable_by_key ( |( _ , output) | output. serial_id ) ;
288
304
289
305
let shared_input_index =
290
306
context. shared_funding_input . as_ref ( ) . and_then ( |shared_funding_input| {
@@ -297,7 +313,7 @@ impl ConstructedTransaction {
297
313
} ) ;
298
314
299
315
let ( input, inputs) : ( Vec < TxIn > , Vec < NegotiatedTxInput > ) = inputs. into_iter ( ) . unzip ( ) ;
300
- let output = outputs. iter ( ) . map ( |output| output . tx_out ( ) . clone ( ) ) . collect ( ) ;
316
+ let ( output, outputs) : ( Vec < TxOut > , Vec < NegotiatedTxOutput > ) = outputs . into_iter ( ) . unzip ( ) ;
301
317
302
318
let tx = Transaction {
303
319
version : Version :: TWO ,
@@ -332,10 +348,6 @@ impl ConstructedTransaction {
332
348
& self . tx
333
349
}
334
350
335
- pub fn outputs ( & self ) -> impl Iterator < Item = & InteractiveTxOutput > {
336
- self . outputs . iter ( )
337
- }
338
-
339
351
pub fn inputs ( & self ) -> impl Iterator < Item = & NegotiatedTxInput > {
340
352
self . inputs . iter ( )
341
353
}
@@ -567,12 +579,7 @@ impl InteractiveTxSigningSession {
567
579
. outputs
568
580
. iter ( )
569
581
. enumerate ( )
570
- . filter ( |( _, output) | {
571
- !is_serial_id_valid_for_counterparty (
572
- self . unsigned_tx . holder_is_initiator ,
573
- output. serial_id ,
574
- )
575
- } )
582
+ . filter ( |( _, output) | output. is_local ( self . unsigned_tx . holder_is_initiator ) )
576
583
. count ( )
577
584
}
578
585
@@ -1768,12 +1775,6 @@ pub(crate) struct InteractiveTxOutput {
1768
1775
output : OutputOwned ,
1769
1776
}
1770
1777
1771
- impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1772
- ( 1 , serial_id, required) ,
1773
- ( 3 , added_by, required) ,
1774
- ( 5 , output, required) ,
1775
- } ) ;
1776
-
1777
1778
impl InteractiveTxOutput {
1778
1779
pub fn tx_out ( & self ) -> & TxOut {
1779
1780
self . output . tx_out ( )
@@ -1798,6 +1799,11 @@ impl InteractiveTxOutput {
1798
1799
pub fn script_pubkey ( & self ) -> & ScriptBuf {
1799
1800
& self . output . tx_out ( ) . script_pubkey
1800
1801
}
1802
+
1803
+ fn into_txout_and_negotiated_output ( self ) -> ( TxOut , NegotiatedTxOutput ) {
1804
+ let txout = self . output . into_tx_out ( ) ;
1805
+ ( txout, NegotiatedTxOutput { serial_id : self . serial_id } )
1806
+ }
1801
1807
}
1802
1808
1803
1809
impl InteractiveTxInput {
@@ -2221,9 +2227,9 @@ mod tests {
2221
2227
use core:: ops:: Deref ;
2222
2228
2223
2229
use super :: {
2224
- get_output_weight, AddingRole , ConstructedTransaction , InteractiveTxOutput ,
2225
- InteractiveTxSigningSession , NegotiatedTxInput , OutputOwned , P2TR_INPUT_WEIGHT_LOWER_BOUND ,
2226
- P2WPKH_INPUT_WEIGHT_LOWER_BOUND , P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2230
+ get_output_weight, ConstructedTransaction , InteractiveTxSigningSession , NegotiatedTxInput ,
2231
+ P2TR_INPUT_WEIGHT_LOWER_BOUND , P2WPKH_INPUT_WEIGHT_LOWER_BOUND ,
2232
+ P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2227
2233
} ;
2228
2234
2229
2235
const TEST_FEERATE_SATS_PER_KW : u32 = FEERATE_FLOOR_SATS_PER_KW * 10 ;
@@ -3302,21 +3308,10 @@ mod tests {
3302
3308
} )
3303
3309
. collect ( ) ;
3304
3310
3305
- let outputs: Vec < InteractiveTxOutput > = transaction
3306
- . output
3307
- . iter ( )
3308
- . cloned ( )
3309
- . map ( |txout| InteractiveTxOutput {
3310
- serial_id : 0 , // N/A for test
3311
- added_by : AddingRole :: Local ,
3312
- output : OutputOwned :: Single ( txout) ,
3313
- } )
3314
- . collect ( ) ;
3315
-
3316
3311
let unsigned_tx = ConstructedTransaction {
3317
3312
holder_is_initiator : true ,
3318
3313
inputs,
3319
- outputs,
3314
+ outputs : vec ! [ ] , // N/A for test
3320
3315
tx : transaction. clone ( ) ,
3321
3316
local_inputs_value_satoshis : 0 , // N/A for test
3322
3317
local_outputs_value_satoshis : 0 , // N/A for test
0 commit comments