From a047e210fa25e87e5eca0645cac01e1ec655e976 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 6 Jul 2017 16:00:54 +0200 Subject: [PATCH] Moved the handlers from stack into modules --- app/app.go | 9 +++++++- app/app_test.go | 4 ++-- cmd/basecli/commands/cmds.go | 6 +++--- cmd/basecli/commands/query.go | 4 ++-- docs/guide/counter/plugins/counter/counter.go | 11 ++++++++-- {stack => modules/auth}/signature.go | 21 ++++++++++++------- {stack => modules/auth}/signature_test.go | 15 ++++++------- {stack => modules/base}/chain.go | 15 ++++++++----- {stack => modules/base}/chain_test.go | 9 ++++---- {stack => modules/base}/logger.go | 18 ++++++++++------ {stack => modules/base}/multiplexer.go | 18 ++++++++++------ modules/coin/handler.go | 4 ++-- modules/coin/handler_test.go | 3 ++- modules/coin/helper.go | 4 ++-- stack/middleware.go | 14 ------------- stack/middleware_test.go | 6 +++++- stack/recovery.go | 13 ++++++++---- stack/recovery_test.go | 2 +- 18 files changed, 104 insertions(+), 72 deletions(-) rename {stack => modules/auth}/signature.go (61%) rename {stack => modules/auth}/signature_test.go (86%) rename {stack => modules/base}/chain.go (75%) rename {stack => modules/base}/chain_test.go (88%) rename {stack => modules/base}/logger.go (63%) rename {stack => modules/base}/multiplexer.go (65%) diff --git a/app/app.go b/app/app.go index 4fb96772f..27f31950d 100644 --- a/app/app.go +++ b/app/app.go @@ -11,6 +11,8 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/modules/auth" + "github.com/tendermint/basecoin/modules/base" "github.com/tendermint/basecoin/modules/coin" "github.com/tendermint/basecoin/stack" sm "github.com/tendermint/basecoin/state" @@ -50,7 +52,12 @@ func DefaultHandler() basecoin.Handler { // use the default stack h := coin.NewHandler() d := stack.NewDispatcher(stack.WrapHandler(h)) - return stack.NewDefault().Use(d) + return stack.New( + base.Logger{}, + stack.Recovery{}, + auth.Signatures{}, + base.Chain{}, + ).Use(d) } // GetState - XXX For testing, not thread safe! diff --git a/app/app_test.go b/app/app_test.go index 5d04d22db..9e6ac1037 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -10,8 +10,8 @@ import ( abci "github.com/tendermint/abci/types" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/modules/coin" - "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" wire "github.com/tendermint/go-wire" @@ -87,7 +87,7 @@ func getBalance(key basecoin.Actor, state state.KVStore) (coin.Coins, error) { } func getAddr(addr []byte, state state.KVStore) (coin.Coins, error) { - actor := stack.SigPerm(addr) + actor := auth.SigPerm(addr) return getBalance(actor, state) } diff --git a/cmd/basecli/commands/cmds.go b/cmd/basecli/commands/cmds.go index b877b7dbd..aa0bf14ba 100644 --- a/cmd/basecli/commands/cmds.go +++ b/cmd/basecli/commands/cmds.go @@ -13,8 +13,8 @@ import ( txcmd "github.com/tendermint/light-client/commands/txs" cmn "github.com/tendermint/tmlibs/common" + "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/modules/coin" - "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/txs" ) @@ -82,7 +82,7 @@ func readSendTxFlags() (tx basecoin.Tx, err error) { if err != nil { return tx, err } - toAddr := stack.SigPerm(to) + toAddr := auth.SigPerm(to) toAddr.ChainID = chain // //parse the fee and amounts into coin types @@ -102,7 +102,7 @@ func readSendTxFlags() (tx basecoin.Tx, err error) { var fromAddr basecoin.Actor signer := txcmd.GetSigner() if !signer.Empty() { - fromAddr = stack.SigPerm(signer.Address()) + fromAddr = auth.SigPerm(signer.Address()) } // craft the inputs and outputs diff --git a/cmd/basecli/commands/query.go b/cmd/basecli/commands/query.go index 1bb05aef7..aba5fbf55 100644 --- a/cmd/basecli/commands/query.go +++ b/cmd/basecli/commands/query.go @@ -11,8 +11,8 @@ import ( proofcmd "github.com/tendermint/light-client/commands/proofs" "github.com/tendermint/light-client/proofs" + "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/modules/coin" - "github.com/tendermint/basecoin/stack" ) // AccountQueryCmd - command to query an account @@ -27,7 +27,7 @@ func doAccountQuery(cmd *cobra.Command, args []string) error { if err != nil { return err } - key := coin.NewAccountant("").MakeKey(stack.SigPerm(addr)) + key := coin.NewAccountant("").MakeKey(auth.SigPerm(addr)) acc := coin.Account{} proof, err := proofcmd.GetAndParseAppProof(key, &acc) diff --git a/docs/guide/counter/plugins/counter/counter.go b/docs/guide/counter/plugins/counter/counter.go index dffa4a610..0bf38f362 100644 --- a/docs/guide/counter/plugins/counter/counter.go +++ b/docs/guide/counter/plugins/counter/counter.go @@ -8,6 +8,8 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/modules/auth" + "github.com/tendermint/basecoin/modules/base" "github.com/tendermint/basecoin/modules/coin" "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" @@ -95,7 +97,12 @@ func NewHandler() basecoin.Handler { stack.WrapHandler(coin), counter, ) - return stack.NewDefault().Use(dispatcher) + return stack.New( + base.Logger{}, + stack.Recovery{}, + auth.Signatures{}, + base.Chain{}, + ).Use(dispatcher) } // Handler the counter transaction processing handler @@ -134,7 +141,7 @@ func (h Handler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoi // handle coin movement.... like, actually decrement the other account if !ctr.Fee.IsZero() { // take the coins and put them in out account! - senders := ctx.GetPermissions("", stack.NameSigs) + senders := ctx.GetPermissions("", auth.NameSigs) if len(senders) == 0 { return res, errors.ErrMissingSignature() } diff --git a/stack/signature.go b/modules/auth/signature.go similarity index 61% rename from stack/signature.go rename to modules/auth/signature.go index 3edf22969..b986046ef 100644 --- a/stack/signature.go +++ b/modules/auth/signature.go @@ -1,28 +1,33 @@ -package stack +package auth import ( crypto "github.com/tendermint/go-crypto" "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" ) -// app name for auth +//nolint const ( NameSigs = "sigs" ) +// Signatures parses out go-crypto signatures and adds permissions to the +// context for use inside the application type Signatures struct { - PassOption + stack.PassOption } -func (_ Signatures) Name() string { +// Name of the module - fulfills Middleware interface +func (Signatures) Name() string { return NameSigs } -var _ Middleware = Signatures{} +var _ stack.Middleware = Signatures{} +// SigPerm takes the binary address from PubKey.Address and makes it an Actor func SigPerm(addr []byte) basecoin.Actor { return basecoin.NewActor(NameSigs, addr) } @@ -33,7 +38,8 @@ type Signed interface { Signers() ([]crypto.PubKey, error) } -func (h Signatures) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +// CheckTx verifies the signatures are correct - fulfills Middlware interface +func (Signatures) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { sigs, tnext, err := getSigners(tx) if err != nil { return res, err @@ -42,7 +48,8 @@ func (h Signatures) CheckTx(ctx basecoin.Context, store state.KVStore, tx baseco return next.CheckTx(ctx2, store, tnext) } -func (h Signatures) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +// DeliverTx verifies the signatures are correct - fulfills Middlware interface +func (Signatures) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { sigs, tnext, err := getSigners(tx) if err != nil { return res, err diff --git a/stack/signature_test.go b/modules/auth/signature_test.go similarity index 86% rename from stack/signature_test.go rename to modules/auth/signature_test.go index 4f99849e0..f1805aea7 100644 --- a/stack/signature_test.go +++ b/modules/auth/signature_test.go @@ -1,4 +1,4 @@ -package stack +package auth import ( "strconv" @@ -10,6 +10,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" ) @@ -18,7 +19,7 @@ func TestSignatureChecks(t *testing.T) { assert := assert.New(t) // generic args - ctx := NewContext("test-chain", log.NewNopLogger()) + ctx := stack.NewContext("test-chain", log.NewNopLogger()) store := state.NewMemKVStore() raw := txs.NewRaw([]byte{1, 2, 3, 4}) @@ -56,11 +57,10 @@ func TestSignatureChecks(t *testing.T) { idx := strconv.Itoa(i) // make the stack check for the given permission - app := New( - Recovery{}, // we need this so panics turn to errors + app := stack.New( Signatures{}, - CheckMiddleware{Required: tc.check}, - ).Use(OKHandler{}) + stack.CheckMiddleware{Required: tc.check}, + ).Use(stack.OKHandler{}) var tx basecoin.Tx // this does the signing as needed @@ -80,11 +80,8 @@ func TestSignatureChecks(t *testing.T) { tx = otx.Wrap() } - // this will trivial expose the printing error... - // _, err := app.CheckTx(ctx, store, raw) _, err := app.CheckTx(ctx, store, tx) if tc.valid { - // TODO: why doen't tmerror print properly??? assert.Nil(err, "%d: %+v", i, err) } else { assert.NotNil(err, idx) diff --git a/stack/chain.go b/modules/base/chain.go similarity index 75% rename from stack/chain.go rename to modules/base/chain.go index 47c9bd200..c6d5dab5c 100644 --- a/stack/chain.go +++ b/modules/base/chain.go @@ -1,27 +1,31 @@ -package stack +package base import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" ) +//nolint const ( NameChain = "chan" ) // Chain enforces that this tx was bound to the named chain type Chain struct { - PassOption + stack.PassOption } -func (_ Chain) Name() string { - return NameRecovery +// Name of the module - fulfills Middleware interface +func (Chain) Name() string { + return NameChain } -var _ Middleware = Chain{} +var _ stack.Middleware = Chain{} +// CheckTx makes sure we are on the proper chain - fulfills Middlware interface func (c Chain) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { stx, err := c.checkChain(ctx.ChainID(), tx) if err != nil { @@ -30,6 +34,7 @@ func (c Chain) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx return next.CheckTx(ctx, store, stx) } +// DeliverTx makes sure we are on the proper chain - fulfills Middlware interface func (c Chain) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { stx, err := c.checkChain(ctx.ChainID(), tx) if err != nil { diff --git a/stack/chain_test.go b/modules/base/chain_test.go similarity index 88% rename from stack/chain_test.go rename to modules/base/chain_test.go index 1e799dbb9..bd46fccd4 100644 --- a/stack/chain_test.go +++ b/modules/base/chain_test.go @@ -1,4 +1,4 @@ -package stack +package base import ( "strconv" @@ -9,6 +9,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" ) @@ -30,12 +31,12 @@ func TestChain(t *testing.T) { } // generic args here... - ctx := NewContext(chainID, log.NewNopLogger()) + ctx := stack.NewContext(chainID, log.NewNopLogger()) store := state.NewMemKVStore() // build the stack - ok := OKHandler{Log: msg} - app := New(Chain{}).Use(ok) + ok := stack.OKHandler{Log: msg} + app := stack.New(Chain{}).Use(ok) for idx, tc := range cases { i := strconv.Itoa(idx) diff --git a/stack/logger.go b/modules/base/logger.go similarity index 63% rename from stack/logger.go rename to modules/base/logger.go index aa8c1d5ff..23b595645 100644 --- a/stack/logger.go +++ b/modules/base/logger.go @@ -1,4 +1,4 @@ -package stack +package base import ( "time" @@ -6,9 +6,11 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" ) +// nolint const ( NameLogger = "lggr" ) @@ -16,13 +18,15 @@ const ( // Logger catches any panics and returns them as errors instead type Logger struct{} -func (_ Logger) Name() string { +// Name of the module - fulfills Middleware interface +func (Logger) Name() string { return NameLogger } -var _ Middleware = Logger{} +var _ stack.Middleware = Logger{} -func (_ Logger) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +// CheckTx logs time and result - fulfills Middlware interface +func (Logger) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { start := time.Now() res, err = next.CheckTx(ctx, store, tx) delta := time.Now().Sub(start) @@ -36,7 +40,8 @@ func (_ Logger) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.T return } -func (_ Logger) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +// DeliverTx logs time and result - fulfills Middlware interface +func (Logger) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { start := time.Now() res, err = next.DeliverTx(ctx, store, tx) delta := time.Now().Sub(start) @@ -50,7 +55,8 @@ func (_ Logger) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin return } -func (_ Logger) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { +// SetOption logs time and result - fulfills Middlware interface +func (Logger) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { start := time.Now() res, err := next.SetOption(l, store, module, key, value) delta := time.Now().Sub(start) diff --git a/stack/multiplexer.go b/modules/base/multiplexer.go similarity index 65% rename from stack/multiplexer.go rename to modules/base/multiplexer.go index b306c7145..b14c58ce2 100644 --- a/stack/multiplexer.go +++ b/modules/base/multiplexer.go @@ -1,4 +1,4 @@ -package stack +package base import ( "strings" @@ -7,32 +7,38 @@ import ( "github.com/tendermint/go-wire/data" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" ) +//nolint const ( NameMultiplexer = "mplx" ) +// Multiplexer grabs a MultiTx and sends them sequentially down the line type Multiplexer struct { - PassOption + stack.PassOption } -func (_ Multiplexer) Name() string { +// Name of the module - fulfills Middleware interface +func (Multiplexer) Name() string { return NameMultiplexer } -var _ Middleware = Multiplexer{} +var _ stack.Middleware = Multiplexer{} -func (_ Multiplexer) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +// CheckTx splits the input tx and checks them all - fulfills Middlware interface +func (Multiplexer) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { if mtx, ok := tx.Unwrap().(*txs.MultiTx); ok { return runAll(ctx, store, mtx.Txs, next.CheckTx) } return next.CheckTx(ctx, store, tx) } -func (_ Multiplexer) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +// DeliverTx splits the input tx and checks them all - fulfills Middlware interface +func (Multiplexer) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { if mtx, ok := tx.Unwrap().(*txs.MultiTx); ok { return runAll(ctx, store, mtx.Txs, next.DeliverTx) } diff --git a/modules/coin/handler.go b/modules/coin/handler.go index 3320c9b2f..cd45910f3 100644 --- a/modules/coin/handler.go +++ b/modules/coin/handler.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/stack" + "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/state" ) @@ -98,7 +98,7 @@ func (h Handler) SetOption(l log.Logger, store state.KVStore, module, key, value return "", ErrInvalidAddress() } // this sets the permission for a public key signature, use that app - actor := stack.SigPerm(addr) + actor := auth.SigPerm(addr) err = storeAccount(store, h.MakeKey(actor), acc.ToAccount()) if err != nil { return "", err diff --git a/modules/coin/handler_test.go b/modules/coin/handler_test.go index 48eb91ff3..74692bbc6 100644 --- a/modules/coin/handler_test.go +++ b/modules/coin/handler_test.go @@ -11,6 +11,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" ) @@ -172,7 +173,7 @@ func TestSetOption(t *testing.T) { // some sample settings pk := crypto.GenPrivKeySecp256k1().Wrap() addr := pk.PubKey().Address() - actor := basecoin.Actor{App: stack.NameSigs, Address: addr} + actor := auth.SigPerm(addr) someCoins := Coins{{"atom", 123}} otherCoins := Coins{{"eth", 11}} diff --git a/modules/coin/helper.go b/modules/coin/helper.go index d15333982..4c66ec6a8 100644 --- a/modules/coin/helper.go +++ b/modules/coin/helper.go @@ -1,11 +1,11 @@ package coin import ( + "github.com/tendermint/basecoin/modules/auth" crypto "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire/data" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/stack" ) // AccountWithKey is a helper for tests, that includes and account @@ -31,7 +31,7 @@ func (a *AccountWithKey) Address() []byte { // Actor returns the basecoin actor associated with this account func (a *AccountWithKey) Actor() basecoin.Actor { - return stack.SigPerm(a.Key.PubKey().Address()) + return auth.SigPerm(a.Key.PubKey().Address()) } // MakeOption returns a string to use with SetOption to initialize this account diff --git a/stack/middleware.go b/stack/middleware.go index 0ae1926fb..b7e1e58dd 100644 --- a/stack/middleware.go +++ b/stack/middleware.go @@ -60,20 +60,6 @@ func New(middlewares ...Middleware) *Stack { } } -// NewDefault sets up the common middlewares before your custom stack. -// -// This is logger, recovery, signature, and chain -func NewDefault(middlewares ...Middleware) *Stack { - mids := []Middleware{ - Logger{}, - Recovery{}, - Signatures{}, - Chain{}, - } - mids = append(mids, middlewares...) - return New(mids...) -} - // Use sets the final handler for the stack and prepares it for use func (s *Stack) Use(handler basecoin.Handler) *Stack { if handler == nil { diff --git a/stack/middleware_test.go b/stack/middleware_test.go index 2f8e48a84..ba3fe3cae 100644 --- a/stack/middleware_test.go +++ b/stack/middleware_test.go @@ -15,6 +15,10 @@ import ( "github.com/tendermint/basecoin/txs" ) +const ( + nameSigner = "signer" +) + func TestPermissionSandbox(t *testing.T) { require := require.New(t) @@ -28,7 +32,7 @@ func TestPermissionSandbox(t *testing.T) { // test cases to make sure permissioning is solid grantee := basecoin.Actor{App: NameGrant, Address: []byte{1}} grantee2 := basecoin.Actor{App: NameGrant, Address: []byte{2}} - signer := basecoin.Actor{App: NameSigs, Address: []byte{1}} + signer := basecoin.Actor{App: nameSigner, Address: []byte{1}} cases := []struct { grant basecoin.Actor require basecoin.Actor diff --git a/stack/recovery.go b/stack/recovery.go index eb03ee802..7ae7de20d 100644 --- a/stack/recovery.go +++ b/stack/recovery.go @@ -10,6 +10,7 @@ import ( "github.com/tendermint/basecoin/state" ) +// nolint const ( NameRecovery = "rcvr" ) @@ -17,13 +18,15 @@ const ( // Recovery catches any panics and returns them as errors instead type Recovery struct{} -func (_ Recovery) Name() string { +// Name of the module - fulfills Middleware interface +func (Recovery) Name() string { return NameRecovery } var _ Middleware = Recovery{} -func (_ Recovery) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +// CheckTx catches any panic and converts to error - fulfills Middlware interface +func (Recovery) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { defer func() { if r := recover(); r != nil { err = normalizePanic(r) @@ -32,7 +35,8 @@ func (_ Recovery) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin return next.CheckTx(ctx, store, tx) } -func (_ Recovery) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +// DeliverTx catches any panic and converts to error - fulfills Middlware interface +func (Recovery) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { defer func() { if r := recover(); r != nil { err = normalizePanic(r) @@ -41,7 +45,8 @@ func (_ Recovery) DeliverTx(ctx basecoin.Context, store state.KVStore, tx baseco return next.DeliverTx(ctx, store, tx) } -func (_ Recovery) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (log string, err error) { +// SetOption catches any panic and converts to error - fulfills Middlware interface +func (Recovery) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (log string, err error) { defer func() { if r := recover(); r != nil { err = normalizePanic(r) diff --git a/stack/recovery_test.go b/stack/recovery_test.go index 7044bdfa7..15eafba7b 100644 --- a/stack/recovery_test.go +++ b/stack/recovery_test.go @@ -27,7 +27,7 @@ func TestRecovery(t *testing.T) { expected string // expected text in panic }{ {"buzz", nil, "buzz"}, - {"", errors.New("owa!"), "owa!"}, + {"", errors.New("some text"), "some text"}, {"text", errors.New("error"), "error"}, }