2017-07-06 02:30:03 -07:00
|
|
|
//nolint
|
2018-01-12 11:49:53 -08:00
|
|
|
package bank
|
2017-07-03 05:50:33 -07:00
|
|
|
|
|
|
|
import (
|
2018-01-18 00:25:23 -08:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2017-07-03 05:50:33 -07:00
|
|
|
)
|
|
|
|
|
2018-04-18 21:49:24 -07:00
|
|
|
// Bank errors reserve 100 ~ 199.
|
2017-12-20 21:23:19 -08:00
|
|
|
const (
|
2018-04-17 19:16:21 -07:00
|
|
|
DefaultCodespace sdk.CodespaceType = 2
|
|
|
|
|
2018-03-17 19:42:54 -07:00
|
|
|
CodeInvalidInput sdk.CodeType = 101
|
|
|
|
CodeInvalidOutput sdk.CodeType = 102
|
2017-12-20 21:23:19 -08:00
|
|
|
)
|
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.
|
2018-03-17 19:42:54 -07:00
|
|
|
func codeToDefaultMsg(code sdk.CodeType) string {
|
2017-12-21 03:26:40 -08:00
|
|
|
switch code {
|
|
|
|
case CodeInvalidInput:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "invalid input coins"
|
2017-12-21 03:26:40 -08:00
|
|
|
case CodeInvalidOutput:
|
2018-06-13 12:13:22 -07:00
|
|
|
return "invalid output coins"
|
2017-12-21 03:26:40 -08:00
|
|
|
default:
|
2018-01-26 04:19:33 -08:00
|
|
|
return sdk.CodeToDefaultMsg(code)
|
2017-12-21 03:26:40 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
// Error constructors
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrInvalidInput(codespace sdk.CodespaceType, msg string) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidInput, msg)
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrNoInputs(codespace sdk.CodespaceType) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidInput, "")
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrInvalidOutput(codespace sdk.CodespaceType, msg string) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidOutput, msg)
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func ErrNoOutputs(codespace sdk.CodespaceType) sdk.Error {
|
|
|
|
return newError(codespace, CodeInvalidOutput, "")
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|
|
|
|
|
2017-12-21 03:26:40 -08:00
|
|
|
//----------------------------------------
|
|
|
|
|
2018-03-17 19:42:54 -07:00
|
|
|
func msgOrDefaultMsg(msg string, code sdk.CodeType) string {
|
2018-01-26 04:19:33 -08:00
|
|
|
if msg != "" {
|
|
|
|
return msg
|
2017-12-21 03:26:40 -08:00
|
|
|
}
|
2018-03-17 19:42:54 -07:00
|
|
|
return codeToDefaultMsg(code)
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|
|
|
|
|
2018-04-17 19:16:21 -07:00
|
|
|
func newError(codespace sdk.CodespaceType, code sdk.CodeType, msg string) sdk.Error {
|
2018-01-26 04:19:33 -08:00
|
|
|
msg = msgOrDefaultMsg(msg, code)
|
2018-04-17 19:16:21 -07:00
|
|
|
return sdk.NewError(codespace, code, msg)
|
2017-07-03 05:50:33 -07:00
|
|
|
}
|