@@ -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) ,
@@ -284,9 +299,13 @@ impl ConstructedTransaction {
284
299
. into_values ( )
285
300
. map ( |input| input. into_txin_and_negotiated_input ( ) )
286
301
. collect ( ) ;
287
- let mut outputs: Vec < InteractiveTxOutput > = context. outputs . into_values ( ) . collect ( ) ;
302
+ let mut outputs: Vec < ( TxOut , NegotiatedTxOutput ) > = context
303
+ . outputs
304
+ . into_values ( )
305
+ . map ( |output| output. into_txout_and_negotiated_output ( ) )
306
+ . collect ( ) ;
288
307
inputs. sort_unstable_by_key ( |( _, input) | input. serial_id ) ;
289
- outputs. sort_unstable_by_key ( |output| output. serial_id ) ;
308
+ outputs. sort_unstable_by_key ( |( _ , output) | output. serial_id ) ;
290
309
291
310
let shared_input_index =
292
311
context. shared_funding_input . as_ref ( ) . and_then ( |shared_funding_input| {
@@ -299,7 +318,7 @@ impl ConstructedTransaction {
299
318
} ) ;
300
319
301
320
let ( input, inputs) : ( Vec < TxIn > , Vec < NegotiatedTxInput > ) = inputs. into_iter ( ) . unzip ( ) ;
302
- let output = outputs. iter ( ) . map ( |output| output . tx_out ( ) . clone ( ) ) . collect ( ) ;
321
+ let ( output, outputs) : ( Vec < TxOut > , Vec < NegotiatedTxOutput > ) = outputs . into_iter ( ) . unzip ( ) ;
303
322
304
323
let tx =
305
324
Transaction { version : Version :: TWO , lock_time : context. tx_locktime , input, output } ;
@@ -330,10 +349,6 @@ impl ConstructedTransaction {
330
349
& self . tx
331
350
}
332
351
333
- pub fn outputs ( & self ) -> impl Iterator < Item = & InteractiveTxOutput > {
334
- self . outputs . iter ( )
335
- }
336
-
337
352
pub fn inputs ( & self ) -> impl Iterator < Item = & NegotiatedTxInput > {
338
353
self . inputs . iter ( )
339
354
}
@@ -565,12 +580,7 @@ impl InteractiveTxSigningSession {
565
580
. outputs
566
581
. iter ( )
567
582
. enumerate ( )
568
- . filter ( |( _, output) | {
569
- !is_serial_id_valid_for_counterparty (
570
- self . unsigned_tx . holder_is_initiator ,
571
- output. serial_id ,
572
- )
573
- } )
583
+ . filter ( |( _, output) | output. is_local ( self . unsigned_tx . holder_is_initiator ) )
574
584
. count ( )
575
585
}
576
586
@@ -1774,12 +1784,6 @@ pub(crate) struct InteractiveTxOutput {
1774
1784
output : OutputOwned ,
1775
1785
}
1776
1786
1777
- impl_writeable_tlv_based ! ( InteractiveTxOutput , {
1778
- ( 1 , serial_id, required) ,
1779
- ( 3 , added_by, required) ,
1780
- ( 5 , output, required) ,
1781
- } ) ;
1782
-
1783
1787
impl InteractiveTxOutput {
1784
1788
pub fn tx_out ( & self ) -> & TxOut {
1785
1789
self . output . tx_out ( )
@@ -1804,6 +1808,11 @@ impl InteractiveTxOutput {
1804
1808
pub fn script_pubkey ( & self ) -> & ScriptBuf {
1805
1809
& self . output . tx_out ( ) . script_pubkey
1806
1810
}
1811
+
1812
+ fn into_txout_and_negotiated_output ( self ) -> ( TxOut , NegotiatedTxOutput ) {
1813
+ let txout = self . output . into_tx_out ( ) ;
1814
+ ( txout, NegotiatedTxOutput { serial_id : self . serial_id } )
1815
+ }
1807
1816
}
1808
1817
1809
1818
impl InteractiveTxInput {
@@ -2227,9 +2236,9 @@ mod tests {
2227
2236
use core:: ops:: Deref ;
2228
2237
2229
2238
use super :: {
2230
- get_output_weight, AddingRole , ConstructedTransaction , InteractiveTxOutput ,
2231
- InteractiveTxSigningSession , NegotiatedTxInput , OutputOwned , P2TR_INPUT_WEIGHT_LOWER_BOUND ,
2232
- P2WPKH_INPUT_WEIGHT_LOWER_BOUND , P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2239
+ get_output_weight, ConstructedTransaction , InteractiveTxSigningSession , NegotiatedTxInput ,
2240
+ P2TR_INPUT_WEIGHT_LOWER_BOUND , P2WPKH_INPUT_WEIGHT_LOWER_BOUND ,
2241
+ P2WSH_INPUT_WEIGHT_LOWER_BOUND , TX_COMMON_FIELDS_WEIGHT ,
2233
2242
} ;
2234
2243
2235
2244
const TEST_FEERATE_SATS_PER_KW : u32 = FEERATE_FLOOR_SATS_PER_KW * 10 ;
@@ -3312,21 +3321,10 @@ mod tests {
3312
3321
} )
3313
3322
. collect ( ) ;
3314
3323
3315
- let outputs: Vec < InteractiveTxOutput > = transaction
3316
- . output
3317
- . iter ( )
3318
- . cloned ( )
3319
- . map ( |txout| InteractiveTxOutput {
3320
- serial_id : 0 , // N/A for test
3321
- added_by : AddingRole :: Local ,
3322
- output : OutputOwned :: Single ( txout) ,
3323
- } )
3324
- . collect ( ) ;
3325
-
3326
3324
let unsigned_tx = ConstructedTransaction {
3327
3325
holder_is_initiator : true ,
3328
3326
inputs,
3329
- outputs,
3327
+ outputs : vec ! [ ] , // N/A for test
3330
3328
tx : transaction. clone ( ) ,
3331
3329
local_inputs_value_satoshis : 0 , // N/A for test
3332
3330
local_outputs_value_satoshis : 0 , // N/A for test
0 commit comments