@@ -91,6 +91,12 @@ pub(crate) enum AbortReason {
91
91
IncorrectSerialIdParity ,
92
92
SerialIdUnknown ,
93
93
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.
94
100
PrevTxOutInvalid ,
95
101
ExceededMaximumSatsAllowed ,
96
102
ExceededNumberOfInputsOrOutputs ,
@@ -108,10 +114,6 @@ pub(crate) enum AbortReason {
108
114
/// if funding output is provided by the peer this is an interop error,
109
115
/// if provided by the same node than internal input consistency error.
110
116
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 ) ,
115
117
/// Internal error, error while getting destination script
116
118
InternalErrorGettingDestinationScript ,
117
119
}
@@ -124,57 +126,39 @@ impl AbortReason {
124
126
125
127
impl Display for AbortReason {
126
128
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" ,
136
134
AbortReason :: IncorrectInputSequenceValue => {
137
- f . write_str ( "Input has a sequence value greater than 0xFFFFFFFD" )
135
+ "Input has a sequence value greater than 0xFFFFFFFD"
138
136
} ,
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" ,
145
141
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"
150
143
} ,
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" ,
155
149
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"
157
151
} ,
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"
162
157
} ,
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
- ) ) ,
174
158
AbortReason :: InternalErrorGettingDestinationScript => {
175
- f . write_str ( "Internal error getting destination script" )
159
+ "Internal error getting destination script"
176
160
} ,
177
- }
161
+ } )
178
162
}
179
163
}
180
164
@@ -1765,15 +1749,15 @@ fn txouts_from_input_prev_txs(
1765
1749
) -> Result < Vec < & TxOut > , AbortReason > {
1766
1750
let mut prev_outputs: Vec < & TxOut > = Vec :: with_capacity ( inputs. len ( ) ) ;
1767
1751
// 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 ( ) {
1769
1753
let txid = tx. as_transaction ( ) . compute_txid ( ) ;
1770
1754
if txin. previous_output . txid != txid {
1771
- return Err ( AbortReason :: ProvidedInputsAndPrevtxsTxIdMismatch ( idx as u32 ) ) ;
1755
+ return Err ( AbortReason :: PrevTxOutInvalid ) ;
1772
1756
}
1773
1757
if let Some ( output) = tx. as_transaction ( ) . output . get ( txin. previous_output . vout as usize ) {
1774
1758
prev_outputs. push ( output) ;
1775
1759
} else {
1776
- return Err ( AbortReason :: ProvidedInputsAndPrevtxsVoutNotFound ( idx as u32 ) ) ;
1760
+ return Err ( AbortReason :: PrevTxOutInvalid ) ;
1777
1761
}
1778
1762
}
1779
1763
Ok ( prev_outputs)
0 commit comments