Move kvstore from types to state

This commit is contained in:
Ethan Frey 2017-07-06 14:23:38 +02:00
parent 56e61c9431
commit 49357a3574
29 changed files with 150 additions and 246 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
package types
package state
import (
"container/list"

View File

@ -1,4 +1,4 @@
package types
package state
import (
"bytes"

View File

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

View File

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

View File

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