-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
335 lines (256 loc) · 13.6 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// Copyright (c) 2014 Conformal Systems LLC.
// Copyright (c) 2015-2021 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package stake
// ErrorKind identifies a kind of error. It has full support for errors.Is and
// errors.As, so the caller can directly check against an error kind when
// determining the reason for an error.
type ErrorKind string
// These constants are used to identify a specific RuleError.
const (
// ErrSStxTooManyInputs indicates that a given SStx contains too many
// inputs.
ErrSStxTooManyInputs = ErrorKind("ErrSStxTooManyInputs")
// ErrSStxTooManyOutputs indicates that a given SStx contains too many
// outputs.
ErrSStxTooManyOutputs = ErrorKind("ErrSStxTooManyOutputs")
// ErrSStxNoOutputs indicates that a given SStx has no outputs.
ErrSStxNoOutputs = ErrorKind("ErrSStxNoOutputs")
// ErrSStxInvalidInput indicates that an invalid output has been used as
// an input for a SStx; only non-SStx tagged outputs may be used to
// purchase stake tickets.
// TODO: Add this into validate
// Ensure that all inputs are not tagged SStx outputs of some sort,
// along with checks to make sure they exist and are available.
ErrSStxInvalidInputs = ErrorKind("ErrSStxInvalidInputs")
// ErrSStxInvalidOutput indicates that the output for an SStx tx is
// invalid; in particular, either the output was not tagged SStx or the
// OP_RETURNs were missing or contained invalid addresses.
ErrSStxInvalidOutputs = ErrorKind("ErrSStxInvalidOutputs")
// ErrSStxInOutProportions indicates the number of inputs in an SStx
// was not equal to the number of output minus one.
ErrSStxInOutProportions = ErrorKind("ErrSStxInOutProportions")
// ErrSStxBadCommitAmount indicates that a ticket tried to commit 0 or
// a negative value as the commitment amount.
ErrSStxBadCommitAmount = ErrorKind("ErrSStxBadCommitAmount")
// ErrSStxBadChangeAmts indicates that the change amount for some SStx
// was invalid, for instance spending more than its inputs.
ErrSStxBadChangeAmts = ErrorKind("ErrSStxBadChangeAmts")
// ErrSStxVerifyCalcAmts indicates that passed calculated amounts failed
// to conform to the amounts found in the ticket.
ErrSStxVerifyCalcAmts = ErrorKind("ErrSStxVerifyCalcAmts")
// ErrSSGenWrongNumInputs indicates that a given SSGen tx contains an
// invalid number of inputs.
ErrSSGenWrongNumInputs = ErrorKind("ErrSSGenWrongNumInputs")
// ErrSSGenTooManyOutputs indicates that a given SSGen tx contains too
// many outputs.
ErrSSGenTooManyOutputs = ErrorKind("ErrSSGenTooManyOutputs")
// ErrSSGenNoOutputs indicates that a given SSGen has no outputs.
ErrSSGenNoOutputs = ErrorKind("ErrSSGenNoOutputs")
// ErrSSGenWrongIndex indicates that a given SSGen sstx input was not
// using the correct index.
ErrSSGenWrongIndex = ErrorKind("ErrSSGenWrongIndex")
// ErrSSGenWrongTxTree indicates that a given SSGen tx input was not found in
// the stake tx tree.
ErrSSGenWrongTxTree = ErrorKind("ErrSSGenWrongTxTree")
// ErrSSGenNoStakebase indicates that the SSGen tx did not contain a
// valid StakeBase in the zeroeth position of inputs.
ErrSSGenNoStakebase = ErrorKind("ErrSSGenNoStakebase")
// ErrSSGenNoReference indicates that there is no reference OP_RETURN
// included as the first output.
ErrSSGenNoReference = ErrorKind("ErrSSGenNoReference")
// ErrSSGenNoReference indicates that the OP_RETURN included as the
// first output was corrupted in some way.
ErrSSGenBadReference = ErrorKind("ErrSSGenBadReference")
// ErrSSGenNoVotePush indicates that there is no vote bits OP_RETURN
// included as the second output.
ErrSSGenNoVotePush = ErrorKind("ErrSSGenNoVotePush")
// ErrSSGenBadVotePush indicates that the OP_RETURN included as the
// second output was corrupted in some way.
ErrSSGenBadVotePush = ErrorKind("ErrSSGenBadVotePush")
// ErrSSGenInvalidDiscriminatorLength indicates that the discriminator
// length is too short.
ErrSSGenInvalidDiscriminatorLength = ErrorKind("ErrSSGenInvalidDiscriminatorLength")
// ErrSSGenInvalidNullScript indicates that the passed script is not a
// valid nullscript.
ErrSSGenInvalidNullScript = ErrorKind("ErrSSGenInvalidNullScript")
// ErrSSGenInvalidTVLength indicates that this is an invalid Treasury
// Vote length.
ErrSSGenInvalidTVLength = ErrorKind("ErrSSGenInvalidTVLength")
// ErrSSGenInvalidTreasuryVote indicates that this is an invalid
// treasury vote.
ErrSSGenInvalidTreasuryVote = ErrorKind("ErrSSGenInvalidTreasuryVote")
// ErrSSGenDuplicateTreasuryVote indicates that there is a duplicate
// treasury vote.
ErrSSGenDuplicateTreasuryVote = ErrorKind("ErrSSGenDuplicateTreasuryVote")
// ErrSSGenInvalidTxVersion indicates that this transaction has the
// wrong version.
ErrSSGenInvalidTxVersion = ErrorKind("ErrSSGenInvalidTxVersion")
// ErrSSGenUnknownDiscriminator indicates that the supplied
// discriminator is unsupported.
ErrSSGenUnknownDiscriminator = ErrorKind("ErrSSGenUnknownDiscriminator")
// ErrSSGenBadGenOuts indicates that something was wrong with the stake
// generation outputs that were present after the first two OP_RETURN
// pushes in an SSGen tx.
ErrSSGenBadGenOuts = ErrorKind("ErrSSGenBadGenOuts")
// ErrSSRtxWrongNumInputs indicates that a given SSRtx contains an
// invalid number of inputs.
ErrSSRtxWrongNumInputs = ErrorKind("ErrSSRtxWrongNumInputs")
// ErrSSRtxTooManyOutputs indicates that a given SSRtx contains too many
// outputs.
ErrSSRtxTooManyOutputs = ErrorKind("ErrSSRtxTooManyOutputs")
// ErrSSRtxNoOutputs indicates that a given SSRtx has no outputs.
ErrSSRtxNoOutputs = ErrorKind("ErrSSRtxNoOutputs")
// ErrSSRtxWrongTxTree indicates that a given SSRtx input was not found in
// the stake tx tree.
ErrSSRtxWrongTxTree = ErrorKind("ErrSSRtxWrongTxTree")
// ErrSSRtxBadOuts indicates that there was a non-SSRtx tagged output
// present in an SSRtx.
ErrSSRtxBadOuts = ErrorKind("ErrSSRtxBadOuts")
// ErrSSRtxInvalidFee indicates that a given SSRtx contains an invalid fee.
ErrSSRtxInvalidFee = ErrorKind("ErrSSRtxInvalidFee")
// ErrSSRtxInputHasSigScript indicates that a given SSRtx input has a
// non-empty signature script.
ErrSSRtxInputHasSigScript = ErrorKind("ErrSSRtxInputHasSigScript")
// ErrSSRtxInvalidTxVersion indicates that a given SSRtx has an invalid
// transaction version.
ErrSSRtxInvalidTxVersion = ErrorKind("ErrSSRtxInvalidTxVersion")
// ErrVerSStxAmts indicates there was an error verifying the calculated
// SStx out amounts and the actual SStx out amounts.
ErrVerSStxAmts = ErrorKind("ErrVerSStxAmts")
// ErrVerifyInput indicates that there was an error in verification
// function input.
ErrVerifyInput = ErrorKind("ErrVerifyInput")
// ErrVerifyOutType indicates that there was a non-equivalence in the
// output type.
ErrVerifyOutType = ErrorKind("ErrVerifyOutType")
// ErrVerifyTooMuchFees indicates that a transaction's output gave
// too much in fees after taking into accounts the limits imposed
// by the SStx output's version field.
ErrVerifyTooMuchFees = ErrorKind("ErrVerifyTooMuchFees")
// ErrVerifySpendTooMuch indicates that a transaction's output spent more
// than it was allowed to spend based on the calculated subsidy or return
// for a vote or revocation.
ErrVerifySpendTooMuch = ErrorKind("ErrVerifySpendTooMuch")
// ErrVerifyOutputAmt indicates that for a vote/revocation spend output,
// the rule was given that it must exactly match the calculated maximum,
// however the amount in the output did not (e.g. it gave fees).
ErrVerifyOutputAmt = ErrorKind("ErrVerifyOutputAmt")
// ErrVerifyOutPkhs indicates that the recipient of the P2PKH or P2SH
// script was different from that indicated in the SStx input.
ErrVerifyOutPkhs = ErrorKind("ErrVerifyOutPkhs")
// ErrDatabaseCorrupt indicates a database inconsistency.
ErrDatabaseCorrupt = ErrorKind("ErrDatabaseCorrupt")
// ErrMissingDatabaseTx indicates that a node disconnection failed to
// pass a database transaction when attempted to remove a very old
// node.
ErrMissingDatabaseTx = ErrorKind("ErrMissingDatabaseTx")
// ErrMemoryCorruption indicates that memory has somehow become corrupt,
// for example invalid block header serialization from an in memory
// struct.
ErrMemoryCorruption = ErrorKind("ErrMemoryCorruption")
// ErrFindTicketIdxs indicates a failure to find the selected ticket
// indexes from the block header.
ErrFindTicketIdxs = ErrorKind("ErrFindTicketIdxs")
// ErrMissingTicket indicates that a ticket was missing in one of the
// ticket treaps when it was attempted to be fetched.
ErrMissingTicket = ErrorKind("ErrMissingTicket")
// ErrDuplicateTicket indicates that a duplicate ticket was attempted
// to be inserted into a ticket treap or the database.
ErrDuplicateTicket = ErrorKind("ErrDuplicateTicket")
// ErrUnknownTicketSpent indicates that an unknown ticket was spent by
// the block.
ErrUnknownTicketSpent = ErrorKind("ErrUnknownTicketSpent")
// ErrTAddInvalidTxVersion indicates that this transaction has the
// wrong version.
ErrTAddInvalidTxVersion = ErrorKind("ErrTAddInvalidTxVersion")
// ErrTAddInvalidCount indicates that this transaction contains an
// invalid TADD script count.
ErrTAddInvalidCount = ErrorKind("ErrTAddInvalidCount")
// ErrTAddInvalidVersion indicates that this transaction has an invalid
// version in an output script.
ErrTAddInvalidVersion = ErrorKind("ErrTAddInvalidVersion")
// ErrTAddInvalidScriptLength indicates that this transaction has a zero
// length output script.
ErrTAddInvalidScriptLength = ErrorKind("ErrTAddInvalidScriptLength")
// ErrTAddInvalidLength indicates that output 0 is not exactly 1 byte.
ErrTAddInvalidLength = ErrorKind("ErrTAddInvalidLength")
// ErrTAddInvalidOpcode indicates that this transaction does not have a
// TADD opcode.
ErrTAddInvalidOpcode = ErrorKind("ErrTAddInvalidOpcode")
// ErrTAddInvalidChange indicates that this transaction contains an
// invalid change script.
ErrTAddInvalidChange = ErrorKind("ErrTAddInvalidChange")
// ErrTSpendInvalidTxVersion indicates that this transaction has
// the wrong version.
ErrTSpendInvalidTxVersion = ErrorKind("ErrTSpendInvalidTxVersion")
// ErrTSpendInvalidLength indicates that this transaction has an
// invalid number of inputs and/or outputs.
ErrTSpendInvalidLength = ErrorKind("ErrTSpendInvalidLength")
// ErrTSpendInvalidVersion indicates that this transaction has an
// invalid version in an output script.
ErrTSpendInvalidVersion = ErrorKind("ErrTSpendInvalidVersion")
// ErrTSpendInvalidScriptLength indicates that the TSPEND transaction
// has outputs that have a zero length script.
ErrTSpendInvalidScriptLength = ErrorKind("ErrTSpendInvalidScriptLength")
// ErrTSpendInvalidPubkey indicates that this transaction contains an
// invalid public key.
ErrTSpendInvalidPubkey = ErrorKind("ErrTSpendInvalidPubkey")
// ErrTSpendInvalidScript indicates that this transaction does not
// match the required TSPEND transaction signature.
ErrTSpendInvalidScript = ErrorKind("ErrTSpendInvalidScript")
// ErrTSpendInvalidTGen indicates that the TSPEND transaction has
// outputs that are not tagged with OP_TGEN.
ErrTSpendInvalidTGen = ErrorKind("ErrTSpendInvalidTGen")
// ErrTSpendInvalidTransaction indicates that a TSPEND transaction
// output 0 does not have an a valid null data script.
ErrTSpendInvalidTransaction = ErrorKind("ErrTSpendInvalidTransaction")
// ErrTSpendInvalidSpendScript indicates that this transaction contains
// an invalid P2SH or P2PKH script.
ErrTSpendInvalidSpendScript = ErrorKind("ErrTSpendInvalidSpendScript")
// ErrTreasuryBaseInvalidTxVersion indicates that this transaction has
// the wrong version.
ErrTreasuryBaseInvalidTxVersion = ErrorKind("ErrTreasuryBaseInvalidTxVersion")
// ErrTreasuryBaseInvalidCount indicates that this transaction contains
// an invalid treasury base script count.
ErrTreasuryBaseInvalidCount = ErrorKind("ErrTreasuryBaseInvalidCount")
// ErrTreasuryBaseInvalidLength indicates that this transaction contains
// an invalid treasury base input script length.
ErrTreasuryBaseInvalidLength = ErrorKind("ErrTreasuryBaseInvalidLength")
// ErrTreasuryBaseInvalidVersion indicates that this transaction has an
// invalid version in an output script.
ErrTreasuryBaseInvalidVersion = ErrorKind("ErrTreasuryBaseInvalidVersion")
// ErrTreasuryBaseInvalidOpcode0 indicates that this transaction does
// not have a TADD opcode in TxOut[0].
ErrTreasuryBaseInvalidOpcode0 = ErrorKind("ErrTreasuryBaseInvalidOpcode0")
// ErrTreasuryBaseInvalidOpcode1 indicates that this transaction does
// not have an OP_RETURN opcode in TxOut[1].
ErrTreasuryBaseInvalidOpcode1 = ErrorKind("ErrTreasuryBaseInvalidOpcode1")
// ErrTreasuryBaseInvalid indicates that this transaction contains
// invalid treasurybase TxIn constants.
ErrTreasuryBaseInvalid = ErrorKind("ErrTreasuryBaseInvalid")
)
// Error satisfies the error interface and prints human-readable errors.
func (e ErrorKind) Error() string {
return string(e)
}
// RuleError identifies a rule violation related to stake transactions. It has
// full support for errors.Is and errors.As, so the caller can ascertain the
// specific reason for the error by checking the underlying error.
type RuleError struct {
Description string
Err error
}
// Error satisfies the error interface and prints human-readable errors.
func (e RuleError) Error() string {
return e.Description
}
// Unwrap returns the underlying wrapped rule error.
func (e RuleError) Unwrap() error {
return e.Err
}
// stakeRuleError creates a RuleError given a set of arguments.
func stakeRuleError(kind ErrorKind, desc string) RuleError {
return RuleError{Err: kind, Description: desc}
}