@@ -91,6 +91,12 @@ pub(crate) enum AbortReason {
9191 IncorrectSerialIdParity ,
9292 SerialIdUnknown ,
9393 DuplicateSerialId ,
94+ /// Invalid provided inputs and previous transactions, several possible reasons:
95+ /// - nonexisting `vout`, or
96+ /// - mismatching `TxId`'s
97+ /// - duplicate input,
98+ /// - not a witness program,
99+ /// etc.
94100 PrevTxOutInvalid ,
95101 ExceededMaximumSatsAllowed ,
96102 ExceededNumberOfInputsOrOutputs ,
@@ -108,10 +114,6 @@ pub(crate) enum AbortReason {
108114 /// if funding output is provided by the peer this is an interop error,
109115 /// if provided by the same node than internal input consistency error.
110116 InvalidLowFundingOutputValue ,
111- /// TxId mismatch in the provided inputs and previous transactions, input index in data
112- ProvidedInputsAndPrevtxsTxIdMismatch ( u32 ) ,
113- /// A vout provided in an input is not found in the matching previous transaction, input index in data
114- ProvidedInputsAndPrevtxsVoutNotFound ( u32 ) ,
115117 /// Internal error, error while getting destination script
116118 InternalErrorGettingDestinationScript ,
117119}
@@ -124,57 +126,39 @@ impl AbortReason {
124126
125127impl Display for AbortReason {
126128 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
127- match self {
128- AbortReason :: InvalidStateTransition => f. write_str ( "State transition was invalid" ) ,
129- AbortReason :: UnexpectedCounterpartyMessage => f. write_str ( "Unexpected message" ) ,
130- AbortReason :: ReceivedTooManyTxAddInputs => {
131- f. write_str ( "Too many `tx_add_input`s received" )
132- } ,
133- AbortReason :: ReceivedTooManyTxAddOutputs => {
134- f. write_str ( "Too many `tx_add_output`s received" )
135- } ,
129+ f. write_str ( match self {
130+ AbortReason :: InvalidStateTransition => "State transition was invalid" ,
131+ AbortReason :: UnexpectedCounterpartyMessage => "Unexpected message" ,
132+ AbortReason :: ReceivedTooManyTxAddInputs => "Too many `tx_add_input`s received" ,
133+ AbortReason :: ReceivedTooManyTxAddOutputs => "Too many `tx_add_output`s received" ,
136134 AbortReason :: IncorrectInputSequenceValue => {
137- f . write_str ( "Input has a sequence value greater than 0xFFFFFFFD" )
135+ "Input has a sequence value greater than 0xFFFFFFFD"
138136 } ,
139- AbortReason :: IncorrectSerialIdParity => {
140- f. write_str ( "Parity for `serial_id` was incorrect" )
141- } ,
142- AbortReason :: SerialIdUnknown => f. write_str ( "The `serial_id` is unknown" ) ,
143- AbortReason :: DuplicateSerialId => f. write_str ( "The `serial_id` already exists" ) ,
144- AbortReason :: PrevTxOutInvalid => f. write_str ( "Invalid previous transaction output" ) ,
137+ AbortReason :: IncorrectSerialIdParity => "Parity for `serial_id` was incorrect" ,
138+ AbortReason :: SerialIdUnknown => "The `serial_id` is unknown" ,
139+ AbortReason :: DuplicateSerialId => "The `serial_id` already exists" ,
140+ AbortReason :: PrevTxOutInvalid => "Invalid previous transaction output" ,
145141 AbortReason :: ExceededMaximumSatsAllowed => {
146- f. write_str ( "Output amount exceeded total bitcoin supply" )
147- } ,
148- AbortReason :: ExceededNumberOfInputsOrOutputs => {
149- f. write_str ( "Too many inputs or outputs" )
142+ "Output amount exceeded total bitcoin supply"
150143 } ,
151- AbortReason :: TransactionTooLarge => f. write_str ( "Transaction weight is too large" ) ,
152- AbortReason :: BelowDustLimit => f. write_str ( "Output amount is below the dust limit" ) ,
153- AbortReason :: InvalidOutputScript => f. write_str ( "The output script is non-standard" ) ,
154- AbortReason :: InsufficientFees => f. write_str ( "Insufficient fees paid" ) ,
144+ AbortReason :: ExceededNumberOfInputsOrOutputs => "Too many inputs or outputs" ,
145+ AbortReason :: TransactionTooLarge => "Transaction weight is too large" ,
146+ AbortReason :: BelowDustLimit => "Output amount is below the dust limit" ,
147+ AbortReason :: InvalidOutputScript => "The output script is non-standard" ,
148+ AbortReason :: InsufficientFees => "Insufficient fees paid" ,
155149 AbortReason :: OutputsValueExceedsInputsValue => {
156- f . write_str ( "Total value of outputs exceeds total value of inputs" )
150+ "Total value of outputs exceeds total value of inputs"
157151 } ,
158- AbortReason :: InvalidTx => f. write_str ( "The transaction is invalid" ) ,
159- AbortReason :: MissingFundingOutput => f. write_str ( "No shared funding output found" ) ,
160- AbortReason :: DuplicateFundingOutput => {
161- f. write_str ( "More than one funding output found" )
152+ AbortReason :: InvalidTx => "The transaction is invalid" ,
153+ AbortReason :: MissingFundingOutput => "No shared funding output found" ,
154+ AbortReason :: DuplicateFundingOutput => "More than one funding output found" ,
155+ AbortReason :: InvalidLowFundingOutputValue => {
156+ "Local part of funding output value is greater than the funding output value"
162157 } ,
163- AbortReason :: InvalidLowFundingOutputValue => f. write_str (
164- "Local part of funding output value is greater than the funding output value" ,
165- ) ,
166- AbortReason :: ProvidedInputsAndPrevtxsTxIdMismatch ( idx) => f. write_fmt ( format_args ! (
167- "TxId mismatch in the provided inputs and previous transactions, input index {}" ,
168- idx
169- ) ) ,
170- AbortReason :: ProvidedInputsAndPrevtxsVoutNotFound ( idx) => f. write_fmt ( format_args ! (
171- "Vout provided in an input is not found in the previous transaction, input index {}" ,
172- idx
173- ) ) ,
174158 AbortReason :: InternalErrorGettingDestinationScript => {
175- f . write_str ( "Internal error getting destination script" )
159+ "Internal error getting destination script"
176160 } ,
177- }
161+ } )
178162 }
179163}
180164
@@ -1765,15 +1749,15 @@ fn txouts_from_input_prev_txs(
17651749) -> Result < Vec < & TxOut > , AbortReason > {
17661750 let mut prev_outputs: Vec < & TxOut > = Vec :: with_capacity ( inputs. len ( ) ) ;
17671751 // Check that vouts exist for each TxIn in provided transactions.
1768- for ( idx , ( txin, tx) ) in inputs. iter ( ) . enumerate ( ) {
1752+ for ( txin, tx) in inputs. iter ( ) {
17691753 let txid = tx. as_transaction ( ) . compute_txid ( ) ;
17701754 if txin. previous_output . txid != txid {
1771- return Err ( AbortReason :: ProvidedInputsAndPrevtxsTxIdMismatch ( idx as u32 ) ) ;
1755+ return Err ( AbortReason :: PrevTxOutInvalid ) ;
17721756 }
17731757 if let Some ( output) = tx. as_transaction ( ) . output . get ( txin. previous_output . vout as usize ) {
17741758 prev_outputs. push ( output) ;
17751759 } else {
1776- return Err ( AbortReason :: ProvidedInputsAndPrevtxsVoutNotFound ( idx as u32 ) ) ;
1760+ return Err ( AbortReason :: PrevTxOutInvalid ) ;
17771761 }
17781762 }
17791763 Ok ( prev_outputs)
0 commit comments