diff --git a/app/app_test.go b/app/app_test.go index 753efcf3f7..2cb636e1c2 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -69,13 +69,13 @@ func (at *appTest) reset() { at.accOut = types.MakeAcc("output0") eyesCli := eyes.NewLocalClient("", 0) - // l := log.TestingLogger().With("module", "app"), - l := log.NewTMLogger(os.Stdout).With("module", "app") - l = log.NewTracingLogger(l) + // logger := log.TestingLogger().With("module", "app"), + logger := log.NewTMLogger(os.Stdout).With("module", "app") + logger = log.NewTracingLogger(logger) at.app = NewBasecoin( DefaultHandler(), eyesCli, - l, + logger, ) res := at.app.SetOption("base/chain_id", at.chainID) diff --git a/docs/guide/counter/plugins/counter/counter.go b/docs/guide/counter/plugins/counter/counter.go index 7587b7a796..79394249ef 100644 --- a/docs/guide/counter/plugins/counter/counter.go +++ b/docs/guide/counter/plugins/counter/counter.go @@ -1,7 +1,7 @@ package counter import ( - rawerr "errors" + "fmt" abci "github.com/tendermint/abci/types" "github.com/tendermint/go-wire" @@ -65,7 +65,7 @@ func (c Tx) ValidateBasic() error { //-------------------------------------------------------------------------------- var ( - errInvalidCounter = rawerr.New("Counter Tx marked invalid") + errInvalidCounter = fmt.Errorf("Counter Tx marked invalid") ) // ErrInvalidCounter - custom error class diff --git a/docs/guide/counter/plugins/counter/counter_test.go b/docs/guide/counter/plugins/counter/counter_test.go index fcc36a15c1..ceeb9a5526 100644 --- a/docs/guide/counter/plugins/counter/counter_test.go +++ b/docs/guide/counter/plugins/counter/counter_test.go @@ -23,16 +23,15 @@ func TestCounterPlugin(t *testing.T) { eyesCli := eyescli.NewLocalClient("", 0) chainID := "test_chain_id" - // l := log.TestingLogger().With("module", "app"), - l := log.NewTMLogger(os.Stdout).With("module", "app") - // l = log.NewTracingLogger(l) + // logger := log.TestingLogger().With("module", "app"), + logger := log.NewTMLogger(os.Stdout).With("module", "app") + // logger = log.NewTracingLogger(logger) bcApp := app.NewBasecoin( NewHandler(), eyesCli, - l, + logger, ) bcApp.SetOption("base/chain_id", chainID) - // t.Log(bcApp.Info()) // Account initialization test1PrivAcc := types.PrivAccountFromSecret("test1") diff --git a/stack/dispatcher.go b/stack/dispatcher.go index 5da79f7a04..df065973d7 100644 --- a/stack/dispatcher.go +++ b/stack/dispatcher.go @@ -11,6 +11,7 @@ import ( "github.com/tendermint/basecoin/types" ) +// nolint const ( NameDispatcher = "disp" ) @@ -19,10 +20,16 @@ const ( // // It will route tx to the proper locations and also allows them to call each // other synchronously through the same tx methods. +// +// Please note that iterating through a map is a non-deteministic operation +// and, as such, should never be done in the context of an ABCI app. Only +// use this map to look up an exact route by name. type Dispatcher struct { routes map[string]Dispatchable } +// NewDispatcher creates a dispatcher and adds the given routes. +// You can also add routes later with .AddRoutes() func NewDispatcher(routes ...Dispatchable) *Dispatcher { d := &Dispatcher{ routes: map[string]Dispatchable{}, @@ -47,10 +54,16 @@ func (d *Dispatcher) AddRoutes(routes ...Dispatchable) { } } +// Name - defines the name of this module func (d *Dispatcher) Name() string { return NameDispatcher } +// CheckTx - implements Handler interface +// +// Tries to find a registered module (Dispatchable) based on the name of the tx. +// The tx name (as registered with go-data) should be in the form `/XXXX`, +// where `module name` must match the name of a dispatchable and XXX can be any string. func (d *Dispatcher) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { r, err := d.lookupTx(tx) if err != nil { @@ -61,6 +74,11 @@ func (d *Dispatcher) CheckTx(ctx basecoin.Context, store types.KVStore, tx basec return r.CheckTx(ctx, store, tx, cb) } +// DeliverTx - implements Handler interface +// +// Tries to find a registered module (Dispatchable) based on the name of the tx. +// The tx name (as registered with go-data) should be in the form `/XXXX`, +// where `module name` must match the name of a dispatchable and XXX can be any string. func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { r, err := d.lookupTx(tx) if err != nil { @@ -71,6 +89,10 @@ func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store types.KVStore, tx bas return r.DeliverTx(ctx, store, tx, cb) } +// SetOption - implements Handler interface +// +// Tries to find a registered module (Dispatchable) based on the +// module name from SetOption of the tx. func (d *Dispatcher) SetOption(l log.Logger, store types.KVStore, module, key, value string) (string, error) { r, err := d.lookupModule(module) if err != nil {