@@ -331,22 +331,6 @@ impl NegotiationContext {
331
331
return Err ( AbortReason :: ExceededNumberOfInputsOrOutputs ) ;
332
332
}
333
333
334
- // Inputs and outputs must be sorted by serial_id
335
- let mut inputs = self . inputs . iter ( ) . collect :: < Vec < _ > > ( ) ;
336
- let mut outputs = self . outputs . iter ( ) . collect :: < Vec < _ > > ( ) ;
337
- inputs. sort_unstable_by_key ( |( serial_id, _) | * serial_id) ;
338
- outputs. sort_unstable_by_key ( |( serial_id, _) | * serial_id) ;
339
-
340
- let tx_to_validate = Transaction {
341
- version : 2 ,
342
- lock_time : self . tx_locktime ,
343
- input : inputs. into_iter ( ) . map ( |( _, input) | input. input . clone ( ) ) . collect ( ) ,
344
- output : outputs. into_iter ( ) . map ( |( _, output) | output. clone ( ) ) . collect ( ) ,
345
- } ;
346
- if tx_to_validate. weight ( ) . to_wu ( ) > MAX_STANDARD_TX_WEIGHT as u64 {
347
- return Err ( AbortReason :: TransactionTooLarge ) ;
348
- }
349
-
350
334
// TODO: How do we enforce their fees cover the witness without knowing its expected length?
351
335
const INPUT_WEIGHT : u64 = BASE_INPUT_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT ;
352
336
@@ -379,6 +363,22 @@ impl NegotiationContext {
379
363
return Err ( AbortReason :: InsufficientFees ) ;
380
364
}
381
365
366
+ // Inputs and outputs must be sorted by serial_id
367
+ let mut inputs = self . inputs . into_iter ( ) . collect :: < Vec < _ > > ( ) ;
368
+ let mut outputs = self . outputs . into_iter ( ) . collect :: < Vec < _ > > ( ) ;
369
+ inputs. sort_unstable_by_key ( |( serial_id, _) | * serial_id) ;
370
+ outputs. sort_unstable_by_key ( |( serial_id, _) | * serial_id) ;
371
+
372
+ let tx_to_validate = Transaction {
373
+ version : 2 ,
374
+ lock_time : self . tx_locktime ,
375
+ input : inputs. into_iter ( ) . map ( |( _, input) | input. input ) . collect ( ) ,
376
+ output : outputs. into_iter ( ) . map ( |( _, output) | output) . collect ( ) ,
377
+ } ;
378
+ if tx_to_validate. weight ( ) . to_wu ( ) > MAX_STANDARD_TX_WEIGHT as u64 {
379
+ return Err ( AbortReason :: TransactionTooLarge ) ;
380
+ }
381
+
382
382
Ok ( tx_to_validate)
383
383
}
384
384
}
0 commit comments