@@ -86,13 +86,31 @@ func (e DispatchOutcomeError) Error() string {
86
86
87
87
// A TransactionValidityError is possible errors while checking the validity of a transaction
88
88
type TransactionValidityError struct {
89
- msg string // description of error
89
+ msg error // description of error
90
90
}
91
91
92
92
func (e TransactionValidityError ) Error () string {
93
93
return fmt .Sprintf ("transaction validity error: %s" , e .msg )
94
94
}
95
95
96
+ var (
97
+ errUnexpectedTxCall = errors .New ("call of the transaction is not expected" )
98
+ errInvalidPayment = errors .New ("invalid payment" )
99
+ errInvalidTransaction = errors .New ("invalid transaction" )
100
+ errOutdatedTransaction = errors .New ("outdated transaction" )
101
+ errBadProof = errors .New ("bad proof" )
102
+ errAncientBirthBlock = errors .New ("ancient birth block" )
103
+ errExhaustsResources = errors .New ("exhausts resources" )
104
+ errMandatoryDispatchError = errors .New ("mandatory dispatch error" )
105
+ errInvalidMandatoryDispatch = errors .New ("invalid mandatory dispatch" )
106
+ errLookupFailed = errors .New ("lookup failed" )
107
+ errValidatorNotFound = errors .New ("validator not found" )
108
+ )
109
+
110
+ func newUnknownError (data scale.VaryingDataTypeValue ) error {
111
+ return fmt .Errorf ("unknown error: %d" , data )
112
+ }
113
+
96
114
// UnmarshalError occurs when unmarshalling fails
97
115
type UnmarshalError struct {
98
116
msg string
@@ -223,31 +241,31 @@ func determineErrType(vdt scale.VaryingDataType) error {
223
241
case Module :
224
242
return & DispatchOutcomeError {fmt .Sprintf ("custom module error: %s" , val .string ())}
225
243
case Call :
226
- return & TransactionValidityError {"call of the transaction is not expected" }
244
+ return & TransactionValidityError {errUnexpectedTxCall }
227
245
case Payment :
228
- return & TransactionValidityError {"invalid payment" }
246
+ return & TransactionValidityError {errInvalidPayment }
229
247
case Future :
230
- return & TransactionValidityError {"invalid transaction" }
248
+ return & TransactionValidityError {errInvalidTransaction }
231
249
case Stale :
232
- return & TransactionValidityError {"outdated transaction" }
250
+ return & TransactionValidityError {errOutdatedTransaction }
233
251
case BadProof :
234
- return & TransactionValidityError {"bad proof" }
252
+ return & TransactionValidityError {errBadProof }
235
253
case AncientBirthBlock :
236
- return & TransactionValidityError {"ancient birth block" }
254
+ return & TransactionValidityError {errAncientBirthBlock }
237
255
case ExhaustsResources :
238
- return & TransactionValidityError {"exhausts resources" }
256
+ return & TransactionValidityError {errExhaustsResources }
239
257
case InvalidCustom :
240
- return & TransactionValidityError {fmt . Sprintf ( "unknown error: %d" , val )}
258
+ return & TransactionValidityError {newUnknownError ( val )}
241
259
case BadMandatory :
242
- return & TransactionValidityError {"mandatory dispatch error" }
260
+ return & TransactionValidityError {errMandatoryDispatchError }
243
261
case MandatoryDispatch :
244
- return & TransactionValidityError {"invalid mandatory dispatch" }
262
+ return & TransactionValidityError {errInvalidMandatoryDispatch }
245
263
case ValidityCannotLookup :
246
- return & TransactionValidityError {"lookup failed" }
264
+ return & TransactionValidityError {errLookupFailed }
247
265
case NoUnsignedValidator :
248
- return & TransactionValidityError {"validator not found" }
266
+ return & TransactionValidityError {errValidatorNotFound }
249
267
case UnknownCustom :
250
- return & TransactionValidityError {fmt . Sprintf ( "unknown error: %d" , val )}
268
+ return & TransactionValidityError {newUnknownError ( val )}
251
269
}
252
270
253
271
return errInvalidResult
0 commit comments