2018-02-23 15:57:31 -08:00
|
|
|
// nolint
|
|
|
|
package stake
|
|
|
|
|
|
|
|
import (
|
2018-03-16 12:47:17 -07:00
|
|
|
"fmt"
|
|
|
|
|
2018-02-23 15:57:31 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type CodeType = sdk.CodeType
|
|
|
|
|
|
|
|
const (
|
2018-04-17 19:16:21 -07:00
|
|
|
DefaultCodespace sdk.CodespaceType = 4
|
|
|
|
|
2018-02-23 15:57:31 -08:00
|
|
|
// Gaia errors reserve 200 ~ 299.
|
|
|
|
CodeInvalidValidator CodeType = 201
|
2018-05-09 21:01:58 -07:00
|
|
|
CodeInvalidBond CodeType = 202
|
|
|
|
CodeInvalidInput CodeType = 203
|
2018-05-25 15:13:29 -07:00
|
|
|
CodeValidatorJailed CodeType = 204
|
2018-02-23 15:57:31 -08:00
|
|
|
CodeUnauthorized CodeType = sdk.CodeUnauthorized
|
|
|
|
CodeInternal CodeType = sdk.CodeInternal
|
|
|
|
CodeUnknownRequest CodeType = sdk.CodeUnknownRequest
|
|
|
|
)
|
|
|
|
|
|
|
|
// NOTE: Don't stringer this, we'll put better messages in later.
|
|
|
|
func codeToDefaultMsg(code CodeType) string {
|
|
|
|
switch code {
|
|
|
|
case CodeInvalidValidator:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "invalid Validator"
|
2018-02-23 15:57:31 -08:00
|
|
|
case CodeInvalidBond:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "invalid Bond"
|
2018-02-23 15:57:31 -08:00
|
|
|
case CodeInvalidInput:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "invalid Input"
|
2018-02-23 15:57:31 -08:00
|
|
|
case CodeUnauthorized:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "unauthorized"
|
2018-02-23 15:57:31 -08:00
|
|
|
case CodeInternal:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "internal Error"
|
2018-02-23 15:57:31 -08:00
|
|
|
case CodeUnknownRequest:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "unknown request"
|
2018-02-23 15:57:31 -08:00
|
|
|
default:
|
|
|
|
return sdk.CodeToDefaultMsg(code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// Error constructors
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrNotEnoughBondShares(codespace sdk.CodespaceType, shares string) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidBond, fmt.Sprintf("not enough shares only have %v", shares))
|
2018-03-16 12:47:17 -07:00
|
|
|
}
|
2018-05-09 21:01:58 -07:00
|
|
|
func ErrValidatorEmpty(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "cannot bond to an empty validator")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadBondingDenom(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidBond, "invalid coin denomination")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadBondingAmount(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidBond, "amount must be > 0")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrNoBondingAcct(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "no bond account for this (address, validator) pair")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrCommissionNegative(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "commission must be positive")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrCommissionHuge(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "commission cannot be more than 100%")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadValidatorAddr(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "validator does not exist for that address")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadDelegatorAddr(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "delegator does not exist for that address")
|
2018-03-20 06:56:07 -07:00
|
|
|
}
|
2018-05-09 21:01:58 -07:00
|
|
|
func ErrValidatorExistsAddr(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "validator already exist, cannot re-create validator")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-05-09 21:01:58 -07:00
|
|
|
func ErrValidatorRevoked(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "validator for this address is currently revoked")
|
2018-04-03 19:26:39 -07:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrMissingSignature(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "missing signature")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBondNotNominated(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "cannot bond to non-nominated account")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-05-09 21:01:58 -07:00
|
|
|
func ErrNoValidatorForAddress(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "validator does not exist for that address")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrNoDelegatorForAddress(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "delegator does not contain validator bond")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrInsufficientFunds(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidInput, "insufficient bond shares")
|
2018-03-20 14:21:18 -07:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadShares(codespace sdk.CodespaceType) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidInput, "bad shares provided as input, must be MAX or decimal")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrBadRemoveValidator(codespace sdk.CodespaceType) sdk.Error {
|
2018-06-13 12:13:22 -07:00
|
|
|
return newError(codespace, CodeInvalidValidator, "error removing validator")
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// TODO group with code from x/bank/errors.go
|
|
|
|
|
|
|
|
func msgOrDefaultMsg(msg string, code CodeType) string {
|
|
|
|
if msg != "" {
|
|
|
|
return msg
|
|
|
|
}
|
|
|
|
return codeToDefaultMsg(code)
|
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func newError(codespace sdk.CodespaceType, code CodeType, msg string) sdk.Error {
|
2018-02-23 15:57:31 -08:00
|
|
|
msg = msgOrDefaultMsg(msg, code)
|
2018-04-17 19:16:21 -07:00
|
|
|
return sdk.NewError(codespace, code, msg)
|
2018-02-23 15:57:31 -08:00
|
|
|
}
|