61 lines
1.4 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"
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
"github.com/tendermint/tmsp/types"
)
type DummyApplication struct {
state merkle.Tree
2015-11-02 07:39:53 -08:00
}
func NewDummyApplication() *DummyApplication {
2016-11-22 20:44:41 -05:00
state := merkle.NewIAVLTree(0, ".", nil)
return &DummyApplication{state: state}
}
func (app *DummyApplication) Info() (string, *types.TMSPInfo, *types.LastBlockInfo, *types.ConfigInfo) {
return Fmt("size:%v", app.state.Size()), nil, nil, nil
}
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
func (app *DummyApplication) AppendTx(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)
2016-08-24 01:42:57 -04:00
2016-11-21 23:42:42 -05:00
queryResult := QueryResult{index, string(value), exists}
return types.NewResultOK(wire.JSONBytes(queryResult), "")
}
type QueryResult struct {
Index int `json:"index"`
Value string `json:"value"`
Exists bool `json:"exists"`
2015-11-02 07:39:53 -08:00
}