package dummy import ( "strings" "github.com/tendermint/abci/types" "github.com/tendermint/merkleeyes/iavl" cmn "github.com/tendermint/tmlibs/common" "github.com/tendermint/tmlibs/merkle" ) type DummyApplication struct { types.BaseApplication state merkle.Tree } func NewDummyApplication() *DummyApplication { state := iavl.NewIAVLTree(0, nil) return &DummyApplication{state: state} } func (app *DummyApplication) Info() (resInfo types.ResponseInfo) { return types.ResponseInfo{Data: cmn.Fmt("{\"size\":%v}", app.state.Size())} } // tx is either "key=value" or just arbitrary bytes func (app *DummyApplication) DeliverTx(tx []byte) types.Result { parts := strings.Split(string(tx), "=") if len(parts) == 2 { app.state.Set([]byte(parts[0]), []byte(parts[1])) } else { app.state.Set(tx, tx) } return types.OK } func (app *DummyApplication) CheckTx(tx []byte) types.Result { return types.OK } func (app *DummyApplication) Commit() types.Result { hash := app.state.Hash() return types.NewResultOK(hash, "") } func (app *DummyApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) { if reqQuery.Prove { value, proof, exists := app.state.Proof(reqQuery.Data) resQuery.Index = -1 // TODO make Proof return index resQuery.Key = reqQuery.Data resQuery.Value = value resQuery.Proof = proof if exists { resQuery.Log = "exists" } else { resQuery.Log = "does not exist" } return } else { index, value, exists := app.state.Get(reqQuery.Data) resQuery.Index = int64(index) resQuery.Value = value if exists { resQuery.Log = "exists" } else { resQuery.Log = "does not exist" } return } }