From a263323d5c816030ff75eb9808028d8e6d747ffa Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 23 Jul 2016 17:37:09 -0400 Subject: [PATCH] update readme. --verbose makes batch look like console --- README.md | 23 +++++++++++++++++++++++ cmd/tmsp-cli/tmsp-cli.go | 36 ++++++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 617e581ba..11559c9ac 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,29 @@ Other implementations: * [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen * [js-tmsp](https://github.com/tendermint/js-tmsp) +## Contents + +This repository holds a number of important pieces: + +- `types/types.proto` + - the protobuf file definig TMSP message types, and the optional grpc interface. + - use `protoc --go_out=plugins=grpc:./types types/types.proto` to generate the `types/types.pb.go` file + - see `protoc --help` and [the grpc docs](www.grpc.io/docs) for examples and details of other languages + +- golang implementation of TMSP client and server + - two implementations: + - asynchronous, ordered message passing over unix or tcp + - grpc + - TendermintCore runs a client, and the application runs a server + +- `cmd/tmsp-cli` + - command line tool wrapping the client for probing/testing a TMSP application + +- examples: + - the `cmd/counter` application, which illustrates nonce checking in txs + - the `cmd/dummy` application, which illustrates a simple key-value merkle tree + + ## Message format Since this is a streaming protocol, all messages are encoded with a length-prefix followed by the message encoded in Protobuf3. Protobuf3 doesn't have an official length-prefix standard, so we use our own. The first byte represents the length of the big-endian encoded length. diff --git a/cmd/tmsp-cli/tmsp-cli.go b/cmd/tmsp-cli/tmsp-cli.go index f30979117..964dbe69c 100644 --- a/cmd/tmsp-cli/tmsp-cli.go +++ b/cmd/tmsp-cli/tmsp-cli.go @@ -22,6 +22,7 @@ func main() { app := cli.NewApp() app.Name = "tmsp-cli" app.Usage = "tmsp-cli [command] [args...]" + app.Version = "0.2" app.Flags = []cli.Flag{ cli.StringFlag{ Name: "address", @@ -33,6 +34,10 @@ func main() { Value: "socket", Usage: "socket or grpc", }, + cli.BoolFlag{ + Name: "verbose", + Usage: "print the command and results as if it were a console session", + }, } app.Commands = []cli.Command{ { @@ -133,7 +138,10 @@ func cmdBatch(app *cli.App, c *cli.Context) error { } else if err != nil { return err } - args := []string{"tmsp"} + args := []string{"tmsp-cli"} + if c.GlobalBool("verbose") { + args = append(args, "--verbose") + } args = append(args, strings.Split(string(line), " ")...) app.Run(args) } @@ -151,7 +159,7 @@ func cmdConsole(app *cli.App, c *cli.Context) error { return err } - args := []string{"tmsp"} + args := []string{"tmsp-cli"} args = append(args, strings.Split(string(line), " ")...) if err := app.Run(args); err != nil { return err @@ -167,14 +175,14 @@ func cmdEcho(c *cli.Context) error { return errors.New("Command echo takes 1 argument") } res := client.EchoSync(args[0]) - printResponse(res, string(res.Data), false) + printResponse(c, res, string(res.Data), false) return nil } // Get some info from the application func cmdInfo(c *cli.Context) error { res := client.InfoSync() - printResponse(res, string(res.Data), false) + printResponse(c, res, string(res.Data), false) return nil } @@ -185,7 +193,7 @@ func cmdSetOption(c *cli.Context) error { return errors.New("Command set_option takes 2 arguments (key, value)") } res := client.SetOptionSync(args[0], args[1]) - printResponse(res, Fmt("%s=%s", args[0], args[1]), false) + printResponse(c, res, Fmt("%s=%s", args[0], args[1]), false) return nil } @@ -197,7 +205,7 @@ func cmdAppendTx(c *cli.Context) error { } txBytes := stringOrHexToBytes(c.Args()[0]) res := client.AppendTxSync(txBytes) - printResponse(res, string(res.Data), true) + printResponse(c, res, string(res.Data), true) return nil } @@ -209,14 +217,14 @@ func cmdCheckTx(c *cli.Context) error { } txBytes := stringOrHexToBytes(c.Args()[0]) res := client.CheckTxSync(txBytes) - printResponse(res, string(res.Data), true) + printResponse(c, res, string(res.Data), true) return nil } // Get application Merkle root hash func cmdCommit(c *cli.Context) error { res := client.CommitSync() - printResponse(res, Fmt("%X", res.Data), false) + printResponse(c, res, Fmt("%X", res.Data), false) return nil } @@ -228,13 +236,17 @@ func cmdQuery(c *cli.Context) error { } queryBytes := stringOrHexToBytes(c.Args()[0]) res := client.QuerySync(queryBytes) - printResponse(res, string(res.Data), true) + printResponse(c, res, string(res.Data), true) return nil } //-------------------------------------------------------------------------------- -func printResponse(res types.Result, s string, printCode bool) { +func printResponse(c *cli.Context, res types.Result, s string, printCode bool) { + if c.GlobalBool("verbose") { + fmt.Println(">", c.Command.Name, strings.Join(c.Args(), " ")) + } + if printCode { fmt.Printf("-> code: %s\n", res.Code.String()) } @@ -248,6 +260,10 @@ func printResponse(res types.Result, s string, printCode bool) { fmt.Printf("-> log: %s\n", res.Log) } + if c.GlobalBool("verbose") { + fmt.Println("") + } + } // NOTE: s is interpreted as a string unless prefixed with 0x