Ported everything to SimpleDB interface
This commit is contained in:
+6
-6
@@ -25,27 +25,27 @@ func (Checkpoint) Name() string {
|
||||
var _ Middleware = Checkpoint{}
|
||||
|
||||
// CheckTx reverts all data changes if there was an error
|
||||
func (c Checkpoint) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
func (c Checkpoint) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
if !c.OnCheck {
|
||||
return next.CheckTx(ctx, store, tx)
|
||||
}
|
||||
ps := state.NewKVCache(unwrap(store))
|
||||
ps := store.Checkpoint()
|
||||
res, err = next.CheckTx(ctx, ps, tx)
|
||||
if err == nil {
|
||||
ps.Sync()
|
||||
err = store.Commit(ps)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// DeliverTx reverts all data changes if there was an error
|
||||
func (c Checkpoint) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
func (c Checkpoint) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
if !c.OnDeliver {
|
||||
return next.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
ps := state.NewKVCache(unwrap(store))
|
||||
ps := store.Checkpoint()
|
||||
res, err = next.DeliverTx(ctx, ps, tx)
|
||||
if err == nil {
|
||||
ps.Sync()
|
||||
err = store.Commit(ps)
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
+2
-2
@@ -76,7 +76,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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
next := func(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
if !parent.IsParent(ctx) {
|
||||
return res, errors.New("Passing in non-child Context")
|
||||
}
|
||||
@@ -86,7 +86,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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
next := func(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
if !parent.IsParent(ctx) {
|
||||
return res, errors.New("Passing in non-child Context")
|
||||
}
|
||||
|
||||
+3
-3
@@ -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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (d *Dispatcher) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
r, err := d.lookupTx(tx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -85,7 +85,7 @@ func (d *Dispatcher) CheckTx(ctx basecoin.Context, store state.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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
r, err := d.lookupTx(tx)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -105,7 +105,7 @@ func (d *Dispatcher) DeliverTx(ctx basecoin.Context, store state.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 state.KVStore, module, key, value string) (string, error) {
|
||||
func (d *Dispatcher) SetOption(l log.Logger, store state.SimpleDB, module, key, value string) (string, error) {
|
||||
r, err := d.lookupModule(module)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
+10
-10
@@ -86,12 +86,12 @@ func (OKHandler) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx always returns an empty success tx
|
||||
func (ok OKHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (ok OKHandler) CheckTx(ctx basecoin.Context, store state.SimpleDB, 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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (ok OKHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
return basecoin.Result{Log: ok.Log}, nil
|
||||
}
|
||||
|
||||
@@ -108,13 +108,13 @@ func (EchoHandler) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx always returns an empty success tx
|
||||
func (EchoHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (EchoHandler) CheckTx(ctx basecoin.Context, store state.SimpleDB, 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 state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (EchoHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
data, err := data.ToWire(tx)
|
||||
return basecoin.Result{Data: data}, err
|
||||
}
|
||||
@@ -133,12 +133,12 @@ func (FailHandler) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx always returns the given error
|
||||
func (f FailHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (f FailHandler) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
return res, errors.Wrap(f.Err)
|
||||
}
|
||||
|
||||
// DeliverTx always returns the given error
|
||||
func (f FailHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (f FailHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
return res, errors.Wrap(f.Err)
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func (PanicHandler) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx always panics
|
||||
func (p PanicHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (p PanicHandler) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
if p.Err != nil {
|
||||
panic(p.Err)
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (p PanicHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx base
|
||||
}
|
||||
|
||||
// DeliverTx always panics
|
||||
func (p PanicHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (p PanicHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
if p.Err != nil {
|
||||
panic(p.Err)
|
||||
}
|
||||
@@ -185,7 +185,7 @@ func (CheckHandler) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx verifies the permissions
|
||||
func (c CheckHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (c CheckHandler) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
check, ok := tx.Unwrap().(CheckTx)
|
||||
if !ok {
|
||||
return res, errors.ErrUnknownTxType(tx)
|
||||
@@ -200,7 +200,7 @@ func (c CheckHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx base
|
||||
}
|
||||
|
||||
// DeliverTx verifies the permissions
|
||||
func (c CheckHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (c CheckHandler) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
// until something changes, just do the same as check
|
||||
return c.CheckTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
+4
-4
@@ -25,14 +25,14 @@ func (_ CheckMiddleware) Name() string {
|
||||
return NameCheck
|
||||
}
|
||||
|
||||
func (p CheckMiddleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
func (p CheckMiddleware) CheckTx(ctx basecoin.Context, store state.SimpleDB, 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 state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
func (p CheckMiddleware) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
if !ctx.HasPermission(p.Required) {
|
||||
return res, errors.ErrUnauthorized()
|
||||
}
|
||||
@@ -51,12 +51,12 @@ func (_ GrantMiddleware) Name() string {
|
||||
return NameGrant
|
||||
}
|
||||
|
||||
func (g GrantMiddleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
func (g GrantMiddleware) CheckTx(ctx basecoin.Context, store state.SimpleDB, 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 state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
func (g GrantMiddleware) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
ctx = ctx.WithPermissions(g.Auth)
|
||||
return next.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
+16
-16
@@ -20,40 +20,40 @@ type Middleware interface {
|
||||
}
|
||||
|
||||
type CheckerMiddle interface {
|
||||
CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error)
|
||||
}
|
||||
|
||||
type CheckerMiddleFunc func(basecoin.Context, state.KVStore,
|
||||
type CheckerMiddleFunc func(basecoin.Context, state.SimpleDB,
|
||||
basecoin.Tx, basecoin.Checker) (basecoin.Result, error)
|
||||
|
||||
func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
return c(ctx, store, tx, next)
|
||||
}
|
||||
|
||||
type DeliverMiddle interface {
|
||||
DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx,
|
||||
DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx,
|
||||
next basecoin.Deliver) (basecoin.Result, error)
|
||||
}
|
||||
|
||||
type DeliverMiddleFunc func(basecoin.Context, state.KVStore,
|
||||
type DeliverMiddleFunc func(basecoin.Context, state.SimpleDB,
|
||||
basecoin.Tx, basecoin.Deliver) (basecoin.Result, error)
|
||||
|
||||
func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
return d(ctx, store, tx, next)
|
||||
}
|
||||
|
||||
type SetOptionMiddle interface {
|
||||
SetOption(l log.Logger, store state.KVStore, module,
|
||||
SetOption(l log.Logger, store state.SimpleDB, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error)
|
||||
}
|
||||
|
||||
type SetOptionMiddleFunc func(log.Logger, state.KVStore,
|
||||
type SetOptionMiddleFunc func(log.Logger, state.SimpleDB,
|
||||
string, string, string, basecoin.SetOptioner) (string, error)
|
||||
|
||||
func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.KVStore,
|
||||
func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.SimpleDB,
|
||||
module, key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
return c(l, store, module, key, value, next)
|
||||
}
|
||||
@@ -61,28 +61,28 @@ func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.KVStore,
|
||||
// holders
|
||||
type PassCheck struct{}
|
||||
|
||||
func (_ PassCheck) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (_ PassCheck) CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
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 state.KVStore,
|
||||
func (_ PassDeliver) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
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 state.KVStore, module,
|
||||
func (_ PassOption) SetOption(l log.Logger, store state.SimpleDB, 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 state.KVStore, module,
|
||||
func (_ NopOption) SetOption(l log.Logger, store state.SimpleDB, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
@@ -112,17 +112,17 @@ func (w wrapped) Name() string {
|
||||
return w.h.Name()
|
||||
}
|
||||
|
||||
func (w wrapped) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w wrapped) CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, _ basecoin.Checker) (basecoin.Result, error) {
|
||||
return w.h.CheckTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w wrapped) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w wrapped) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, _ basecoin.Deliver) (basecoin.Result, error) {
|
||||
return w.h.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w wrapped) SetOption(l log.Logger, store state.KVStore,
|
||||
func (w wrapped) SetOption(l log.Logger, store state.SimpleDB,
|
||||
module, key, value string, _ basecoin.SetOptioner) (string, error) {
|
||||
return w.h.SetOption(l, store, module, key, value)
|
||||
}
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ func (m *middleware) Name() string {
|
||||
}
|
||||
|
||||
// CheckTx always returns an empty success tx
|
||||
func (m *middleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (basecoin.Result, error) {
|
||||
func (m *middleware) CheckTx(ctx basecoin.Context, store state.SimpleDB, 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
|
||||
@@ -33,7 +33,7 @@ func (m *middleware) CheckTx(ctx basecoin.Context, store state.KVStore, tx basec
|
||||
}
|
||||
|
||||
// DeliverTx always returns an empty success tx
|
||||
func (m *middleware) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (m *middleware) DeliverTx(ctx basecoin.Context, store state.SimpleDB, 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
|
||||
@@ -43,7 +43,7 @@ func (m *middleware) DeliverTx(ctx basecoin.Context, store state.KVStore, tx bas
|
||||
return m.middleware.DeliverTx(ctx, store, tx, next)
|
||||
}
|
||||
|
||||
func (m *middleware) SetOption(l log.Logger, store state.KVStore, module, key, value string) (string, error) {
|
||||
func (m *middleware) SetOption(l log.Logger, store state.SimpleDB, module, key, value string) (string, error) {
|
||||
// set the namespace for the app
|
||||
store = stateSpace(store, m.Name())
|
||||
|
||||
|
||||
+78
-6
@@ -1,13 +1,18 @@
|
||||
package stack
|
||||
|
||||
import "github.com/tendermint/basecoin/state"
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
|
||||
"github.com/tendermint/basecoin/state"
|
||||
)
|
||||
|
||||
type prefixStore struct {
|
||||
prefix []byte
|
||||
store state.KVStore
|
||||
store state.SimpleDB
|
||||
}
|
||||
|
||||
var _ state.KVStore = prefixStore{}
|
||||
var _ state.SimpleDB = prefixStore{}
|
||||
|
||||
func (p prefixStore) Set(key, value []byte) {
|
||||
key = append(p.prefix, key...)
|
||||
@@ -19,11 +24,78 @@ func (p prefixStore) Get(key []byte) (value []byte) {
|
||||
return p.store.Get(key)
|
||||
}
|
||||
|
||||
func (p prefixStore) Has(key []byte) bool {
|
||||
key = append(p.prefix, key...)
|
||||
return p.store.Has(key)
|
||||
}
|
||||
|
||||
func (p prefixStore) Remove(key []byte) (value []byte) {
|
||||
key = append(p.prefix, key...)
|
||||
return p.store.Remove(key)
|
||||
}
|
||||
|
||||
func (p prefixStore) List(start, end []byte, limit int) []state.Model {
|
||||
start = append(p.prefix, start...)
|
||||
end = append(p.prefix, end...)
|
||||
res := p.store.List(start, end, limit)
|
||||
|
||||
trim := len(p.prefix)
|
||||
for i := range res {
|
||||
res[i].Key = res[i].Key[trim:]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (p prefixStore) First(start, end []byte) state.Model {
|
||||
start = append(p.prefix, start...)
|
||||
end = append(p.prefix, end...)
|
||||
res := p.store.First(start, end)
|
||||
if len(res.Key) > 0 {
|
||||
res.Key = res.Key[len(p.prefix):]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (p prefixStore) Last(start, end []byte) state.Model {
|
||||
start = append(p.prefix, start...)
|
||||
end = append(p.prefix, end...)
|
||||
res := p.store.Last(start, end)
|
||||
if len(res.Key) > 0 {
|
||||
res.Key = res.Key[len(p.prefix):]
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (p prefixStore) Checkpoint() state.SimpleDB {
|
||||
return prefixStore{
|
||||
prefix: p.prefix,
|
||||
store: p.store.Checkpoint(),
|
||||
}
|
||||
}
|
||||
|
||||
func (p prefixStore) Commit(sub state.SimpleDB) error {
|
||||
ps, ok := sub.(prefixStore)
|
||||
if !ok {
|
||||
return errors.New("Must commit prefixStore")
|
||||
}
|
||||
if !bytes.Equal(ps.prefix, p.prefix) {
|
||||
return errors.New("Cannot commit sub-tx with different prefix")
|
||||
}
|
||||
|
||||
// commit the wrapped data, don't worry about the prefix here
|
||||
p.store.Commit(ps)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p prefixStore) Discard() {
|
||||
p.store.Discard()
|
||||
}
|
||||
|
||||
// stateSpace will unwrap any prefixStore and then add the prefix
|
||||
//
|
||||
// this can be used by the middleware and dispatcher to isolate one space,
|
||||
// then unwrap and isolate another space
|
||||
func stateSpace(store state.KVStore, app string) state.KVStore {
|
||||
func stateSpace(store state.SimpleDB, app string) state.SimpleDB {
|
||||
// unwrap one-level if wrapped
|
||||
if pstore, ok := store.(prefixStore); ok {
|
||||
store = pstore.store
|
||||
@@ -31,7 +103,7 @@ func stateSpace(store state.KVStore, app string) state.KVStore {
|
||||
return PrefixedStore(app, store)
|
||||
}
|
||||
|
||||
func unwrap(store state.KVStore) state.KVStore {
|
||||
func unwrap(store state.SimpleDB) state.SimpleDB {
|
||||
// unwrap one-level if wrapped
|
||||
if pstore, ok := store.(prefixStore); ok {
|
||||
store = pstore.store
|
||||
@@ -45,7 +117,7 @@ func unwrap(store state.KVStore) state.KVStore {
|
||||
// This is useful for tests or utilities that have access to the global
|
||||
// state to check individual app spaces. Individual apps should not be able
|
||||
// to use this to read each other's space
|
||||
func PrefixedStore(app string, store state.KVStore) state.KVStore {
|
||||
func PrefixedStore(app string, store state.SimpleDB) state.SimpleDB {
|
||||
prefix := append([]byte(app), byte(0))
|
||||
return prefixStore{prefix, store}
|
||||
}
|
||||
|
||||
+3
-3
@@ -26,7 +26,7 @@ func (Recovery) Name() string {
|
||||
var _ Middleware = Recovery{}
|
||||
|
||||
// CheckTx catches any panic and converts to error - fulfills Middlware interface
|
||||
func (Recovery) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
func (Recovery) CheckTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = normalizePanic(r)
|
||||
@@ -36,7 +36,7 @@ func (Recovery) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.T
|
||||
}
|
||||
|
||||
// DeliverTx catches any panic and converts to error - fulfills Middlware interface
|
||||
func (Recovery) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
func (Recovery) DeliverTx(ctx basecoin.Context, store state.SimpleDB, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = normalizePanic(r)
|
||||
@@ -46,7 +46,7 @@ func (Recovery) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin
|
||||
}
|
||||
|
||||
// SetOption catches any panic and converts to error - fulfills Middlware interface
|
||||
func (Recovery) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (log string, err error) {
|
||||
func (Recovery) SetOption(l log.Logger, store state.SimpleDB, module, key, value string, next basecoin.SetOptioner) (log string, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = normalizePanic(r)
|
||||
|
||||
@@ -23,19 +23,19 @@ var _ Middleware = writerMid{}
|
||||
|
||||
func (w writerMid) Name() string { return w.name }
|
||||
|
||||
func (w writerMid) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w writerMid) CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
store.Set(w.key, w.value)
|
||||
return next.CheckTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w writerMid) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w writerMid) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
store.Set(w.key, w.value)
|
||||
return next.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w writerMid) SetOption(l log.Logger, store state.KVStore, module,
|
||||
func (w writerMid) SetOption(l log.Logger, store state.SimpleDB, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
store.Set([]byte(key), []byte(value))
|
||||
return next.SetOption(l, store, module, key, value)
|
||||
@@ -51,19 +51,19 @@ var _ basecoin.Handler = writerHand{}
|
||||
|
||||
func (w writerHand) Name() string { return w.name }
|
||||
|
||||
func (w writerHand) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w writerHand) CheckTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx) (basecoin.Result, error) {
|
||||
store.Set(w.key, w.value)
|
||||
return basecoin.Result{}, nil
|
||||
}
|
||||
|
||||
func (w writerHand) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
func (w writerHand) DeliverTx(ctx basecoin.Context, store state.SimpleDB,
|
||||
tx basecoin.Tx) (basecoin.Result, error) {
|
||||
store.Set(w.key, w.value)
|
||||
return basecoin.Result{}, nil
|
||||
}
|
||||
|
||||
func (w writerHand) SetOption(l log.Logger, store state.KVStore, module,
|
||||
func (w writerHand) SetOption(l log.Logger, store state.SimpleDB, module,
|
||||
key, value string) (string, error) {
|
||||
store.Set([]byte(key), []byte(value))
|
||||
return "Success", nil
|
||||
|
||||
Reference in New Issue
Block a user