From 49357a35749f71c573c5e91112b9d45c2a2680f8 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 6 Jul 2017 14:23:38 +0200 Subject: [PATCH] Move kvstore from types to state --- app/app_test.go | 5 +- docs/guide/counter/plugins/counter/counter.go | 9 +- handler.go | 32 +++--- modules/coin/handler.go | 8 +- modules/coin/handler_test.go | 5 +- modules/coin/store.go | 13 ++- modules/fee/handler.go | 9 +- plugins/ibc/ibc.go | 26 ++--- stack/chain.go | 6 +- stack/chain_test.go | 4 +- stack/context.go | 6 +- stack/dispatcher.go | 8 +- stack/helpers.go | 18 +-- stack/helpers_test.go | 8 +- stack/helperware.go | 10 +- stack/interface.go | 34 +++--- stack/logger.go | 8 +- stack/middleware.go | 8 +- stack/middleware_test.go | 12 +- stack/multiplexer.go | 13 ++- stack/recovery.go | 8 +- stack/recovery_test.go | 8 +- stack/signature.go | 6 +- stack/signature_test.go | 5 +- {types => state}/kvstore.go | 2 +- {types => state}/kvstore_test.go | 2 +- state/state.go | 9 +- state/state_test.go | 9 +- types/test_helpers.go | 105 ------------------ 29 files changed, 150 insertions(+), 246 deletions(-) rename {types => state}/kvstore.go (99%) rename {types => state}/kvstore_test.go (99%) delete mode 100644 types/test_helpers.go diff --git a/app/app_test.go b/app/app_test.go index 048240be58..840dfce799 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -12,6 +12,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/modules/coin" "github.com/tendermint/basecoin/stack" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" "github.com/tendermint/basecoin/types" wire "github.com/tendermint/go-wire" @@ -81,12 +82,12 @@ func (at *appTest) reset() { require.True(at.t, resabci.IsOK(), resabci) } -func getBalance(key basecoin.Actor, state types.KVStore) (types.Coins, error) { +func getBalance(key basecoin.Actor, state state.KVStore) (types.Coins, error) { acct, err := coin.NewAccountant("").GetAccount(state, key) return acct.Coins, err } -func getAddr(addr []byte, state types.KVStore) (types.Coins, error) { +func getAddr(addr []byte, state state.KVStore) (types.Coins, error) { actor := stack.SigPerm(addr) return getBalance(actor, state) } diff --git a/docs/guide/counter/plugins/counter/counter.go b/docs/guide/counter/plugins/counter/counter.go index 79394249ef..355594c43f 100644 --- a/docs/guide/counter/plugins/counter/counter.go +++ b/docs/guide/counter/plugins/counter/counter.go @@ -10,6 +10,7 @@ import ( "github.com/tendermint/basecoin/errors" "github.com/tendermint/basecoin/modules/coin" "github.com/tendermint/basecoin/stack" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" ) @@ -114,13 +115,13 @@ func (Handler) Name() string { func (Handler) AssertDispatcher() {} // CheckTx checks if the tx is properly structured -func (h Handler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, _ basecoin.Checker) (res basecoin.Result, err error) { +func (h Handler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, _ basecoin.Checker) (res basecoin.Result, err error) { _, err = checkTx(ctx, tx) return } // DeliverTx executes the tx if valid -func (h Handler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, dispatch basecoin.Deliver) (res basecoin.Result, err error) { +func (h Handler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, dispatch basecoin.Deliver) (res basecoin.Result, err error) { ctr, err := checkTx(ctx, tx) if err != nil { return res, err @@ -192,7 +193,7 @@ func StateKey() []byte { } // LoadState - retrieve the counter state from the store -func LoadState(store types.KVStore) (state State, err error) { +func LoadState(store state.KVStore) (state State, err error) { bytes := store.Get(StateKey()) if len(bytes) > 0 { err = wire.ReadBinaryBytes(bytes, &state) @@ -204,7 +205,7 @@ func LoadState(store types.KVStore) (state State, err error) { } // SaveState - save the counter state to the provided store -func SaveState(store types.KVStore, state State) error { +func SaveState(store state.KVStore, state State) error { bytes := wire.BinaryBytes(state) store.Set(StateKey(), bytes) return nil diff --git a/handler.go b/handler.go index 34404395b5..00fee085f7 100644 --- a/handler.go +++ b/handler.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/go-wire/data" "github.com/tendermint/tmlibs/log" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // Handler is anything that processes a transaction @@ -15,9 +15,9 @@ type Handler interface { SetOptioner Named // TODO: flesh these out as well - // InitChain(store types.KVStore, vals []*abci.Validator) - // BeginBlock(store types.KVStore, hash []byte, header *abci.Header) - // EndBlock(store types.KVStore, height uint64) abci.ResponseEndBlock + // InitChain(store state.KVStore, vals []*abci.Validator) + // BeginBlock(store state.KVStore, hash []byte, header *abci.Header) + // EndBlock(store state.KVStore, height uint64) abci.ResponseEndBlock } type Named interface { @@ -25,35 +25,35 @@ type Named interface { } type Checker interface { - CheckTx(ctx Context, store types.KVStore, tx Tx) (Result, error) + CheckTx(ctx Context, store state.KVStore, tx Tx) (Result, error) } // CheckerFunc (like http.HandlerFunc) is a shortcut for making wrapers -type CheckerFunc func(Context, types.KVStore, Tx) (Result, error) +type CheckerFunc func(Context, state.KVStore, Tx) (Result, error) -func (c CheckerFunc) CheckTx(ctx Context, store types.KVStore, tx Tx) (Result, error) { +func (c CheckerFunc) CheckTx(ctx Context, store state.KVStore, tx Tx) (Result, error) { return c(ctx, store, tx) } type Deliver interface { - DeliverTx(ctx Context, store types.KVStore, tx Tx) (Result, error) + DeliverTx(ctx Context, store state.KVStore, tx Tx) (Result, error) } // DeliverFunc (like http.HandlerFunc) is a shortcut for making wrapers -type DeliverFunc func(Context, types.KVStore, Tx) (Result, error) +type DeliverFunc func(Context, state.KVStore, Tx) (Result, error) -func (c DeliverFunc) DeliverTx(ctx Context, store types.KVStore, tx Tx) (Result, error) { +func (c DeliverFunc) DeliverTx(ctx Context, store state.KVStore, tx Tx) (Result, error) { return c(ctx, store, tx) } type SetOptioner interface { - SetOption(l log.Logger, store types.KVStore, module, key, value string) (string, error) + SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) } // SetOptionFunc (like http.HandlerFunc) is a shortcut for making wrapers -type SetOptionFunc func(log.Logger, types.KVStore, string, string, string) (string, error) +type SetOptionFunc func(log.Logger, state.KVStore, string, string, string) (string, error) -func (c SetOptionFunc) SetOption(l log.Logger, store types.KVStore, module, key, value string) (string, error) { +func (c SetOptionFunc) SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) { return c(l, store, module, key, value) } @@ -75,14 +75,14 @@ func (r Result) ToABCI() abci.Result { // holders type NopCheck struct{} -func (_ NopCheck) CheckTx(Context, types.KVStore, Tx) (r Result, e error) { return } +func (_ NopCheck) CheckTx(Context, state.KVStore, Tx) (r Result, e error) { return } type NopDeliver struct{} -func (_ NopDeliver) DeliverTx(Context, types.KVStore, Tx) (r Result, e error) { return } +func (_ NopDeliver) DeliverTx(Context, state.KVStore, Tx) (r Result, e error) { return } type NopOption struct{} -func (_ NopOption) SetOption(log.Logger, types.KVStore, string, string, string) (string, error) { +func (_ NopOption) SetOption(log.Logger, state.KVStore, string, string, string) (string, error) { return "", nil } diff --git a/modules/coin/handler.go b/modules/coin/handler.go index 44526bc9f3..3320c9b2fa 100644 --- a/modules/coin/handler.go +++ b/modules/coin/handler.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" "github.com/tendermint/basecoin/stack" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) //NameCoin - name space of the coin module @@ -35,7 +35,7 @@ func (Handler) Name() string { } // CheckTx checks if there is enough money in the account -func (h Handler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (h Handler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { send, err := checkTx(ctx, tx) if err != nil { return res, err @@ -54,7 +54,7 @@ func (h Handler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin. } // DeliverTx moves the money -func (h Handler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (h Handler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { send, err := checkTx(ctx, tx) if err != nil { return res, err @@ -82,7 +82,7 @@ func (h Handler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoi } // SetOption - sets the genesis account balance -func (h Handler) SetOption(l log.Logger, store types.KVStore, module, key, value string) (log string, err error) { +func (h Handler) SetOption(l log.Logger, store state.KVStore, module, key, value string) (log string, err error) { if module != NameCoin { return "", errors.ErrUnknownModule(module) } diff --git a/modules/coin/handler_test.go b/modules/coin/handler_test.go index b13d1bb59a..38a9fa2cfa 100644 --- a/modules/coin/handler_test.go +++ b/modules/coin/handler_test.go @@ -12,6 +12,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/stack" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" ) @@ -140,7 +141,7 @@ func TestDeliverTx(t *testing.T) { h := NewHandler() for i, tc := range cases { // setup the cases.... - store := types.NewMemKVStore() + store := state.NewMemKVStore() for _, m := range tc.init { acct := Account{Coins: m.coins} err := storeAccount(store, h.MakeKey(m.addr), acct) @@ -196,7 +197,7 @@ func TestSetOption(t *testing.T) { h := NewHandler() l := log.NewNopLogger() for i, tc := range cases { - store := types.NewMemKVStore() + store := state.NewMemKVStore() key := "account" // set the options diff --git a/modules/coin/store.go b/modules/coin/store.go index b5d14ca850..e779fa4db7 100644 --- a/modules/coin/store.go +++ b/modules/coin/store.go @@ -7,6 +7,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" ) @@ -27,7 +28,7 @@ func NewAccountant(prefix string) Accountant { } // GetAccount - Get account from store and address -func (a Accountant) GetAccount(store types.KVStore, addr basecoin.Actor) (Account, error) { +func (a Accountant) GetAccount(store state.KVStore, addr basecoin.Actor) (Account, error) { acct, err := loadAccount(store, a.MakeKey(addr)) // for empty accounts, don't return an error, but rather an empty account @@ -38,13 +39,13 @@ func (a Accountant) GetAccount(store types.KVStore, addr basecoin.Actor) (Accoun } // CheckCoins makes sure there are funds, but doesn't change anything -func (a Accountant) CheckCoins(store types.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (types.Coins, error) { +func (a Accountant) CheckCoins(store state.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (types.Coins, error) { acct, err := a.updateCoins(store, addr, coins, seq) return acct.Coins, err } // ChangeCoins changes the money, returns error if it would be negative -func (a Accountant) ChangeCoins(store types.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (types.Coins, error) { +func (a Accountant) ChangeCoins(store state.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (types.Coins, error) { acct, err := a.updateCoins(store, addr, coins, seq) if err != nil { return acct.Coins, err @@ -57,7 +58,7 @@ func (a Accountant) ChangeCoins(store types.KVStore, addr basecoin.Actor, coins // updateCoins will load the account, make all checks, and return the updated account. // // it doesn't save anything, that is up to you to decide (Check/Change Coins) -func (a Accountant) updateCoins(store types.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (acct Account, err error) { +func (a Accountant) updateCoins(store state.KVStore, addr basecoin.Actor, coins types.Coins, seq int) (acct Account, err error) { acct, err = loadAccount(store, a.MakeKey(addr)) // we can increase an empty account... if IsNoAccountErr(err) && coins.IsPositive() { @@ -101,7 +102,7 @@ type Account struct { Sequence int `json:"sequence"` } -func loadAccount(store types.KVStore, key []byte) (acct Account, err error) { +func loadAccount(store state.KVStore, key []byte) (acct Account, err error) { // fmt.Printf("load: %X\n", key) data := store.Get(key) if len(data) == 0 { @@ -115,7 +116,7 @@ func loadAccount(store types.KVStore, key []byte) (acct Account, err error) { return acct, nil } -func storeAccount(store types.KVStore, key []byte, acct Account) error { +func storeAccount(store state.KVStore, key []byte, acct Account) error { // fmt.Printf("store: %X\n", key) bin := wire.BinaryBytes(acct) store.Set(key, bin) diff --git a/modules/fee/handler.go b/modules/fee/handler.go index 7f4f579f07..25fb4f2b0c 100644 --- a/modules/fee/handler.go +++ b/modules/fee/handler.go @@ -4,6 +4,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" "github.com/tendermint/basecoin/stack" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/types" ) @@ -13,11 +14,11 @@ const NameFee = "fee" // AccountChecker - interface used by SimpleFeeHandler type AccountChecker interface { // Get amount checks the current amount - GetAmount(store types.KVStore, addr basecoin.Actor) (types.Coins, error) + GetAmount(store state.KVStore, addr basecoin.Actor) (types.Coins, error) // ChangeAmount modifies the balance by the given amount and returns the new balance // always returns an error if leading to negative balance - ChangeAmount(store types.KVStore, addr basecoin.Actor, coins types.Coins) (types.Coins, error) + ChangeAmount(store state.KVStore, addr basecoin.Actor, coins types.Coins) (types.Coins, error) } // SimpleFeeHandler - checker object for fee checking @@ -37,7 +38,7 @@ var _ stack.Middleware = SimpleFeeHandler{} // Yes, I know refactor a bit... really too late already // CheckTx - check the transaction -func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { feeTx, ok := tx.Unwrap().(*Fee) if !ok { return res, errors.ErrInvalidFormat(tx) @@ -61,7 +62,7 @@ func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx } // DeliverTx - send the fee handler transaction -func (h SimpleFeeHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +func (h SimpleFeeHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { feeTx, ok := tx.Unwrap().(*Fee) if !ok { return res, errors.ErrInvalidFormat(tx) diff --git a/plugins/ibc/ibc.go b/plugins/ibc/ibc.go index 06c3622e3a..3084ef7caf 100644 --- a/plugins/ibc/ibc.go +++ b/plugins/ibc/ibc.go @@ -72,7 +72,7 @@ package ibc // // GetSequenceNumber gets the sequence number for packets being sent from the src chain to the dst chain. // // The sequence number counts how many packets have been sent. // // The next packet must include the latest sequence number. -// func GetSequenceNumber(store types.KVStore, src, dst string) uint64 { +// func GetSequenceNumber(store state.KVStore, src, dst string) uint64 { // sequenceKey := toKey(_IBC, _EGRESS, src, dst) // seqBytes := store.Get(sequenceKey) // if seqBytes == nil { @@ -86,14 +86,14 @@ package ibc // } // // SetSequenceNumber sets the sequence number for packets being sent from the src chain to the dst chain -// func SetSequenceNumber(store types.KVStore, src, dst string, seq uint64) { +// func SetSequenceNumber(store state.KVStore, src, dst string, seq uint64) { // sequenceKey := toKey(_IBC, _EGRESS, src, dst) // store.Set(sequenceKey, []byte(strconv.FormatUint(seq, 10))) // } // // SaveNewIBCPacket creates an IBC packet with the given payload from the src chain to the dst chain // // using the correct sequence number. It also increments the sequence number by 1 -// func SaveNewIBCPacket(state types.KVStore, src, dst string, payload Payload) { +// func SaveNewIBCPacket(state state.KVStore, src, dst string, payload Payload) { // // fetch sequence number and increment by 1 // seq := GetSequenceNumber(state, src, dst) // SetSequenceNumber(state, src, dst, seq+1) @@ -104,7 +104,7 @@ package ibc // save(state, packetKey, packet) // } -// func GetIBCPacket(state types.KVStore, src, dst string, seq uint64) (Packet, error) { +// func GetIBCPacket(state state.KVStore, src, dst string, seq uint64) (Packet, error) { // packetKey := toKey(_IBC, _EGRESS, src, dst, cmn.Fmt("%v", seq)) // packetBytes := state.Get(packetKey) @@ -251,11 +251,11 @@ package ibc // return &IBCPlugin{} // } -// func (ibc *IBCPlugin) SetOption(store types.KVStore, key string, value string) (log string) { +// func (ibc *IBCPlugin) SetOption(store state.KVStore, key string, value string) (log string) { // return "" // } -// func (ibc *IBCPlugin) RunTx(store types.KVStore, ctx types.CallContext, txBytes []byte) (res abci.Result) { +// func (ibc *IBCPlugin) RunTx(store state.KVStore, ctx types.CallContext, txBytes []byte) (res abci.Result) { // // Decode tx // var tx IBCTx // err := wire.ReadBinaryBytes(txBytes, &tx) @@ -295,7 +295,7 @@ package ibc // } // type IBCStateMachine struct { -// store types.KVStore +// store state.KVStore // ctx types.CallContext // res abci.Result // } @@ -499,13 +499,13 @@ package ibc // return // } -// func (ibc *IBCPlugin) InitChain(store types.KVStore, vals []*abci.Validator) { +// func (ibc *IBCPlugin) InitChain(store state.KVStore, vals []*abci.Validator) { // } -// func (cp *IBCPlugin) BeginBlock(store types.KVStore, hash []byte, header *abci.Header) { +// func (cp *IBCPlugin) BeginBlock(store state.KVStore, hash []byte, header *abci.Header) { // } -// func (cp *IBCPlugin) EndBlock(store types.KVStore, height uint64) (res abci.ResponseEndBlock) { +// func (cp *IBCPlugin) EndBlock(store state.KVStore, height uint64) (res abci.ResponseEndBlock) { // return // } @@ -513,7 +513,7 @@ package ibc // // TODO: move to utils // // Returns true if exists, false if nil. -// func exists(store types.KVStore, key []byte) (exists bool) { +// func exists(store state.KVStore, key []byte) (exists bool) { // value := store.Get(key) // return len(value) > 0 // } @@ -521,7 +521,7 @@ package ibc // // Load bytes from store by reading value for key and read into ptr. // // Returns true if exists, false if nil. // // Returns err if decoding error. -// func load(store types.KVStore, key []byte, ptr interface{}) (exists bool, err error) { +// func load(store state.KVStore, key []byte, ptr interface{}) (exists bool, err error) { // value := store.Get(key) // if len(value) > 0 { // err = wire.ReadBinaryBytes(value, ptr) @@ -537,7 +537,7 @@ package ibc // } // // Save bytes to store by writing obj's go-wire binary bytes. -// func save(store types.KVStore, key []byte, obj interface{}) { +// func save(store state.KVStore, key []byte, obj interface{}) { // store.Set(key, wire.BinaryBytes(obj)) // } diff --git a/stack/chain.go b/stack/chain.go index e07e6dd688..47c9bd2002 100644 --- a/stack/chain.go +++ b/stack/chain.go @@ -3,8 +3,8 @@ package stack import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" - "github.com/tendermint/basecoin/types" ) const ( @@ -22,7 +22,7 @@ func (_ Chain) Name() string { var _ Middleware = Chain{} -func (c Chain) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +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 { return res, err @@ -30,7 +30,7 @@ func (c Chain) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx return next.CheckTx(ctx, store, stx) } -func (c Chain) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +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 { return res, err diff --git a/stack/chain_test.go b/stack/chain_test.go index cb1e39059e..1e799dbb90 100644 --- a/stack/chain_test.go +++ b/stack/chain_test.go @@ -9,8 +9,8 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" - "github.com/tendermint/basecoin/types" ) func TestChain(t *testing.T) { @@ -31,7 +31,7 @@ func TestChain(t *testing.T) { // generic args here... ctx := NewContext(chainID, log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() // build the stack ok := OKHandler{Log: msg} diff --git a/stack/context.go b/stack/context.go index 80ad743901..8953ee8656 100644 --- a/stack/context.go +++ b/stack/context.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // store nonce as it's own type so no one can even try to fake it @@ -115,7 +115,7 @@ func withApp(ctx basecoin.Context, app string) basecoin.Context { } func secureCheck(h basecoin.Checker, parent basecoin.Context) basecoin.Checker { - next := func(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { + next := func(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { if !parent.IsParent(ctx) { return res, errors.New("Passing in non-child Context") } @@ -125,7 +125,7 @@ func secureCheck(h basecoin.Checker, parent basecoin.Context) basecoin.Checker { } func secureDeliver(h basecoin.Deliver, parent basecoin.Context) basecoin.Deliver { - next := func(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { + next := func(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { if !parent.IsParent(ctx) { return res, errors.New("Passing in non-child Context") } diff --git a/stack/dispatcher.go b/stack/dispatcher.go index df065973d7..b8850b89b0 100644 --- a/stack/dispatcher.go +++ b/stack/dispatcher.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // nolint @@ -64,7 +64,7 @@ func (d *Dispatcher) Name() string { // 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) { +func (d *Dispatcher) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { r, err := d.lookupTx(tx) if err != nil { return res, err @@ -79,7 +79,7 @@ func (d *Dispatcher) CheckTx(ctx basecoin.Context, store types.KVStore, tx basec // 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) { +func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { r, err := d.lookupTx(tx) if err != nil { return res, err @@ -93,7 +93,7 @@ func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store types.KVStore, tx bas // // 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) { +func (d *Dispatcher) SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) { r, err := d.lookupModule(module) if err != nil { return "", err diff --git a/stack/helpers.go b/stack/helpers.go index 387a2ae96c..e3f284d194 100644 --- a/stack/helpers.go +++ b/stack/helpers.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/go-wire/data" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) const ( @@ -29,12 +29,12 @@ func (_ OKHandler) Name() string { } // CheckTx always returns an empty success tx -func (ok OKHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (ok OKHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { return basecoin.Result{Log: ok.Log}, nil } // DeliverTx always returns an empty success tx -func (ok OKHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (ok OKHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { return basecoin.Result{Log: ok.Log}, nil } @@ -50,13 +50,13 @@ func (_ EchoHandler) Name() string { } // CheckTx always returns an empty success tx -func (_ EchoHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (_ EchoHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { data, err := data.ToWire(tx) return basecoin.Result{Data: data}, err } // DeliverTx always returns an empty success tx -func (_ EchoHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (_ EchoHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { data, err := data.ToWire(tx) return basecoin.Result{Data: data}, err } @@ -74,12 +74,12 @@ func (_ FailHandler) Name() string { } // CheckTx always returns the given error -func (f FailHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (f FailHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { return res, errors.WithStack(f.Err) } // DeliverTx always returns the given error -func (f FailHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (f FailHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { return res, errors.WithStack(f.Err) } @@ -97,7 +97,7 @@ func (_ PanicHandler) Name() string { } // CheckTx always panics -func (p PanicHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (p PanicHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { if p.Err != nil { panic(p.Err) } @@ -105,7 +105,7 @@ func (p PanicHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx base } // DeliverTx always panics -func (p PanicHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (p PanicHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { if p.Err != nil { panic(p.Err) } diff --git a/stack/helpers_test.go b/stack/helpers_test.go index 8787bb6a6e..1105988f47 100644 --- a/stack/helpers_test.go +++ b/stack/helpers_test.go @@ -9,14 +9,14 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) func TestOK(t *testing.T) { assert := assert.New(t) ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() data := "this looks okay" tx := basecoin.Tx{} @@ -34,7 +34,7 @@ func TestFail(t *testing.T) { assert := assert.New(t) ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() msg := "big problem" tx := basecoin.Tx{} @@ -54,7 +54,7 @@ func TestPanic(t *testing.T) { assert := assert.New(t) ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() msg := "system crash!" tx := basecoin.Tx{} diff --git a/stack/helperware.go b/stack/helperware.go index 25c93f4e51..162b8e888d 100644 --- a/stack/helperware.go +++ b/stack/helperware.go @@ -3,7 +3,7 @@ package stack import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) const ( @@ -24,14 +24,14 @@ func (_ CheckMiddleware) Name() string { return NameCheck } -func (p CheckMiddleware) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +func (p CheckMiddleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { if !ctx.HasPermission(p.Required) { return res, errors.ErrUnauthorized() } return next.CheckTx(ctx, store, tx) } -func (p CheckMiddleware) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +func (p CheckMiddleware) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { if !ctx.HasPermission(p.Required) { return res, errors.ErrUnauthorized() } @@ -50,12 +50,12 @@ func (_ GrantMiddleware) Name() string { return NameGrant } -func (g GrantMiddleware) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +func (g GrantMiddleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { ctx = ctx.WithPermissions(g.Auth) return next.CheckTx(ctx, store, tx) } -func (g GrantMiddleware) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +func (g GrantMiddleware) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { ctx = ctx.WithPermissions(g.Auth) return next.DeliverTx(ctx, store, tx) } diff --git a/stack/interface.go b/stack/interface.go index 3b5b5d4e61..9d91f9a595 100644 --- a/stack/interface.go +++ b/stack/interface.go @@ -4,7 +4,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // Middleware is anything that wraps another handler to enhance functionality. @@ -19,57 +19,57 @@ type Middleware interface { } type CheckerMiddle interface { - CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) + CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) } -type CheckerMiddleFunc func(basecoin.Context, types.KVStore, basecoin.Tx, basecoin.Checker) (basecoin.Result, error) +type CheckerMiddleFunc func(basecoin.Context, state.KVStore, basecoin.Tx, basecoin.Checker) (basecoin.Result, error) -func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) { +func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) { return c(ctx, store, tx, next) } type DeliverMiddle interface { - DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) + DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) } -type DeliverMiddleFunc func(basecoin.Context, types.KVStore, basecoin.Tx, basecoin.Deliver) (basecoin.Result, error) +type DeliverMiddleFunc func(basecoin.Context, state.KVStore, basecoin.Tx, basecoin.Deliver) (basecoin.Result, error) -func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) { +func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) { return d(ctx, store, tx, next) } type SetOptionMiddle interface { - SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) + SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) } -type SetOptionMiddleFunc func(log.Logger, types.KVStore, string, string, string, basecoin.SetOptioner) (string, error) +type SetOptionMiddleFunc func(log.Logger, state.KVStore, string, string, string, basecoin.SetOptioner) (string, error) -func (c SetOptionMiddleFunc) SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { +func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { return c(l, store, module, key, value, next) } // holders type PassCheck struct{} -func (_ PassCheck) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) { +func (_ PassCheck) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) { return next.CheckTx(ctx, store, tx) } type PassDeliver struct{} -func (_ PassDeliver) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) { +func (_ PassDeliver) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) { return next.DeliverTx(ctx, store, tx) } type PassOption struct{} -func (_ PassOption) SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { +func (_ PassOption) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { return next.SetOption(l, store, module, key, value) } type NopOption struct{} -func (_ NopOption) SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { +func (_ NopOption) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { return "", nil } @@ -98,14 +98,14 @@ func (w wrapped) Name() string { return w.h.Name() } -func (w wrapped) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, _ basecoin.Checker) (basecoin.Result, error) { +func (w wrapped) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, _ basecoin.Checker) (basecoin.Result, error) { return w.h.CheckTx(ctx, store, tx) } -func (w wrapped) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, _ basecoin.Deliver) (basecoin.Result, error) { +func (w wrapped) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, _ basecoin.Deliver) (basecoin.Result, error) { return w.h.DeliverTx(ctx, store, tx) } -func (w wrapped) SetOption(l log.Logger, store types.KVStore, module, key, value string, _ basecoin.SetOptioner) (string, error) { +func (w wrapped) SetOption(l log.Logger, store state.KVStore, module, key, value string, _ basecoin.SetOptioner) (string, error) { return w.h.SetOption(l, store, module, key, value) } diff --git a/stack/logger.go b/stack/logger.go index 1f79ac3d36..aa8c1d5fff 100644 --- a/stack/logger.go +++ b/stack/logger.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) const ( @@ -22,7 +22,7 @@ func (_ Logger) Name() string { var _ Middleware = Logger{} -func (_ Logger) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +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 +36,7 @@ func (_ Logger) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.T return } -func (_ Logger) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +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 +50,7 @@ func (_ Logger) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin return } -func (_ Logger) SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) { +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/middleware.go b/stack/middleware.go index ed9c3beba0..0ae1926fb7 100644 --- a/stack/middleware.go +++ b/stack/middleware.go @@ -4,7 +4,7 @@ import ( "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // middleware lets us wrap a whole stack up into one Handler @@ -22,7 +22,7 @@ func (m *middleware) Name() string { } // CheckTx always returns an empty success tx -func (m *middleware) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (basecoin.Result, error) { +func (m *middleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (basecoin.Result, error) { // make sure we pass in proper context to child next := secureCheck(m.next, ctx) // set the permissions for this app @@ -31,7 +31,7 @@ func (m *middleware) CheckTx(ctx basecoin.Context, store types.KVStore, tx basec } // DeliverTx always returns an empty success tx -func (m *middleware) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { +func (m *middleware) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) { // make sure we pass in proper context to child next := secureDeliver(m.next, ctx) // set the permissions for this app @@ -39,7 +39,7 @@ func (m *middleware) DeliverTx(ctx basecoin.Context, store types.KVStore, tx bas return m.middleware.DeliverTx(ctx, store, tx, next) } -func (m *middleware) SetOption(l log.Logger, store types.KVStore, module, key, value string) (string, error) { +func (m *middleware) SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) { return m.middleware.SetOption(l, store, module, key, value, m.next) } diff --git a/stack/middleware_test.go b/stack/middleware_test.go index 4f88539191..2f8e48a84d 100644 --- a/stack/middleware_test.go +++ b/stack/middleware_test.go @@ -5,12 +5,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/txs" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/go-wire/data" "github.com/tendermint/tmlibs/log" + + "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/errors" + "github.com/tendermint/basecoin/state" + "github.com/tendermint/basecoin/txs" ) func TestPermissionSandbox(t *testing.T) { @@ -18,7 +20,7 @@ func TestPermissionSandbox(t *testing.T) { // generic args ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() raw := txs.NewRaw([]byte{1, 2, 3, 4}) rawBytes, err := data.ToWire(raw) require.Nil(err) diff --git a/stack/multiplexer.go b/stack/multiplexer.go index 2000551cb2..b306c7145e 100644 --- a/stack/multiplexer.go +++ b/stack/multiplexer.go @@ -3,11 +3,12 @@ package stack import ( "strings" - "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/txs" - "github.com/tendermint/basecoin/types" wire "github.com/tendermint/go-wire" "github.com/tendermint/go-wire/data" + + "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/state" + "github.com/tendermint/basecoin/txs" ) const ( @@ -24,21 +25,21 @@ func (_ Multiplexer) Name() string { var _ Middleware = Multiplexer{} -func (_ Multiplexer) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +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 types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +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) } return next.DeliverTx(ctx, store, tx) } -func runAll(ctx basecoin.Context, store types.KVStore, txs []basecoin.Tx, next basecoin.CheckerFunc) (res basecoin.Result, err error) { +func runAll(ctx basecoin.Context, store state.KVStore, txs []basecoin.Tx, next basecoin.CheckerFunc) (res basecoin.Result, err error) { // store all results, unless anything errors rs := make([]basecoin.Result, len(txs)) for i, stx := range txs { diff --git a/stack/recovery.go b/stack/recovery.go index be213ad878..eb03ee8026 100644 --- a/stack/recovery.go +++ b/stack/recovery.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) const ( @@ -23,7 +23,7 @@ func (_ Recovery) Name() string { var _ Middleware = Recovery{} -func (_ Recovery) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +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 +32,7 @@ func (_ Recovery) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin return next.CheckTx(ctx, store, tx) } -func (_ Recovery) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +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 +41,7 @@ func (_ Recovery) DeliverTx(ctx basecoin.Context, store types.KVStore, tx baseco return next.DeliverTx(ctx, store, tx) } -func (_ Recovery) SetOption(l log.Logger, store types.KVStore, module, key, value string, next basecoin.SetOptioner) (log string, err error) { +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 54fcbe6931..7044bdfa7e 100644 --- a/stack/recovery_test.go +++ b/stack/recovery_test.go @@ -6,9 +6,11 @@ import ( "testing" "github.com/stretchr/testify/assert" - "github.com/tendermint/basecoin" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/tmlibs/log" + + "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/state" ) func TestRecovery(t *testing.T) { @@ -16,7 +18,7 @@ func TestRecovery(t *testing.T) { // generic args here... ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() tx := basecoin.Tx{} cases := []struct { diff --git a/stack/signature.go b/stack/signature.go index d996f921a7..3edf22969c 100644 --- a/stack/signature.go +++ b/stack/signature.go @@ -5,7 +5,7 @@ import ( "github.com/tendermint/basecoin" "github.com/tendermint/basecoin/errors" - "github.com/tendermint/basecoin/types" + "github.com/tendermint/basecoin/state" ) // app name for auth @@ -33,7 +33,7 @@ type Signed interface { Signers() ([]crypto.PubKey, error) } -func (h Signatures) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) { +func (h 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 +42,7 @@ func (h Signatures) CheckTx(ctx basecoin.Context, store types.KVStore, tx baseco return next.CheckTx(ctx2, store, tnext) } -func (h Signatures) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) { +func (h 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/stack/signature_test.go index 0dbf1a6173..4f99849e09 100644 --- a/stack/signature_test.go +++ b/stack/signature_test.go @@ -5,12 +5,13 @@ import ( "testing" "github.com/stretchr/testify/assert" + crypto "github.com/tendermint/go-crypto" "github.com/tendermint/tmlibs/log" "github.com/tendermint/basecoin" + "github.com/tendermint/basecoin/state" "github.com/tendermint/basecoin/txs" - "github.com/tendermint/basecoin/types" ) func TestSignatureChecks(t *testing.T) { @@ -18,7 +19,7 @@ func TestSignatureChecks(t *testing.T) { // generic args ctx := NewContext("test-chain", log.NewNopLogger()) - store := types.NewMemKVStore() + store := state.NewMemKVStore() raw := txs.NewRaw([]byte{1, 2, 3, 4}) // let's make some keys.... diff --git a/types/kvstore.go b/state/kvstore.go similarity index 99% rename from types/kvstore.go rename to state/kvstore.go index a795d7dd1f..b07d57109f 100644 --- a/types/kvstore.go +++ b/state/kvstore.go @@ -1,4 +1,4 @@ -package types +package state import ( "container/list" diff --git a/types/kvstore_test.go b/state/kvstore_test.go similarity index 99% rename from types/kvstore_test.go rename to state/kvstore_test.go index 0b4afc7328..e4961c3606 100644 --- a/types/kvstore_test.go +++ b/state/kvstore_test.go @@ -1,4 +1,4 @@ -package types +package state import ( "bytes" diff --git a/state/state.go b/state/state.go index 36b5114d2e..398e18ca5e 100644 --- a/state/state.go +++ b/state/state.go @@ -2,7 +2,6 @@ package state import ( abci "github.com/tendermint/abci/types" - "github.com/tendermint/basecoin/types" eyes "github.com/tendermint/merkleeyes/client" "github.com/tendermint/tmlibs/log" ) @@ -11,13 +10,13 @@ import ( // See CacheWrap(). type State struct { chainID string - store types.KVStore + store KVStore readCache map[string][]byte // optional, for caching writes to store - writeCache *types.KVCache // optional, for caching writes w/o writing to store + writeCache *KVCache // optional, for caching writes w/o writing to store logger log.Logger } -func NewState(store types.KVStore, l log.Logger) *State { +func NewState(store KVStore, l log.Logger) *State { return &State{ chainID: "", store: store, @@ -58,7 +57,7 @@ func (s *State) Set(key []byte, value []byte) { } func (s *State) CacheWrap() *State { - cache := types.NewKVCache(s) + cache := NewKVCache(s) return &State{ chainID: s.chainID, store: cache, diff --git a/state/state_test.go b/state/state_test.go index 171790d4a7..8cc587b3b9 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -4,7 +4,6 @@ import ( "bytes" "testing" - "github.com/tendermint/basecoin/types" eyes "github.com/tendermint/merkleeyes/client" "github.com/tendermint/tmlibs/log" @@ -15,14 +14,14 @@ func TestState(t *testing.T) { assert := assert.New(t) //States and Stores for tests - store := types.NewMemKVStore() + store := NewMemKVStore() state := NewState(store, log.TestingLogger()) cache := state.CacheWrap() eyesCli := eyes.NewLocalClient("", 0) //reset the store/state/cache reset := func() { - store = types.NewMemKVStore() + store = NewMemKVStore() state = NewState(store, log.TestingLogger()) cache = state.CacheWrap() } @@ -43,14 +42,14 @@ func TestState(t *testing.T) { } //set the kvc to have all the key value pairs - setRecords := func(kv types.KVStore) { + setRecords := func(kv KVStore) { for _, n := range keyvalue { kv.Set([]byte(n.key), []byte(n.value)) } } //store has all the key value pairs - storeHasAll := func(kv types.KVStore) bool { + storeHasAll := func(kv KVStore) bool { for _, n := range keyvalue { if !bytes.Equal(kv.Get([]byte(n.key)), []byte(n.value)) { return false diff --git a/types/test_helpers.go b/types/test_helpers.go deleted file mode 100644 index 7bcccc11a5..0000000000 --- a/types/test_helpers.go +++ /dev/null @@ -1,105 +0,0 @@ -package types - -// // Helper functions for testing - -// import ( -// "github.com/tendermint/go-crypto" -// cmn "github.com/tendermint/tmlibs/common" -// ) - -// // Creates a PrivAccount from secret. -// // The amount is not set. -// func PrivAccountFromSecret(secret string) PrivAccount { -// privKey := -// crypto.GenPrivKeyEd25519FromSecret([]byte(secret)).Wrap() -// privAccount := PrivAccount{ -// PrivKey: privKey, -// Account: Account{ -// PubKey: privKey.PubKey(), -// }, -// } -// return privAccount -// } - -// // Make `num` random accounts -// func RandAccounts(num int, minAmount int64, maxAmount int64) []PrivAccount { -// privAccs := make([]PrivAccount, num) -// for i := 0; i < num; i++ { - -// balance := minAmount -// if maxAmount > minAmount { -// balance += cmn.RandInt64() % (maxAmount - minAmount) -// } - -// privKey := crypto.GenPrivKeyEd25519().Wrap() -// pubKey := privKey.PubKey() -// privAccs[i] = PrivAccount{ -// PrivKey: privKey, -// Account: Account{ -// PubKey: pubKey, -// Balance: Coins{Coin{"", balance}}, -// }, -// } -// } - -// return privAccs -// } - -// ///////////////////////////////////////////////////////////////// - -// //func MakeAccs(secrets ...string) (accs []PrivAccount) { -// // for _, secret := range secrets { -// // privAcc := PrivAccountFromSecret(secret) -// // privAcc.Account.Balance = Coins{{"mycoin", 7}} -// // accs = append(accs, privAcc) -// // } -// // return -// //} - -// func MakeAcc(secret string) PrivAccount { -// privAcc := PrivAccountFromSecret(secret) -// privAcc.Account.Balance = Coins{{"mycoin", 7}} -// return privAcc -// } - -// func Accs2TxInputs(seq int, accs ...PrivAccount) []TxInput { -// var txs []TxInput -// for _, acc := range accs { -// tx := NewTxInput( -// acc.Account.PubKey, -// Coins{{"mycoin", 5}}, -// seq) -// txs = append(txs, tx) -// } -// return txs -// } - -// //turn a list of accounts into basic list of transaction outputs -// func Accs2TxOutputs(accs ...PrivAccount) []TxOutput { -// var txs []TxOutput -// for _, acc := range accs { -// tx := TxOutput{ -// acc.Account.PubKey.Address(), -// Coins{{"mycoin", 4}}} -// txs = append(txs, tx) -// } -// return txs -// } - -// func MakeSendTx(seq int, accOut PrivAccount, accsIn ...PrivAccount) *SendTx { -// tx := &SendTx{ -// Gas: 0, -// Fee: Coin{"mycoin", 1}, -// Inputs: Accs2TxInputs(seq, accsIn...), -// Outputs: Accs2TxOutputs(accOut), -// } - -// return tx -// } - -// func SignTx(chainID string, tx *SendTx, accs ...PrivAccount) { -// signBytes := tx.SignBytes(chainID) -// for i, _ := range tx.Inputs { -// tx.Inputs[i].Signature = accs[i].Sign(signBytes) -// } -// }