From 4674bf96b036ec64f70f836593a68388f3d12ae5 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Sat, 13 May 2017 18:37:00 +0200 Subject: [PATCH 1/3] Extend the query command --- cmd/abci-cli/abci-cli.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index f4fe45fe..9327a3f1 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "os" + "strconv" "strings" abcicli "github.com/tendermint/abci/client" @@ -307,18 +308,36 @@ func cmdCommit(c *cli.Context) error { // TODO: Make request and response support all fields. func cmdQuery(c *cli.Context) error { args := c.Args() - if len(args) != 1 { - return errors.New("Command query takes 1 argument") + fmt.Println(len(args)) + if len(args) == 0 { + return errors.New("Command query takes 1 or more arguments") } - queryBytes, err := stringOrHexToBytes(c.Args()[0]) + + queryBytes, err := stringOrHexToBytes(args[0]) if err != nil { return err } + + var path = "/store" + if len(args) > 1 { + path = args[1] + } + + var height uint64 + if len(args) > 2 { + height, _ = strconv.ParseUint(args[2], 10, 64) + } + + var prove = true + if len(args) > 3 { + prove, _ = strconv.ParseBool(args[3]) + } + resQuery, err := client.QuerySync(types.RequestQuery{ Data: queryBytes, - Path: "/store", // TOOD expose - Height: 0, // TODO expose - //Prove: true, // TODO expose + Path: path, + Height: height, + Prove: prove, }) if err != nil { return err From b55e695d3d33d87c2ab1335669c597fd746ca384 Mon Sep 17 00:00:00 2001 From: Adrian Brink Date: Sat, 13 May 2017 21:08:34 +0200 Subject: [PATCH 2/3] Remove debug statement --- cmd/abci-cli/abci-cli.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index 9327a3f1..de157832 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -308,7 +308,7 @@ func cmdCommit(c *cli.Context) error { // TODO: Make request and response support all fields. func cmdQuery(c *cli.Context) error { args := c.Args() - fmt.Println(len(args)) + if len(args) == 0 { return errors.New("Command query takes 1 or more arguments") } From 894f3fca73b2dacca5fe99bda50c128d5cbef8e5 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Mon, 15 May 2017 12:28:37 -0400 Subject: [PATCH 3/3] cmd: query params are flags --- cmd/abci-cli/abci-cli.go | 41 +++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index de157832..1b3d2dc5 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "os" - "strconv" "strings" abcicli "github.com/tendermint/abci/client" @@ -127,6 +126,22 @@ func main() { Action: func(c *cli.Context) error { return cmdQuery(c) }, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "path", + Value: "/store", + Usage: "Path to prefix the query with", + }, + cli.IntFlag{ + Name: "height", + Value: 0, + Usage: "Height to query the blockchain at", + }, + cli.BoolFlag{ + Name: "prove", + Usage: "Whether or not to return a merkle proof of the query result", + }, + }, }, } app.Before = before @@ -305,12 +320,11 @@ func cmdCommit(c *cli.Context) error { } // Query application state -// TODO: Make request and response support all fields. func cmdQuery(c *cli.Context) error { args := c.Args() - if len(args) == 0 { - return errors.New("Command query takes 1 or more arguments") + if len(args) != 1 { + return errors.New("Command query takes 1 argument, the query bytes") } queryBytes, err := stringOrHexToBytes(args[0]) @@ -318,25 +332,14 @@ func cmdQuery(c *cli.Context) error { return err } - var path = "/store" - if len(args) > 1 { - path = args[1] - } - - var height uint64 - if len(args) > 2 { - height, _ = strconv.ParseUint(args[2], 10, 64) - } - - var prove = true - if len(args) > 3 { - prove, _ = strconv.ParseBool(args[3]) - } + path := c.String("path") + height := c.Int("height") + prove := c.Bool("prove") resQuery, err := client.QuerySync(types.RequestQuery{ Data: queryBytes, Path: path, - Height: height, + Height: uint64(height), Prove: prove, }) if err != nil {