72 lines
1.7 KiB
Go
Raw Normal View History

2016-02-14 14:59:53 -08:00
package dummy
2015-11-02 07:39:53 -08:00
import (
2016-02-08 13:47:47 -08:00
"strings"
2017-01-15 14:43:16 -08:00
"github.com/tendermint/abci/types"
"github.com/tendermint/merkleeyes/iavl"
2017-04-21 18:25:13 -04:00
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
2015-11-02 07:39:53 -08:00
)
type DummyApplication struct {
2017-02-13 18:48:59 -05:00
types.BaseApplication
state merkle.Tree
2015-11-02 07:39:53 -08:00
}
func NewDummyApplication() *DummyApplication {
state := iavl.NewIAVLTree(0, nil)
return &DummyApplication{state: state}
}
2017-09-22 11:10:39 -04:00
func (app *DummyApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) {
2017-03-03 18:39:10 -05:00
return types.ResponseInfo{Data: cmn.Fmt("{\"size\":%v}", app.state.Size())}
}
2016-07-01 20:22:58 -04:00
// tx is either "key=value" or just arbitrary bytes
2017-01-12 15:27:08 -05:00
func (app *DummyApplication) DeliverTx(tx []byte) types.Result {
2016-02-08 13:47:47 -08:00
parts := strings.Split(string(tx), "=")
if len(parts) == 2 {
app.state.Set([]byte(parts[0]), []byte(parts[1]))
} else {
app.state.Set(tx, tx)
}
2016-03-23 02:50:29 -07:00
return types.OK
2015-11-02 07:39:53 -08:00
}
func (app *DummyApplication) CheckTx(tx []byte) types.Result {
2016-03-23 02:50:29 -07:00
return types.OK
2015-11-02 07:39:53 -08:00
}
2016-03-23 02:50:29 -07:00
func (app *DummyApplication) Commit() types.Result {
hash := app.state.Hash()
return types.NewResultOK(hash, "")
2016-01-18 14:37:42 -08:00
}
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
}
2015-11-02 07:39:53 -08:00
}