2016-02-14 14:59:53 -08:00
|
|
|
package dummy
|
2015-11-02 07:39:53 -08:00
|
|
|
|
|
|
|
import (
|
2017-01-16 22:59:46 -08:00
|
|
|
"fmt"
|
2016-02-08 13:47:47 -08:00
|
|
|
"strings"
|
|
|
|
|
2017-01-15 14:43:16 -08:00
|
|
|
"github.com/tendermint/abci/types"
|
2015-11-02 07:39:53 -08:00
|
|
|
"github.com/tendermint/go-merkle"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DummyApplication struct {
|
2015-11-29 14:22:30 -08:00
|
|
|
state merkle.Tree
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewDummyApplication() *DummyApplication {
|
2016-12-06 02:15:32 -08:00
|
|
|
state := merkle.NewIAVLTree(0, nil)
|
2015-11-29 14:22:30 -08:00
|
|
|
return &DummyApplication{state: state}
|
|
|
|
}
|
|
|
|
|
2016-12-26 17:44:36 -08:00
|
|
|
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
|
2017-01-16 22:59:46 -08:00
|
|
|
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2016-01-25 08:01:18 -08:00
|
|
|
func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
|
|
|
return ""
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-20 17:10:13 -07: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
|
|
|
}
|
|
|
|
|
2017-01-23 23:42:09 -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
|
2017-01-10 17:06:51 +01:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
2017-02-06 19:08:37 -05:00
|
|
|
|
|
|
|
func (app *DummyApplication) InitChain(validators []*types.Validator) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *DummyApplication) BeginBlock(hash []byte, header *types.Header) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (app *DummyApplication) EndBlock(height uint64) types.ResponseEndBlock {
|
|
|
|
return types.ResponseEndBlock{}
|
|
|
|
}
|