Complete error package overhaul

This commit is contained in:
Ethan Frey
2017-07-03 14:50:33 +02:00
parent 5fa77bf647
commit 995452ea02
16 changed files with 184 additions and 107 deletions
+19
View File
@@ -0,0 +1,19 @@
package fee
import (
rawerr "errors"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/basecoin/errors"
)
var (
errInsufficientFees = rawerr.New("Insufficient Fees")
)
func ErrInsufficientFees() errors.TMError {
return errors.WithCode(errInsufficientFees, abci.CodeType_BaseInvalidInput)
}
func IsInsufficientFeesErr(err error) bool {
return errors.IsSameError(errInsufficientFees, err)
}
+6 -6
View File
@@ -36,16 +36,16 @@ var _ stack.Middleware = SimpleFeeHandler{}
func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
feeTx, ok := tx.Unwrap().(*Fee)
if !ok {
return res, errors.InvalidFormat()
return res, errors.ErrInvalidFormat(tx)
}
fees := types.Coins{feeTx.Fee}
if !fees.IsGTE(h.MinFee) {
return res, errors.InsufficientFees()
return res, ErrInsufficientFees()
}
if !ctx.HasPermission(feeTx.Payer) {
return res, errors.Unauthorized()
return res, errors.ErrUnauthorized()
}
_, err = h.ChangeAmount(store, feeTx.Payer, fees.Negative())
@@ -59,16 +59,16 @@ func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx
func (h SimpleFeeHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
feeTx, ok := tx.Unwrap().(*Fee)
if !ok {
return res, errors.InvalidFormat()
return res, errors.ErrInvalidFormat(tx)
}
fees := types.Coins{feeTx.Fee}
if !fees.IsGTE(h.MinFee) {
return res, errors.InsufficientFees()
return res, ErrInsufficientFees()
}
if !ctx.HasPermission(feeTx.Payer) {
return res, errors.Unauthorized()
return res, errors.ErrUnauthorized()
}
_, err = h.ChangeAmount(store, feeTx.Payer, fees.Negative())