working sequence number with errors
This commit is contained in:
committed by
Ethan Frey
parent
50e4d31149
commit
16b039534d
+38
-12
@@ -12,12 +12,16 @@ import (
|
||||
|
||||
var (
|
||||
errDecoding = fmt.Errorf("Error decoding input")
|
||||
errNoAccount = fmt.Errorf("No such account")
|
||||
errUnauthorized = fmt.Errorf("Unauthorized")
|
||||
errInvalidSignature = fmt.Errorf("Invalid Signature")
|
||||
errTooLarge = fmt.Errorf("Input size too large")
|
||||
errMissingSignature = fmt.Errorf("Signature missing")
|
||||
errTooManySignatures = fmt.Errorf("Too many signatures")
|
||||
errNoChain = fmt.Errorf("No chain id provided")
|
||||
errNoNonce = fmt.Errorf("Tx doesn't contain nonce")
|
||||
errNotMember = fmt.Errorf("nonce contains non-permissioned member")
|
||||
errBadNonce = fmt.Errorf("Bad nonce seqence")
|
||||
errWrongChain = fmt.Errorf("Wrong chain for tx")
|
||||
errUnknownTxType = fmt.Errorf("Tx type unknown")
|
||||
errInvalidFormat = fmt.Errorf("Invalid format")
|
||||
@@ -26,6 +30,14 @@ var (
|
||||
errUnknownKey = fmt.Errorf("Unknown key")
|
||||
)
|
||||
|
||||
var (
|
||||
internalErr = abci.CodeType_InternalError
|
||||
encodingErr = abci.CodeType_EncodingError
|
||||
unauthorized = abci.CodeType_Unauthorized
|
||||
unknownRequest = abci.CodeType_UnknownRequest
|
||||
unknownAddress = abci.CodeType_BaseUnknownAddress
|
||||
)
|
||||
|
||||
// some crazy reflection to unwrap any generated struct.
|
||||
func unwrap(i interface{}) interface{} {
|
||||
v := reflect.ValueOf(i)
|
||||
@@ -71,76 +83,90 @@ func IsUnknownKeyErr(err error) bool {
|
||||
}
|
||||
|
||||
func ErrInternal(msg string) TMError {
|
||||
return New(msg, abci.CodeType_InternalError)
|
||||
return New(msg, internalErr)
|
||||
}
|
||||
|
||||
// IsInternalErr matches any error that is not classified
|
||||
func IsInternalErr(err error) bool {
|
||||
return HasErrorCode(err, abci.CodeType_InternalError)
|
||||
return HasErrorCode(err, internalErr)
|
||||
}
|
||||
|
||||
func ErrDecoding() TMError {
|
||||
return WithCode(errDecoding, abci.CodeType_EncodingError)
|
||||
return WithCode(errDecoding, encodingErr)
|
||||
}
|
||||
func IsDecodingErr(err error) bool {
|
||||
return IsSameError(errDecoding, err)
|
||||
}
|
||||
|
||||
func ErrUnauthorized() TMError {
|
||||
return WithCode(errUnauthorized, abci.CodeType_Unauthorized)
|
||||
return WithCode(errUnauthorized, unauthorized)
|
||||
}
|
||||
|
||||
// IsUnauthorizedErr is generic helper for any unauthorized errors,
|
||||
// also specific sub-types
|
||||
func IsUnauthorizedErr(err error) bool {
|
||||
return HasErrorCode(err, abci.CodeType_Unauthorized)
|
||||
return HasErrorCode(err, unauthorized)
|
||||
}
|
||||
|
||||
func ErrMissingSignature() TMError {
|
||||
return WithCode(errMissingSignature, abci.CodeType_Unauthorized)
|
||||
return WithCode(errMissingSignature, unauthorized)
|
||||
}
|
||||
func IsMissingSignatureErr(err error) bool {
|
||||
return IsSameError(errMissingSignature, err)
|
||||
}
|
||||
|
||||
func ErrTooManySignatures() TMError {
|
||||
return WithCode(errTooManySignatures, abci.CodeType_Unauthorized)
|
||||
return WithCode(errTooManySignatures, unauthorized)
|
||||
}
|
||||
func IsTooManySignaturesErr(err error) bool {
|
||||
return IsSameError(errTooManySignatures, err)
|
||||
}
|
||||
|
||||
func ErrInvalidSignature() TMError {
|
||||
return WithCode(errInvalidSignature, abci.CodeType_Unauthorized)
|
||||
return WithCode(errInvalidSignature, unauthorized)
|
||||
}
|
||||
func IsInvalidSignatureErr(err error) bool {
|
||||
return IsSameError(errInvalidSignature, err)
|
||||
}
|
||||
|
||||
func ErrNoChain() TMError {
|
||||
return WithCode(errNoChain, abci.CodeType_Unauthorized)
|
||||
return WithCode(errNoChain, unauthorized)
|
||||
}
|
||||
func IsNoChainErr(err error) bool {
|
||||
return IsSameError(errNoChain, err)
|
||||
}
|
||||
|
||||
func ErrNoNonce() TMError {
|
||||
return WithCode(errNoNonce, unauthorized)
|
||||
}
|
||||
func ErrBadNonce() TMError {
|
||||
return WithCode(errBadNonce, unauthorized)
|
||||
}
|
||||
func ErrNotMember() TMError {
|
||||
return WithCode(errBadNonce, unauthorized)
|
||||
}
|
||||
|
||||
func ErrNoAccount() TMError {
|
||||
return WithCode(errNoAccount, unknownAddress)
|
||||
}
|
||||
|
||||
func ErrWrongChain(chain string) TMError {
|
||||
msg := errors.Wrap(errWrongChain, chain)
|
||||
return WithCode(msg, abci.CodeType_Unauthorized)
|
||||
return WithCode(msg, unauthorized)
|
||||
}
|
||||
func IsWrongChainErr(err error) bool {
|
||||
return IsSameError(errWrongChain, err)
|
||||
}
|
||||
|
||||
func ErrTooLarge() TMError {
|
||||
return WithCode(errTooLarge, abci.CodeType_EncodingError)
|
||||
return WithCode(errTooLarge, encodingErr)
|
||||
}
|
||||
func IsTooLargeErr(err error) bool {
|
||||
return IsSameError(errTooLarge, err)
|
||||
}
|
||||
|
||||
func ErrExpired() TMError {
|
||||
return WithCode(errExpired, abci.CodeType_Unauthorized)
|
||||
return WithCode(errExpired, unauthorized)
|
||||
}
|
||||
func IsExpiredErr(err error) bool {
|
||||
return IsSameError(errExpired, err)
|
||||
|
||||
Reference in New Issue
Block a user