Cleanup as requested on PR

This commit is contained in:
Ethan Frey 2017-07-06 12:18:20 +02:00
parent 205e38ee1a
commit 390fdf95cf
4 changed files with 32 additions and 11 deletions

View File

@ -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)

View File

@ -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

View File

@ -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")

View File

@ -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 `<module name>/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 `<module name>/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 {