mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 14:21:22 +00:00
Implemented dummy query
This commit is contained in:
@ -222,7 +222,7 @@ func cmdAppendTx(c *cli.Context) {
|
|||||||
func cmdCheckTx(c *cli.Context) {
|
func cmdCheckTx(c *cli.Context) {
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
fmt.Println("append_tx takes 1 argument")
|
fmt.Println("check_tx takes 1 argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
txString := args[0]
|
txString := args[0]
|
||||||
@ -258,7 +258,7 @@ func cmdGetHash(c *cli.Context) {
|
|||||||
func cmdQuery(c *cli.Context) {
|
func cmdQuery(c *cli.Context) {
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
fmt.Println("append_tx takes 1 argument")
|
fmt.Println("query takes 1 argument")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
queryString := args[0]
|
queryString := args[0]
|
||||||
@ -287,12 +287,15 @@ func printResponse(res *types.Response, s string) {
|
|||||||
if res.Error != "" {
|
if res.Error != "" {
|
||||||
fmt.Printf("error: %s\t", res.Error)
|
fmt.Printf("error: %s\t", res.Error)
|
||||||
}
|
}
|
||||||
if res.Code > 0 {
|
if res.Code != types.CodeType_OK {
|
||||||
fmt.Printf("code: %s", res.Code.String())
|
fmt.Printf("code: %s", res.Code.String())
|
||||||
}
|
}
|
||||||
if s != "" {
|
if s != "" {
|
||||||
fmt.Printf("data: {%s}", s)
|
fmt.Printf("data: {%s}", s)
|
||||||
}
|
}
|
||||||
|
if res.Log != "" {
|
||||||
|
fmt.Printf("log: %s", res.Log)
|
||||||
|
}
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package example
|
package example
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
. "github.com/tendermint/go-common"
|
. "github.com/tendermint/go-common"
|
||||||
"github.com/tendermint/go-merkle"
|
"github.com/tendermint/go-merkle"
|
||||||
"github.com/tendermint/tmsp/types"
|
"github.com/tendermint/tmsp/types"
|
||||||
@ -27,7 +29,12 @@ func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *DummyApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
func (app *DummyApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||||
app.state.Set(tx, tx)
|
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, ""
|
return types.CodeType_OK, nil, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,5 +48,7 @@ func (app *DummyApplication) GetHash() (hash []byte, log string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
|
func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
|
||||||
return types.CodeType_OK, nil, "Query not supported"
|
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), ""
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user