errors cleanup
This commit is contained in:
parent
0a9460dc93
commit
8617841296
2
Makefile
2
Makefile
|
@ -29,7 +29,7 @@ test_unit:
|
||||||
test_cli: tests/cli/shunit2
|
test_cli: tests/cli/shunit2
|
||||||
# sudo apt-get install jq
|
# sudo apt-get install jq
|
||||||
./tests/cli/keys.sh
|
./tests/cli/keys.sh
|
||||||
#./tests/cli/rpc.sh
|
./tests/cli/rpc.sh
|
||||||
./tests/cli/init.sh
|
./tests/cli/init.sh
|
||||||
./tests/cli/basictx.sh
|
./tests/cli/basictx.sh
|
||||||
./tests/cli/counter.sh
|
./tests/cli/counter.sh
|
||||||
|
|
|
@ -5,27 +5,17 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errDecoding = fmt.Errorf("Error decoding input")
|
errDecoding = fmt.Errorf("Error decoding input")
|
||||||
errUnauthorized = fmt.Errorf("Unauthorized")
|
errUnauthorized = fmt.Errorf("Unauthorized")
|
||||||
errInvalidSignature = fmt.Errorf("Invalid Signature")
|
|
||||||
errTooLarge = fmt.Errorf("Input size too large")
|
errTooLarge = fmt.Errorf("Input size too large")
|
||||||
errNoSigners = fmt.Errorf("There are no signers")
|
|
||||||
errMissingSignature = fmt.Errorf("Signature missing")
|
errMissingSignature = fmt.Errorf("Signature missing")
|
||||||
errTooManySignatures = fmt.Errorf("Too many signatures")
|
|
||||||
errNoChain = fmt.Errorf("No chain id provided")
|
|
||||||
errTxEmpty = fmt.Errorf("The provided Tx is empty")
|
|
||||||
errWrongChain = fmt.Errorf("Wrong chain for tx")
|
|
||||||
errUnknownTxType = fmt.Errorf("Tx type unknown")
|
errUnknownTxType = fmt.Errorf("Tx type unknown")
|
||||||
errInvalidFormat = fmt.Errorf("Invalid format")
|
errInvalidFormat = fmt.Errorf("Invalid format")
|
||||||
errUnknownModule = fmt.Errorf("Unknown module")
|
errUnknownModule = fmt.Errorf("Unknown module")
|
||||||
errExpired = fmt.Errorf("Tx expired")
|
|
||||||
errUnknownKey = fmt.Errorf("Unknown key")
|
|
||||||
|
|
||||||
internalErr = abci.CodeType_InternalError
|
internalErr = abci.CodeType_InternalError
|
||||||
encodingErr = abci.CodeType_EncodingError
|
encodingErr = abci.CodeType_EncodingError
|
||||||
|
@ -70,14 +60,6 @@ func IsUnknownModuleErr(err error) bool {
|
||||||
return IsSameError(errUnknownModule, err)
|
return IsSameError(errUnknownModule, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrUnknownKey(mod string) TMError {
|
|
||||||
w := errors.Wrap(errUnknownKey, mod)
|
|
||||||
return WithCode(w, abci.CodeType_UnknownRequest)
|
|
||||||
}
|
|
||||||
func IsUnknownKeyErr(err error) bool {
|
|
||||||
return IsSameError(errUnknownKey, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrInternal(msg string) TMError {
|
func ErrInternal(msg string) TMError {
|
||||||
return New(msg, internalErr)
|
return New(msg, internalErr)
|
||||||
}
|
}
|
||||||
|
@ -104,10 +86,6 @@ func IsUnauthorizedErr(err error) bool {
|
||||||
return HasErrorCode(err, unauthorized)
|
return HasErrorCode(err, unauthorized)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNoSigners() TMError {
|
|
||||||
return WithCode(errNoSigners, unauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrMissingSignature() TMError {
|
func ErrMissingSignature() TMError {
|
||||||
return WithCode(errMissingSignature, unauthorized)
|
return WithCode(errMissingSignature, unauthorized)
|
||||||
}
|
}
|
||||||
|
@ -115,49 +93,9 @@ func IsMissingSignatureErr(err error) bool {
|
||||||
return IsSameError(errMissingSignature, err)
|
return IsSameError(errMissingSignature, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrTooManySignatures() TMError {
|
|
||||||
return WithCode(errTooManySignatures, unauthorized)
|
|
||||||
}
|
|
||||||
func IsTooManySignaturesErr(err error) bool {
|
|
||||||
return IsSameError(errTooManySignatures, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrInvalidSignature() TMError {
|
|
||||||
return WithCode(errInvalidSignature, unauthorized)
|
|
||||||
}
|
|
||||||
func IsInvalidSignatureErr(err error) bool {
|
|
||||||
return IsSameError(errInvalidSignature, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrNoChain() TMError {
|
|
||||||
return WithCode(errNoChain, unauthorized)
|
|
||||||
}
|
|
||||||
func IsNoChainErr(err error) bool {
|
|
||||||
return IsSameError(errNoChain, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrTxEmpty() TMError {
|
|
||||||
return WithCode(errTxEmpty, unauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrWrongChain(chain string) TMError {
|
|
||||||
msg := errors.Wrap(errWrongChain, chain)
|
|
||||||
return WithCode(msg, unauthorized)
|
|
||||||
}
|
|
||||||
func IsWrongChainErr(err error) bool {
|
|
||||||
return IsSameError(errWrongChain, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrTooLarge() TMError {
|
func ErrTooLarge() TMError {
|
||||||
return WithCode(errTooLarge, encodingErr)
|
return WithCode(errTooLarge, encodingErr)
|
||||||
}
|
}
|
||||||
func IsTooLargeErr(err error) bool {
|
func IsTooLargeErr(err error) bool {
|
||||||
return IsSameError(errTooLarge, err)
|
return IsSameError(errTooLarge, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrExpired() TMError {
|
|
||||||
return WithCode(errExpired, unauthorized)
|
|
||||||
}
|
|
||||||
func IsExpiredErr(err error) bool {
|
|
||||||
return IsSameError(errExpired, err)
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ func TestErrorMatches(t *testing.T) {
|
||||||
{errUnauthorized, ErrUnauthorized(), true},
|
{errUnauthorized, ErrUnauthorized(), true},
|
||||||
{errMissingSignature, ErrUnauthorized(), false},
|
{errMissingSignature, ErrUnauthorized(), false},
|
||||||
{errMissingSignature, ErrMissingSignature(), true},
|
{errMissingSignature, ErrMissingSignature(), true},
|
||||||
{errWrongChain, ErrWrongChain("hakz"), true},
|
|
||||||
{errUnknownTxType, ErrUnknownTxType(holder{}), true},
|
{errUnknownTxType, ErrUnknownTxType(holder{}), true},
|
||||||
{errUnknownTxType, ErrUnknownTxType("some text here..."), true},
|
{errUnknownTxType, ErrUnknownTxType("some text here..."), true},
|
||||||
{errUnknownTxType, ErrUnknownTxType(demoTx{5}.Wrap()), true},
|
{errUnknownTxType, ErrUnknownTxType(demoTx{5}.Wrap()), true},
|
||||||
|
@ -66,13 +65,6 @@ func TestChecks(t *testing.T) {
|
||||||
{ErrDecoding(), IsDecodingErr, true},
|
{ErrDecoding(), IsDecodingErr, true},
|
||||||
{ErrUnauthorized(), IsDecodingErr, false},
|
{ErrUnauthorized(), IsDecodingErr, false},
|
||||||
{ErrUnauthorized(), IsUnauthorizedErr, true},
|
{ErrUnauthorized(), IsUnauthorizedErr, true},
|
||||||
{ErrInvalidSignature(), IsInvalidSignatureErr, true},
|
|
||||||
// unauthorized includes InvalidSignature, but not visa versa
|
|
||||||
{ErrInvalidSignature(), IsUnauthorizedErr, true},
|
|
||||||
{ErrUnauthorized(), IsInvalidSignatureErr, false},
|
|
||||||
// make sure WrongChain works properly
|
|
||||||
{ErrWrongChain("fooz"), IsUnauthorizedErr, true},
|
|
||||||
{ErrWrongChain("barz"), IsWrongChainErr, true},
|
|
||||||
// make sure lots of things match InternalErr, but not everything
|
// make sure lots of things match InternalErr, but not everything
|
||||||
{ErrInternal("bad db connection"), IsInternalErr, true},
|
{ErrInternal("bad db connection"), IsInternalErr, true},
|
||||||
{Wrap(errors.New("wrapped")), IsInternalErr, true},
|
{Wrap(errors.New("wrapped")), IsInternalErr, true},
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
//nolint
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
|
"github.com/tendermint/basecoin/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errInvalidSignature = fmt.Errorf("Invalid Signature") //move auth
|
||||||
|
errTooManySignatures = fmt.Errorf("Too many signatures") //move auth
|
||||||
|
|
||||||
|
unauthorized = abci.CodeType_Unauthorized
|
||||||
|
)
|
||||||
|
|
||||||
|
func ErrTooManySignatures() errors.TMError {
|
||||||
|
return errors.WithCode(errTooManySignatures, unauthorized)
|
||||||
|
}
|
||||||
|
func IsTooManySignaturesErr(err error) bool {
|
||||||
|
return errors.IsSameError(errTooManySignatures, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrInvalidSignature() errors.TMError {
|
||||||
|
return errors.WithCode(errInvalidSignature, unauthorized)
|
||||||
|
}
|
||||||
|
func IsInvalidSignatureErr(err error) bool {
|
||||||
|
return errors.IsSameError(errInvalidSignature, err)
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package auth
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/tendermint/basecoin/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChecks(t *testing.T) {
|
||||||
|
// TODO: make sure the Is and Err methods match
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
err error
|
||||||
|
check func(error) bool
|
||||||
|
match bool
|
||||||
|
}{
|
||||||
|
// unauthorized includes InvalidSignature, but not visa versa
|
||||||
|
{ErrInvalidSignature(), IsInvalidSignatureErr, true},
|
||||||
|
{ErrInvalidSignature(), errors.IsUnauthorizedErr, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tc := range cases {
|
||||||
|
match := tc.check(tc.err)
|
||||||
|
assert.Equal(tc.match, match, "%d", i)
|
||||||
|
}
|
||||||
|
}
|
|
@ -106,7 +106,7 @@ func (s *OneSig) Sign(pubkey crypto.PubKey, sig crypto.Signature) error {
|
||||||
return errors.ErrMissingSignature()
|
return errors.ErrMissingSignature()
|
||||||
}
|
}
|
||||||
if !s.Empty() {
|
if !s.Empty() {
|
||||||
return errors.ErrTooManySignatures()
|
return ErrTooManySignatures()
|
||||||
}
|
}
|
||||||
// set the value once we are happy
|
// set the value once we are happy
|
||||||
s.Signed = signed
|
s.Signed = signed
|
||||||
|
@ -121,7 +121,7 @@ func (s *OneSig) Signers() ([]crypto.PubKey, error) {
|
||||||
return nil, errors.ErrMissingSignature()
|
return nil, errors.ErrMissingSignature()
|
||||||
}
|
}
|
||||||
if !s.Pubkey.VerifyBytes(s.SignBytes(), s.Sig) {
|
if !s.Pubkey.VerifyBytes(s.SignBytes(), s.Sig) {
|
||||||
return nil, errors.ErrInvalidSignature()
|
return nil, ErrInvalidSignature()
|
||||||
}
|
}
|
||||||
return []crypto.PubKey{s.Pubkey}, nil
|
return []crypto.PubKey{s.Pubkey}, nil
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ func (s *MultiSig) Signers() ([]crypto.PubKey, error) {
|
||||||
for i := range s.Sigs {
|
for i := range s.Sigs {
|
||||||
ms := s.Sigs[i]
|
ms := s.Sigs[i]
|
||||||
if !ms.Pubkey.VerifyBytes(data, ms.Sig) {
|
if !ms.Pubkey.VerifyBytes(data, ms.Sig) {
|
||||||
return nil, errors.ErrInvalidSignature()
|
return nil, ErrInvalidSignature()
|
||||||
}
|
}
|
||||||
keys[i] = ms.Pubkey
|
keys[i] = ms.Pubkey
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package base
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/tendermint/basecoin"
|
"github.com/tendermint/basecoin"
|
||||||
"github.com/tendermint/basecoin/errors"
|
|
||||||
"github.com/tendermint/basecoin/stack"
|
"github.com/tendermint/basecoin/stack"
|
||||||
"github.com/tendermint/basecoin/state"
|
"github.com/tendermint/basecoin/state"
|
||||||
)
|
)
|
||||||
|
@ -48,7 +47,7 @@ func (c Chain) checkChainTx(chainID string, height uint64, tx basecoin.Tx) (base
|
||||||
// make sure it is a chaintx
|
// make sure it is a chaintx
|
||||||
ctx, ok := tx.Unwrap().(ChainTx)
|
ctx, ok := tx.Unwrap().(ChainTx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return tx, errors.ErrNoChain()
|
return tx, ErrNoChain()
|
||||||
}
|
}
|
||||||
|
|
||||||
// basic validation
|
// basic validation
|
||||||
|
@ -59,10 +58,10 @@ func (c Chain) checkChainTx(chainID string, height uint64, tx basecoin.Tx) (base
|
||||||
|
|
||||||
// compare against state
|
// compare against state
|
||||||
if ctx.ChainID != chainID {
|
if ctx.ChainID != chainID {
|
||||||
return tx, errors.ErrWrongChain(ctx.ChainID)
|
return tx, ErrWrongChain(ctx.ChainID)
|
||||||
}
|
}
|
||||||
if ctx.ExpiresAt != 0 && ctx.ExpiresAt <= height {
|
if ctx.ExpiresAt != 0 && ctx.ExpiresAt <= height {
|
||||||
return tx, errors.ErrExpired()
|
return tx, ErrExpired()
|
||||||
}
|
}
|
||||||
return ctx.Tx, nil
|
return ctx.Tx, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
//nolint
|
||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
pkgerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
|
"github.com/tendermint/basecoin/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errNoChain = fmt.Errorf("No chain id provided") //move base
|
||||||
|
errWrongChain = fmt.Errorf("Wrong chain for tx") //move base
|
||||||
|
errExpired = fmt.Errorf("Tx expired") //move base
|
||||||
|
|
||||||
|
unauthorized = abci.CodeType_Unauthorized
|
||||||
|
)
|
||||||
|
|
||||||
|
func ErrNoChain() errors.TMError {
|
||||||
|
return errors.WithCode(errNoChain, unauthorized)
|
||||||
|
}
|
||||||
|
func IsNoChainErr(err error) bool {
|
||||||
|
return errors.IsSameError(errNoChain, err)
|
||||||
|
}
|
||||||
|
func ErrWrongChain(chain string) errors.TMError {
|
||||||
|
msg := pkgerrors.Wrap(errWrongChain, chain)
|
||||||
|
return errors.WithCode(msg, unauthorized)
|
||||||
|
}
|
||||||
|
func IsWrongChainErr(err error) bool {
|
||||||
|
return errors.IsSameError(errWrongChain, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrExpired() errors.TMError {
|
||||||
|
return errors.WithCode(errExpired, unauthorized)
|
||||||
|
}
|
||||||
|
func IsExpiredErr(err error) bool {
|
||||||
|
return errors.IsSameError(errExpired, err)
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package base
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/tendermint/basecoin/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestErrorMatches(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
pattern, err error
|
||||||
|
match bool
|
||||||
|
}{
|
||||||
|
{errWrongChain, ErrWrongChain("hakz"), true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tc := range cases {
|
||||||
|
same := errors.IsSameError(tc.pattern, tc.err)
|
||||||
|
assert.Equal(tc.match, same, "%d: %#v / %#v", i, tc.pattern, tc.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChecks(t *testing.T) {
|
||||||
|
// TODO: make sure the Is and Err methods match
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
cases := []struct {
|
||||||
|
err error
|
||||||
|
check func(error) bool
|
||||||
|
match bool
|
||||||
|
}{
|
||||||
|
// make sure WrongChain works properly
|
||||||
|
{ErrWrongChain("fooz"), errors.IsUnauthorizedErr, true},
|
||||||
|
{ErrWrongChain("barz"), IsWrongChainErr, true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tc := range cases {
|
||||||
|
match := tc.check(tc.err)
|
||||||
|
assert.Equal(tc.match, match, "%d", i)
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,10 +86,10 @@ func (c ChainTx) Wrap() basecoin.Tx {
|
||||||
}
|
}
|
||||||
func (c ChainTx) ValidateBasic() error {
|
func (c ChainTx) ValidateBasic() error {
|
||||||
if c.ChainID == "" {
|
if c.ChainID == "" {
|
||||||
return errors.ErrNoChain()
|
return ErrNoChain()
|
||||||
}
|
}
|
||||||
if !chainPattern.MatchString(c.ChainID) {
|
if !chainPattern.MatchString(c.ChainID) {
|
||||||
return errors.ErrWrongChain(c.ChainID)
|
return ErrWrongChain(c.ChainID)
|
||||||
}
|
}
|
||||||
if c.Tx.Empty() {
|
if c.Tx.Empty() {
|
||||||
return errors.ErrUnknownTxType(c.Tx)
|
return errors.ErrUnknownTxType(c.Tx)
|
||||||
|
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
lc "github.com/tendermint/light-client"
|
|
||||||
lcmd "github.com/tendermint/basecoin/client/commands"
|
lcmd "github.com/tendermint/basecoin/client/commands"
|
||||||
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
|
proofcmd "github.com/tendermint/basecoin/client/commands/proofs"
|
||||||
|
lc "github.com/tendermint/light-client"
|
||||||
|
|
||||||
"github.com/tendermint/basecoin/modules/auth"
|
"github.com/tendermint/basecoin/modules/auth"
|
||||||
"github.com/tendermint/basecoin/modules/coin"
|
"github.com/tendermint/basecoin/modules/coin"
|
||||||
|
@ -17,10 +17,10 @@ import (
|
||||||
var AccountQueryCmd = &cobra.Command{
|
var AccountQueryCmd = &cobra.Command{
|
||||||
Use: "account [address]",
|
Use: "account [address]",
|
||||||
Short: "Get details of an account, with proof",
|
Short: "Get details of an account, with proof",
|
||||||
RunE: lcmd.RequireInit(doAccountQuery),
|
RunE: lcmd.RequireInit(accountQueryCmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
func doAccountQuery(cmd *cobra.Command, args []string) error {
|
func accountQueryCmd(cmd *cobra.Command, args []string) error {
|
||||||
addr, err := proofcmd.ParseHexKey(args, "address")
|
addr, err := proofcmd.ParseHexKey(args, "address")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
var SendTxCmd = &cobra.Command{
|
var SendTxCmd = &cobra.Command{
|
||||||
Use: "send",
|
Use: "send",
|
||||||
Short: "send tokens from one account to another",
|
Short: "send tokens from one account to another",
|
||||||
RunE: commands.RequireInit(doSendTx),
|
RunE: commands.RequireInit(sendTxCmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
//nolint
|
||||||
|
@ -31,8 +31,8 @@ func init() {
|
||||||
flags.String(FlagFrom, "", "Address sending coins, if not first signer")
|
flags.String(FlagFrom, "", "Address sending coins, if not first signer")
|
||||||
}
|
}
|
||||||
|
|
||||||
// doSendTx is an example of how to make a tx
|
// sendTxCmd is an example of how to make a tx
|
||||||
func doSendTx(cmd *cobra.Command, args []string) error {
|
func sendTxCmd(cmd *cobra.Command, args []string) error {
|
||||||
// load data from json or flags
|
// load data from json or flags
|
||||||
// var tx basecoin.Tx
|
// var tx basecoin.Tx
|
||||||
// found, err := txcmd.LoadJSON(&tx)
|
// found, err := txcmd.LoadJSON(&tx)
|
||||||
|
|
|
@ -4,23 +4,25 @@ package coin
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
pkgerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/basecoin/errors"
|
"github.com/tendermint/basecoin/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNoAccount = fmt.Errorf("No such account")
|
errNoAccount = fmt.Errorf("No such account")
|
||||||
errInsufficientFunds = fmt.Errorf("Insufficient Funds")
|
errInsufficientFunds = fmt.Errorf("Insufficient funds")
|
||||||
errNoInputs = fmt.Errorf("No Input Coins")
|
errNoInputs = fmt.Errorf("No input coins")
|
||||||
errNoOutputs = fmt.Errorf("No Output Coins")
|
errNoOutputs = fmt.Errorf("No output coins")
|
||||||
errInvalidAddress = fmt.Errorf("Invalid Address")
|
errInvalidAddress = fmt.Errorf("Invalid address")
|
||||||
errInvalidCoins = fmt.Errorf("Invalid Coins")
|
errInvalidCoins = fmt.Errorf("Invalid coins")
|
||||||
)
|
errUnknownKey = fmt.Errorf("Unknown key")
|
||||||
|
|
||||||
var (
|
|
||||||
invalidInput = abci.CodeType_BaseInvalidInput
|
invalidInput = abci.CodeType_BaseInvalidInput
|
||||||
invalidOutput = abci.CodeType_BaseInvalidOutput
|
invalidOutput = abci.CodeType_BaseInvalidOutput
|
||||||
unknownAddress = abci.CodeType_BaseUnknownAddress
|
unknownAddress = abci.CodeType_BaseUnknownAddress
|
||||||
|
unknownRequest = abci.CodeType_UnknownRequest
|
||||||
)
|
)
|
||||||
|
|
||||||
// here are some generic handlers to grab classes of errors based on code
|
// here are some generic handlers to grab classes of errors based on code
|
||||||
|
@ -79,3 +81,11 @@ func ErrNoOutputs() errors.TMError {
|
||||||
func IsNoOutputsErr(err error) bool {
|
func IsNoOutputsErr(err error) bool {
|
||||||
return errors.IsSameError(errNoOutputs, err)
|
return errors.IsSameError(errNoOutputs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ErrUnknownKey(mod string) errors.TMError {
|
||||||
|
w := pkgerrors.Wrap(errUnknownKey, mod)
|
||||||
|
return errors.WithCode(w, unknownRequest)
|
||||||
|
}
|
||||||
|
func IsUnknownKeyErr(err error) bool {
|
||||||
|
return errors.IsSameError(errUnknownKey, err)
|
||||||
|
}
|
||||||
|
|
|
@ -99,7 +99,7 @@ func (h Handler) SetOption(l log.Logger, store state.KVStore, module, key, value
|
||||||
return "Success", nil
|
return "Success", nil
|
||||||
|
|
||||||
}
|
}
|
||||||
return "", errors.ErrUnknownKey(key)
|
return "", ErrUnknownKey(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkTx(ctx basecoin.Context, tx basecoin.Tx) (send SendTx, err error) {
|
func checkTx(ctx basecoin.Context, tx basecoin.Tx) (send SendTx, err error) {
|
||||||
|
|
|
@ -10,19 +10,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInsufficientFees = fmt.Errorf("Insufficient Fees")
|
errInsufficientFees = fmt.Errorf("Insufficient fees")
|
||||||
errWrongFeeDenom = fmt.Errorf("Required fee denomination")
|
errWrongFeeDenom = fmt.Errorf("Required fee denomination")
|
||||||
|
|
||||||
|
invalidInput = abci.CodeType_BaseInvalidInput
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrInsufficientFees() errors.TMError {
|
func ErrInsufficientFees() errors.TMError {
|
||||||
return errors.WithCode(errInsufficientFees, abci.CodeType_BaseInvalidInput)
|
return errors.WithCode(errInsufficientFees, invalidInput)
|
||||||
}
|
}
|
||||||
func IsInsufficientFeesErr(err error) bool {
|
func IsInsufficientFeesErr(err error) bool {
|
||||||
return errors.IsSameError(errInsufficientFees, err)
|
return errors.IsSameError(errInsufficientFees, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrWrongFeeDenom(denom string) errors.TMError {
|
func ErrWrongFeeDenom(denom string) errors.TMError {
|
||||||
return errors.WithMessage(denom, errWrongFeeDenom, abci.CodeType_BaseInvalidInput)
|
return errors.WithMessage(denom, errWrongFeeDenom, invalidInput)
|
||||||
}
|
}
|
||||||
func IsWrongFeeDenomErr(err error) bool {
|
func IsWrongFeeDenomErr(err error) bool {
|
||||||
return errors.IsSameError(errWrongFeeDenom, err)
|
return errors.IsSameError(errWrongFeeDenom, err)
|
||||||
|
|
|
@ -11,22 +11,31 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNoNonce = fmt.Errorf("Tx doesn't contain nonce")
|
errNoNonce = fmt.Errorf("Tx doesn't contain nonce")
|
||||||
errNotMember = fmt.Errorf("nonce contains non-permissioned member")
|
errNotMember = fmt.Errorf("Nonce contains non-permissioned member")
|
||||||
errZeroSequence = fmt.Errorf("Sequence number cannot be zero")
|
errZeroSequence = fmt.Errorf("Sequence number cannot be zero")
|
||||||
|
errNoSigners = fmt.Errorf("There are no signers")
|
||||||
|
errTxEmpty = fmt.Errorf("The provided Tx is empty")
|
||||||
|
|
||||||
unauthorized = abci.CodeType_Unauthorized
|
unauthorized = abci.CodeType_Unauthorized
|
||||||
|
badNonce = abci.CodeType_BadNonce
|
||||||
|
invalidInput = abci.CodeType_BaseInvalidInput
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrBadNonce(got, expected uint32) errors.TMError {
|
func ErrBadNonce(got, expected uint32) errors.TMError {
|
||||||
return errors.WithCode(fmt.Errorf("Bad nonce sequence, got %d, expected %d", got, expected), unauthorized)
|
return errors.WithCode(fmt.Errorf("Bad nonce sequence, got %d, expected %d", got, expected), badNonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNoNonce() errors.TMError {
|
func ErrNoNonce() errors.TMError {
|
||||||
return errors.WithCode(errNoNonce, unauthorized)
|
return errors.WithCode(errNoNonce, badNonce)
|
||||||
}
|
}
|
||||||
func ErrNotMember() errors.TMError {
|
func ErrNotMember() errors.TMError {
|
||||||
return errors.WithCode(errNotMember, unauthorized)
|
return errors.WithCode(errNotMember, unauthorized)
|
||||||
}
|
}
|
||||||
func ErrZeroSequence() errors.TMError {
|
func ErrZeroSequence() errors.TMError {
|
||||||
return errors.WithCode(errZeroSequence, unauthorized)
|
return errors.WithCode(errZeroSequence, invalidInput)
|
||||||
|
}
|
||||||
|
func ErrNoSigners() errors.TMError {
|
||||||
|
return errors.WithCode(errNoSigners, invalidInput)
|
||||||
|
}
|
||||||
|
func ErrTxEmpty() errors.TMError {
|
||||||
|
return errors.WithCode(errTxEmpty, invalidInput)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/tendermint/basecoin"
|
"github.com/tendermint/basecoin"
|
||||||
"github.com/tendermint/basecoin/errors"
|
|
||||||
"github.com/tendermint/basecoin/state"
|
"github.com/tendermint/basecoin/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,11 +49,11 @@ func (n Tx) Wrap() basecoin.Tx {
|
||||||
func (n Tx) ValidateBasic() error {
|
func (n Tx) ValidateBasic() error {
|
||||||
switch {
|
switch {
|
||||||
case n.Tx.Empty():
|
case n.Tx.Empty():
|
||||||
return errors.ErrTxEmpty()
|
return ErrTxEmpty()
|
||||||
case n.Sequence == 0:
|
case n.Sequence == 0:
|
||||||
return ErrZeroSequence()
|
return ErrZeroSequence()
|
||||||
case len(n.Signers) == 0:
|
case len(n.Signers) == 0:
|
||||||
return errors.ErrNoSigners()
|
return ErrNoSigners()
|
||||||
}
|
}
|
||||||
return n.Tx.ValidateBasic()
|
return n.Tx.ValidateBasic()
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,54 +16,56 @@ var (
|
||||||
errNoMembers = fmt.Errorf("No members specified")
|
errNoMembers = fmt.Errorf("No members specified")
|
||||||
errTooManyMembers = fmt.Errorf("Too many members specified")
|
errTooManyMembers = fmt.Errorf("Too many members specified")
|
||||||
errNotEnoughMembers = fmt.Errorf("Not enough members specified")
|
errNotEnoughMembers = fmt.Errorf("Not enough members specified")
|
||||||
|
|
||||||
|
unauthorized = abci.CodeType_Unauthorized
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: codegen?
|
// TODO: codegen?
|
||||||
// ex: err-gen NoRole,"No such role",CodeType_Unauthorized
|
// ex: err-gen NoRole,"No such role",CodeType_Unauthorized
|
||||||
func ErrNoRole() errors.TMError {
|
func ErrNoRole() errors.TMError {
|
||||||
return errors.WithCode(errNoRole, abci.CodeType_Unauthorized)
|
return errors.WithCode(errNoRole, unauthorized)
|
||||||
}
|
}
|
||||||
func IsNoRoleErr(err error) bool {
|
func IsNoRoleErr(err error) bool {
|
||||||
return errors.IsSameError(errNoRole, err)
|
return errors.IsSameError(errNoRole, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrRoleExists() errors.TMError {
|
func ErrRoleExists() errors.TMError {
|
||||||
return errors.WithCode(errRoleExists, abci.CodeType_Unauthorized)
|
return errors.WithCode(errRoleExists, unauthorized)
|
||||||
}
|
}
|
||||||
func IsRoleExistsErr(err error) bool {
|
func IsRoleExistsErr(err error) bool {
|
||||||
return errors.IsSameError(errRoleExists, err)
|
return errors.IsSameError(errRoleExists, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNotMember() errors.TMError {
|
func ErrNotMember() errors.TMError {
|
||||||
return errors.WithCode(errNotMember, abci.CodeType_Unauthorized)
|
return errors.WithCode(errNotMember, unauthorized)
|
||||||
}
|
}
|
||||||
func IsNotMemberErr(err error) bool {
|
func IsNotMemberErr(err error) bool {
|
||||||
return errors.IsSameError(errNotMember, err)
|
return errors.IsSameError(errNotMember, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrInsufficientSigs() errors.TMError {
|
func ErrInsufficientSigs() errors.TMError {
|
||||||
return errors.WithCode(errInsufficientSigs, abci.CodeType_Unauthorized)
|
return errors.WithCode(errInsufficientSigs, unauthorized)
|
||||||
}
|
}
|
||||||
func IsInsufficientSigsErr(err error) bool {
|
func IsInsufficientSigsErr(err error) bool {
|
||||||
return errors.IsSameError(errInsufficientSigs, err)
|
return errors.IsSameError(errInsufficientSigs, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNoMembers() errors.TMError {
|
func ErrNoMembers() errors.TMError {
|
||||||
return errors.WithCode(errNoMembers, abci.CodeType_Unauthorized)
|
return errors.WithCode(errNoMembers, unauthorized)
|
||||||
}
|
}
|
||||||
func IsNoMembersErr(err error) bool {
|
func IsNoMembersErr(err error) bool {
|
||||||
return errors.IsSameError(errNoMembers, err)
|
return errors.IsSameError(errNoMembers, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrTooManyMembers() errors.TMError {
|
func ErrTooManyMembers() errors.TMError {
|
||||||
return errors.WithCode(errTooManyMembers, abci.CodeType_Unauthorized)
|
return errors.WithCode(errTooManyMembers, unauthorized)
|
||||||
}
|
}
|
||||||
func IsTooManyMembersErr(err error) bool {
|
func IsTooManyMembersErr(err error) bool {
|
||||||
return errors.IsSameError(errTooManyMembers, err)
|
return errors.IsSameError(errTooManyMembers, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrNotEnoughMembers() errors.TMError {
|
func ErrNotEnoughMembers() errors.TMError {
|
||||||
return errors.WithCode(errNotEnoughMembers, abci.CodeType_Unauthorized)
|
return errors.WithCode(errNotEnoughMembers, unauthorized)
|
||||||
}
|
}
|
||||||
func IsNotEnoughMembersErr(err error) bool {
|
func IsNotEnoughMembersErr(err error) bool {
|
||||||
return errors.IsSameError(errNotEnoughMembers, err)
|
return errors.IsSameError(errNotEnoughMembers, err)
|
||||||
|
|
Loading…
Reference in New Issue