mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-23 19:31:18 +00:00
83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package dummy
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/tendermint/abci/types"
|
|
"github.com/tendermint/go-merkle"
|
|
)
|
|
|
|
type DummyApplication struct {
|
|
state merkle.Tree
|
|
}
|
|
|
|
func NewDummyApplication() *DummyApplication {
|
|
state := merkle.NewIAVLTree(0, nil)
|
|
return &DummyApplication{state: state}
|
|
}
|
|
|
|
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
|
|
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
|
|
}
|
|
|
|
func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
|
return ""
|
|
}
|
|
|
|
// tx is either "key=value" or just arbitrary bytes
|
|
func (app *DummyApplication) DeliverTx(tx []byte) types.Result {
|
|
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.OK
|
|
}
|
|
|
|
func (app *DummyApplication) CheckTx(tx []byte) types.Result {
|
|
return types.OK
|
|
}
|
|
|
|
func (app *DummyApplication) Commit() types.Result {
|
|
hash := app.state.Hash()
|
|
return types.NewResultOK(hash, "")
|
|
}
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
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{}
|
|
}
|