cosmos-sdk/x/bank/errors.go

104 lines
2.2 KiB
Go
Raw Normal View History

2017-07-06 02:30:03 -07:00
//nolint
package bank
2017-07-03 05:50:33 -07:00
import (
2018-01-07 12:49:58 -08:00
"fmt"
"github.com/cosmos/cosmos-sdk/errors"
2017-07-03 05:50:33 -07:00
)
const (
2017-12-21 03:26:40 -08:00
// Coin errors reserve 100 ~ 199.
2018-01-03 17:20:21 -08:00
CodeInvalidInput uint32 = 101
CodeInvalidOutput uint32 = 102
CodeInvalidAddress uint32 = 103
CodeUnknownAddress uint32 = 104
CodeInsufficientCoins uint32 = 105
CodeInvalidCoins uint32 = 106
CodeUnknownRequest uint32 = errors.CodeUnknownRequest
)
2017-07-03 05:50:33 -07:00
2017-12-21 03:26:40 -08:00
// NOTE: Don't stringer this, we'll put better messages in later.
func codeToDefaultLog(code uint32) string {
switch code {
case CodeInvalidInput:
return "Invalid input coins"
case CodeInvalidOutput:
return "Invalid output coins"
case CodeInvalidAddress:
return "Invalid address"
case CodeUnknownAddress:
return "Unknown address"
2018-01-03 17:20:21 -08:00
case CodeInsufficientCoins:
return "Insufficient coins"
case CodeInvalidCoins:
return "Invalid coins"
2017-12-21 03:26:40 -08:00
case CodeUnknownRequest:
return "Unknown request"
default:
return errors.CodeToDefaultLog(code)
}
}
//----------------------------------------
// Error constructors
func ErrInvalidInput(log string) error {
return newError(CodeInvalidInput, log)
2017-07-03 05:50:33 -07:00
}
2017-12-21 03:26:40 -08:00
func ErrInvalidOutput(log string) error {
return newError(CodeInvalidOutput, log)
2017-07-03 05:50:33 -07:00
}
2017-12-21 03:26:40 -08:00
func ErrInvalidAddress(log string) error {
return newError(CodeInvalidAddress, log)
2017-07-03 05:50:33 -07:00
}
2017-12-21 03:26:40 -08:00
func ErrUnknownAddress(log string) error {
return newError(CodeUnknownAddress, log)
2017-07-03 05:50:33 -07:00
}
2018-01-03 17:20:21 -08:00
func ErrInsufficientCoins(log string) error {
return newError(CodeInsufficientCoins, log)
}
func ErrInvalidCoins(log string) error {
return newError(CodeInvalidCoins, log)
}
2017-12-21 03:26:40 -08:00
func ErrUnknownRequest(log string) error {
return newError(CodeUnknownRequest, log)
2017-07-21 14:28:44 -07:00
}
2018-01-07 12:49:58 -08:00
//----------------------------------------
// TODO: clean up
func ErrNoInputs() error {
return fmt.Errorf("No inputs")
}
func ErrNoOutputs() error {
return fmt.Errorf("No outputs")
}
func ErrInvalidSequence(seq int64) error {
return fmt.Errorf("Bad sequence %d", seq)
}
2017-12-21 03:26:40 -08:00
//----------------------------------------
// Misc
2018-01-03 17:20:21 -08:00
func logOrDefaultLog(log string, code uint32) string {
2017-12-21 03:26:40 -08:00
if log != "" {
return log
} else {
2018-01-03 17:20:21 -08:00
return codeToDefaultLog(code)
2017-12-21 03:26:40 -08:00
}
2017-07-03 05:50:33 -07:00
}
2017-12-21 03:26:40 -08:00
func newError(code uint32, log string) error {
log = logOrDefaultLog(log, code)
return errors.NewABCIError(code, log)
2017-07-03 05:50:33 -07:00
}