2017-05-24 11:44:58 -07:00
|
|
|
package errors
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) 2017 Ethan Frey
|
|
|
|
**/
|
|
|
|
|
2017-06-29 08:03:43 -07:00
|
|
|
import (
|
2017-07-03 05:22:46 -07:00
|
|
|
rawerr "errors"
|
2017-06-29 08:03:43 -07:00
|
|
|
"fmt"
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
"github.com/pkg/errors"
|
2017-06-29 08:03:43 -07:00
|
|
|
abci "github.com/tendermint/abci/types"
|
2017-06-30 04:55:25 -07:00
|
|
|
"github.com/tendermint/basecoin"
|
2017-06-29 08:03:43 -07:00
|
|
|
)
|
2017-05-24 11:44:58 -07:00
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
var (
|
|
|
|
errDecoding = rawerr.New("Error decoding input")
|
|
|
|
errUnauthorized = rawerr.New("Unauthorized")
|
|
|
|
errInvalidAddress = rawerr.New("Invalid Address")
|
|
|
|
errInvalidCoins = rawerr.New("Invalid Coins")
|
|
|
|
errInvalidFormat = rawerr.New("Invalid Format")
|
|
|
|
errInvalidSequence = rawerr.New("Invalid Sequence")
|
|
|
|
errInvalidSignature = rawerr.New("Invalid Signature")
|
|
|
|
errInsufficientFees = rawerr.New("Insufficient Fees")
|
|
|
|
errInsufficientFunds = rawerr.New("Insufficient Funds")
|
|
|
|
errNoInputs = rawerr.New("No Input Coins")
|
|
|
|
errNoOutputs = rawerr.New("No Output Coins")
|
|
|
|
errTooLarge = rawerr.New("Input size too large")
|
|
|
|
errMissingSignature = rawerr.New("Signature missing")
|
|
|
|
errTooManySignatures = rawerr.New("Too many signatures")
|
|
|
|
errNoChain = rawerr.New("No chain id provided")
|
|
|
|
errWrongChain = rawerr.New("Wrong chain for tx")
|
|
|
|
errUnknownTxType = rawerr.New("Tx type unknown")
|
2017-05-24 11:44:58 -07:00
|
|
|
)
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func ErrUnknownTxType(tx basecoin.Tx) TMError {
|
|
|
|
msg := fmt.Sprintf("%T", tx.Unwrap())
|
|
|
|
w := errors.Wrap(errUnknownTxType, msg)
|
|
|
|
return WithCode(w, abci.CodeType_UnknownRequest)
|
2017-06-30 04:55:25 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func IsUnknownTxTypeErr(err error) bool {
|
|
|
|
return IsSameError(errUnknownTxType, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrInternal(msg string) TMError {
|
2017-06-29 07:09:15 -07:00
|
|
|
return New(msg, abci.CodeType_InternalError)
|
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
// IsInternalErr matches any error that is not classified
|
|
|
|
func IsInternalErr(err error) bool {
|
|
|
|
return HasErrorCode(err, abci.CodeType_InternalError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrDecoding() TMError {
|
|
|
|
return WithCode(errDecoding, abci.CodeType_EncodingError)
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsDecodingErr(err error) bool {
|
|
|
|
return IsSameError(errDecoding, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrUnauthorized() TMError {
|
|
|
|
return WithCode(errUnauthorized, abci.CodeType_Unauthorized)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsUnauthorizedErr is generic helper for any unauthorized errors,
|
|
|
|
// also specific sub-types
|
|
|
|
func IsUnauthorizedErr(err error) bool {
|
|
|
|
return HasErrorCode(err, abci.CodeType_Unauthorized)
|
2017-05-24 11:44:58 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func ErrMissingSignature() TMError {
|
|
|
|
return WithCode(errMissingSignature, abci.CodeType_Unauthorized)
|
2017-05-24 11:44:58 -07:00
|
|
|
}
|
2017-05-29 05:15:42 -07:00
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func IsMissingSignatureErr(err error) bool {
|
|
|
|
return IsSameError(errMissingSignature, err)
|
2017-06-01 07:54:16 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func ErrTooManySignatures() TMError {
|
|
|
|
return WithCode(errTooManySignatures, abci.CodeType_Unauthorized)
|
2017-06-01 07:54:16 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func IsTooManySignaturesErr(err error) bool {
|
|
|
|
return IsSameError(errTooManySignatures, err)
|
2017-06-01 07:54:16 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func ErrInvalidSignature() TMError {
|
|
|
|
return WithCode(errInvalidSignature, abci.CodeType_Unauthorized)
|
2017-06-29 08:03:43 -07:00
|
|
|
}
|
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func IsInvalidSignatureErr(err error) bool {
|
|
|
|
return IsSameError(errInvalidSignature, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrNoChain() TMError {
|
|
|
|
return WithCode(errNoChain, abci.CodeType_Unauthorized)
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsNoChainErr(err error) bool {
|
|
|
|
return IsSameError(errNoChain, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrWrongChain(chain string) TMError {
|
|
|
|
msg := errors.Wrap(errWrongChain, chain)
|
|
|
|
return WithCode(msg, abci.CodeType_Unauthorized)
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsWrongChainErr(err error) bool {
|
|
|
|
return IsSameError(errWrongChain, err)
|
2017-06-29 08:03:43 -07:00
|
|
|
}
|
|
|
|
|
2017-05-29 05:15:42 -07:00
|
|
|
func InvalidAddress() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInvalidAddress, abci.CodeType_BaseInvalidInput)
|
2017-05-29 05:15:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func InvalidCoins() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInvalidCoins, abci.CodeType_BaseInvalidInput)
|
2017-05-29 05:15:42 -07:00
|
|
|
}
|
|
|
|
|
2017-06-01 11:26:43 -07:00
|
|
|
func InvalidFormat() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInvalidFormat, abci.CodeType_BaseInvalidInput)
|
2017-06-01 11:26:43 -07:00
|
|
|
}
|
|
|
|
|
2017-05-29 05:15:42 -07:00
|
|
|
func InvalidSequence() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInvalidSequence, abci.CodeType_BaseInvalidInput)
|
2017-05-29 05:15:42 -07:00
|
|
|
}
|
|
|
|
|
2017-06-01 11:26:43 -07:00
|
|
|
func InsufficientFees() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInsufficientFees, abci.CodeType_BaseInvalidInput)
|
2017-06-01 11:26:43 -07:00
|
|
|
}
|
|
|
|
|
2017-06-30 11:55:23 -07:00
|
|
|
func InsufficientFunds() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errInsufficientFunds, abci.CodeType_BaseInvalidInput)
|
2017-06-30 11:55:23 -07:00
|
|
|
}
|
|
|
|
|
2017-05-29 05:15:42 -07:00
|
|
|
func NoInputs() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errNoInputs, abci.CodeType_BaseInvalidInput)
|
2017-05-29 05:15:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NoOutputs() TMError {
|
2017-07-03 05:22:46 -07:00
|
|
|
return WithCode(errNoOutputs, abci.CodeType_BaseInvalidOutput)
|
|
|
|
}
|
|
|
|
|
|
|
|
func ErrTooLarge() TMError {
|
|
|
|
return WithCode(errTooLarge, abci.CodeType_EncodingError)
|
2017-05-29 05:15:42 -07:00
|
|
|
}
|
2017-06-01 05:59:19 -07:00
|
|
|
|
2017-07-03 05:22:46 -07:00
|
|
|
func IsTooLargeErr(err error) bool {
|
|
|
|
return IsSameError(errTooLarge, err)
|
2017-06-01 05:59:19 -07:00
|
|
|
}
|