Fix util package with rename
This commit is contained in:
parent
555db84977
commit
6aa10f24db
|
@ -4,7 +4,6 @@ import (
|
|||
"regexp"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk"
|
||||
"github.com/cosmos/cosmos-sdk/state"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -33,7 +32,7 @@ var _ sdk.Decorator = Chain{}
|
|||
|
||||
// CheckTx makes sure we are on the proper chain
|
||||
// - fulfills Decorator interface
|
||||
func (c Chain) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (c Chain) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}, next sdk.Checker) (res sdk.CheckResult, err error) {
|
||||
|
||||
err = c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx)
|
||||
|
@ -45,7 +44,7 @@ func (c Chain) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
|||
|
||||
// DeliverTx makes sure we are on the proper chain
|
||||
// - fulfills Decorator interface
|
||||
func (c Chain) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (c Chain) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}, next sdk.Deliverer) (res sdk.DeliverResult, err error) {
|
||||
|
||||
err = c.checkChainTx(ctx.ChainID(), ctx.BlockHeight(), tx)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
/**
|
||||
Package util contains various utility handlers, decorators,
|
||||
and test helpers that can be use by many modules and applications.
|
||||
**/
|
||||
package util
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk"
|
||||
"github.com/cosmos/cosmos-sdk/errors"
|
||||
"github.com/cosmos/cosmos-sdk/state"
|
||||
)
|
||||
|
||||
//nolint
|
||||
|
@ -49,13 +48,13 @@ type OKHandler struct {
|
|||
var _ sdk.Handler = OKHandler{}
|
||||
|
||||
// CheckTx always returns an empty success tx
|
||||
func (ok OKHandler) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (ok OKHandler) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.CheckResult, err error) {
|
||||
return sdk.CheckResult{Log: ok.Log}, nil
|
||||
}
|
||||
|
||||
// DeliverTx always returns an empty success tx
|
||||
func (ok OKHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (ok OKHandler) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.DeliverResult, err error) {
|
||||
return sdk.DeliverResult{Log: ok.Log}, nil
|
||||
}
|
||||
|
@ -66,14 +65,14 @@ type EchoHandler struct{}
|
|||
var _ sdk.Handler = EchoHandler{}
|
||||
|
||||
// CheckTx returns input if RawTx comes in, otherwise panic
|
||||
func (EchoHandler) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (EchoHandler) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
msg interface{}) (res sdk.CheckResult, err error) {
|
||||
raw := sdk.MustGetTx(msg).(RawTx)
|
||||
return sdk.CheckResult{Data: raw.Data}, nil
|
||||
}
|
||||
|
||||
// DeliverTx returns input if RawTx comes in, otherwise panic
|
||||
func (EchoHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (EchoHandler) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
msg interface{}) (res sdk.DeliverResult, err error) {
|
||||
raw := sdk.MustGetTx(msg).(RawTx)
|
||||
return sdk.DeliverResult{Data: raw.Data}, nil
|
||||
|
@ -87,13 +86,13 @@ type FailHandler struct {
|
|||
var _ sdk.Handler = FailHandler{}
|
||||
|
||||
// CheckTx always returns the given error
|
||||
func (f FailHandler) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (f FailHandler) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.CheckResult, err error) {
|
||||
return res, errors.Wrap(f.Err)
|
||||
}
|
||||
|
||||
// DeliverTx always returns the given error
|
||||
func (f FailHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (f FailHandler) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.DeliverResult, err error) {
|
||||
return res, errors.Wrap(f.Err)
|
||||
}
|
||||
|
@ -107,7 +106,7 @@ type PanicHandler struct {
|
|||
var _ sdk.Handler = PanicHandler{}
|
||||
|
||||
// CheckTx always panics
|
||||
func (p PanicHandler) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (p PanicHandler) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.CheckResult, err error) {
|
||||
|
||||
if p.Err != nil {
|
||||
|
@ -117,7 +116,7 @@ func (p PanicHandler) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
|||
}
|
||||
|
||||
// DeliverTx always panics
|
||||
func (p PanicHandler) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (p PanicHandler) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}) (res sdk.DeliverResult, err error) {
|
||||
|
||||
if p.Err != nil {
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
abci "github.com/tendermint/abci/types"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk"
|
||||
"github.com/cosmos/cosmos-sdk/state"
|
||||
)
|
||||
|
||||
// Logger writes out log messages on every request
|
||||
|
@ -15,7 +14,7 @@ type Logger struct{}
|
|||
var _ sdk.Decorator = Logger{}
|
||||
|
||||
// CheckTx logs time and result - fulfills Middlware interface
|
||||
func (Logger) CheckTx(ctx sdk.Context, store state.SimpleDB, tx interface{}, next sdk.Checker) (res sdk.CheckResult, err error) {
|
||||
func (Logger) CheckTx(ctx sdk.Context, store sdk.SimpleDB, tx interface{}, next sdk.Checker) (res sdk.CheckResult, err error) {
|
||||
start := time.Now()
|
||||
res, err = next.CheckTx(ctx, store, tx)
|
||||
delta := time.Now().Sub(start)
|
||||
|
@ -30,7 +29,7 @@ func (Logger) CheckTx(ctx sdk.Context, store state.SimpleDB, tx interface{}, nex
|
|||
}
|
||||
|
||||
// DeliverTx logs time and result - fulfills Middlware interface
|
||||
func (Logger) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx interface{}, next sdk.Deliverer) (res sdk.DeliverResult, err error) {
|
||||
func (Logger) DeliverTx(ctx sdk.Context, store sdk.SimpleDB, tx interface{}, next sdk.Deliverer) (res sdk.DeliverResult, err error) {
|
||||
start := time.Now()
|
||||
res, err = next.DeliverTx(ctx, store, tx)
|
||||
delta := time.Now().Sub(start)
|
||||
|
@ -48,7 +47,7 @@ func (Logger) DeliverTx(ctx sdk.Context, store state.SimpleDB, tx interface{}, n
|
|||
// Pass in a name to be logged with this to separate out various
|
||||
// tickers
|
||||
func LogTicker(clock sdk.Ticker, name string) sdk.Ticker {
|
||||
res := func(ctx sdk.Context, s state.SimpleDB) ([]*abci.Validator, error) {
|
||||
res := func(ctx sdk.Context, s sdk.SimpleDB) ([]*abci.Validator, error) {
|
||||
start := time.Now()
|
||||
vals, err := clock.Tick(ctx, s)
|
||||
delta := time.Now().Sub(start)
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
sdk "github.com/cosmos/cosmos-sdk"
|
||||
"github.com/cosmos/cosmos-sdk/errors"
|
||||
"github.com/cosmos/cosmos-sdk/state"
|
||||
)
|
||||
|
||||
// Recovery catches any panics and returns them as errors instead
|
||||
|
@ -14,7 +13,7 @@ type Recovery struct{}
|
|||
var _ sdk.Decorator = Recovery{}
|
||||
|
||||
// CheckTx catches any panic and converts to error - fulfills Middlware interface
|
||||
func (Recovery) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (Recovery) CheckTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}, next sdk.Checker) (res sdk.CheckResult, err error) {
|
||||
|
||||
defer func() {
|
||||
|
@ -26,7 +25,7 @@ func (Recovery) CheckTx(ctx sdk.Context, store state.SimpleDB,
|
|||
}
|
||||
|
||||
// DeliverTx catches any panic and converts to error - fulfills Middlware interface
|
||||
func (Recovery) DeliverTx(ctx sdk.Context, store state.SimpleDB,
|
||||
func (Recovery) DeliverTx(ctx sdk.Context, store sdk.SimpleDB,
|
||||
tx interface{}, next sdk.Deliverer) (res sdk.DeliverResult, err error) {
|
||||
|
||||
defer func() {
|
||||
|
|
Loading…
Reference in New Issue