tendermint/example/golang/dummy.go

55 lines
1.3 KiB
Go
Raw Normal View History

2015-11-27 15:42:00 -08:00
package example
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"
"github.com/tendermint/tmsp/types"
)
type DummyApplication struct {
state merkle.Tree
2015-11-02 07:39:53 -08:00
}
func NewDummyApplication() *DummyApplication {
state := merkle.NewIAVLTree(
0,
nil,
)
return &DummyApplication{state: state}
}
func (app *DummyApplication) Info() string {
return 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
}
func (app *DummyApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
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)
}
return types.CodeType_OK, nil, ""
2015-11-02 07:39:53 -08:00
}
func (app *DummyApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
return types.CodeType_OK, nil, ""
2015-11-02 07:39:53 -08:00
}
func (app *DummyApplication) GetHash() (hash []byte, log string) {
hash = app.state.Hash()
return hash, ""
2016-01-18 14:37:42 -08:00
}
func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
2016-02-08 13:47:47 -08:00
index, value, exists := app.state.Get(query)
resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
return types.CodeType_OK, []byte(resStr), ""
2015-11-02 07:39:53 -08:00
}