6 "github.com/tendermint/abci/types"
7 wire "github.com/tendermint/go-wire"
8 "github.com/tendermint/iavl"
9 cmn "github.com/tendermint/tmlibs/common"
10 dbm "github.com/tendermint/tmlibs/db"
13 type DummyApplication struct {
16 state *iavl.VersionedTree
19 func NewDummyApplication() *DummyApplication {
20 state := iavl.NewVersionedTree(0, dbm.NewMemDB())
21 return &DummyApplication{state: state}
24 func (app *DummyApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) {
25 return types.ResponseInfo{Data: cmn.Fmt("{\"size\":%v}", app.state.Size())}
28 // tx is either "key=value" or just arbitrary bytes
29 func (app *DummyApplication) DeliverTx(tx []byte) types.Result {
30 parts := strings.Split(string(tx), "=")
32 app.state.Set([]byte(parts[0]), []byte(parts[1]))
39 func (app *DummyApplication) CheckTx(tx []byte) types.Result {
43 func (app *DummyApplication) Commit() types.Result {
48 if app.state.Size() > 0 {
49 // just add one more to height (kind of arbitrarily stupid)
50 height := app.state.LatestVersion() + 1
51 hash, err = app.state.SaveVersion(height)
53 // if this wasn't a dummy app, we'd do something smarter
58 return types.NewResultOK(hash, "")
61 func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
63 value, proof, err := app.state.GetWithProof(reqQuery.Data)
64 // if this wasn't a dummy app, we'd do something smarter
68 resQuery.Index = -1 // TODO make Proof return index
69 resQuery.Key = reqQuery.Data
70 resQuery.Value = value
71 resQuery.Proof = wire.BinaryBytes(proof)
73 resQuery.Log = "exists"
75 resQuery.Log = "does not exist"
79 index, value := app.state.Get(reqQuery.Data)
80 resQuery.Index = int64(index)
81 resQuery.Value = value
83 resQuery.Log = "exists"
85 resQuery.Log = "does not exist"