Pull in logic from merkleeyes, get it all working with trees

This commit is contained in:
Ethan Frey
2017-07-27 15:31:32 -04:00
parent 5272ca5831
commit f6e7d4b741
12 changed files with 454 additions and 249 deletions
+43
View File
@@ -0,0 +1,43 @@
package stack
import (
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/state"
)
//nolint
const (
NameCheckpoint = "check"
)
// Checkpoint isolates all data store below this
type Checkpoint struct {
PassOption
}
// Name of the module - fulfills Middleware interface
func (Checkpoint) Name() string {
return NameCheckpoint
}
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) {
ps := state.NewKVCache(unwrap(store))
res, err = next.CheckTx(ctx, ps, tx)
if err == nil {
ps.Sync()
}
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) {
ps := state.NewKVCache(unwrap(store))
res, err = next.DeliverTx(ctx, ps, tx)
if err == nil {
ps.Sync()
}
return res, err
}
+8
View File
@@ -31,6 +31,14 @@ func stateSpace(store state.KVStore, app string) state.KVStore {
return PrefixedStore(app, store)
}
func unwrap(store state.KVStore) state.KVStore {
// unwrap one-level if wrapped
if pstore, ok := store.(prefixStore); ok {
store = pstore.store
}
return store
}
// PrefixedStore allows one to create an isolated state-space for a given
// app prefix, but it cannot easily be unwrapped
//