66 lines
1.6 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 (
"encoding/hex"
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-common"
"github.com/tendermint/go-merkle"
2016-11-21 23:42:42 -05:00
"github.com/tendermint/go-wire"
2015-11-02 07:39:53 -08:00
)
type DummyApplication struct {
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)
return &DummyApplication{state: state}
}
2016-12-26 17:44:36 -08:00
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
return types.ResponseInfo{Data: Fmt("{\"size\":%v}", app.state.Size())}
}
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
}
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(query []byte) types.Result {
2016-02-08 13:47:47 -08:00
index, value, exists := app.state.Get(query)
queryResult := QueryResult{index, string(value), hex.EncodeToString(value), exists}
2016-11-21 23:42:42 -05:00
return types.NewResultOK(wire.JSONBytes(queryResult), "")
}
2017-01-10 15:59:29 +01:00
func (app *DummyApplication) Proof(key []byte, blockHeight int64) types.Result {
2017-01-10 15:49:26 +01:00
return types.NewResultOK(nil, Fmt("TODO: support proof!"))
}
2016-11-21 23:42:42 -05:00
type QueryResult struct {
Index int `json:"index"`
Value string `json:"value"`
ValueHex string `json:"valueHex"`
Exists bool `json:"exists"`
2015-11-02 07:39:53 -08:00
}