Browse Source

update readme. --verbose makes batch look like console

pull/1780/head
Ethan Buchman 9 years ago
parent
commit
a263323d5c
2 changed files with 49 additions and 10 deletions
  1. +23
    -0
      README.md
  2. +26
    -10
      cmd/tmsp-cli/tmsp-cli.go

+ 23
- 0
README.md View File

@ -12,6 +12,29 @@ Other implementations:
* [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen * [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen
* [js-tmsp](https://github.com/tendermint/js-tmsp) * [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 ## 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. 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.


+ 26
- 10
cmd/tmsp-cli/tmsp-cli.go View File

@ -22,6 +22,7 @@ func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "tmsp-cli" app.Name = "tmsp-cli"
app.Usage = "tmsp-cli [command] [args...]" app.Usage = "tmsp-cli [command] [args...]"
app.Version = "0.2"
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "address", Name: "address",
@ -33,6 +34,10 @@ func main() {
Value: "socket", Value: "socket",
Usage: "socket or grpc", 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{ app.Commands = []cli.Command{
{ {
@ -133,7 +138,10 @@ func cmdBatch(app *cli.App, c *cli.Context) error {
} else if err != nil { } else if err != nil {
return err return err
} }
args := []string{"tmsp"}
args := []string{"tmsp-cli"}
if c.GlobalBool("verbose") {
args = append(args, "--verbose")
}
args = append(args, strings.Split(string(line), " ")...) args = append(args, strings.Split(string(line), " ")...)
app.Run(args) app.Run(args)
} }
@ -151,7 +159,7 @@ func cmdConsole(app *cli.App, c *cli.Context) error {
return err return err
} }
args := []string{"tmsp"}
args := []string{"tmsp-cli"}
args = append(args, strings.Split(string(line), " ")...) args = append(args, strings.Split(string(line), " ")...)
if err := app.Run(args); err != nil { if err := app.Run(args); err != nil {
return err return err
@ -167,14 +175,14 @@ func cmdEcho(c *cli.Context) error {
return errors.New("Command echo takes 1 argument") return errors.New("Command echo takes 1 argument")
} }
res := client.EchoSync(args[0]) res := client.EchoSync(args[0])
printResponse(res, string(res.Data), false)
printResponse(c, res, string(res.Data), false)
return nil return nil
} }
// Get some info from the application // Get some info from the application
func cmdInfo(c *cli.Context) error { func cmdInfo(c *cli.Context) error {
res := client.InfoSync() res := client.InfoSync()
printResponse(res, string(res.Data), false)
printResponse(c, res, string(res.Data), false)
return nil return nil
} }
@ -185,7 +193,7 @@ func cmdSetOption(c *cli.Context) error {
return errors.New("Command set_option takes 2 arguments (key, value)") return errors.New("Command set_option takes 2 arguments (key, value)")
} }
res := client.SetOptionSync(args[0], args[1]) 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 return nil
} }
@ -197,7 +205,7 @@ func cmdAppendTx(c *cli.Context) error {
} }
txBytes := stringOrHexToBytes(c.Args()[0]) txBytes := stringOrHexToBytes(c.Args()[0])
res := client.AppendTxSync(txBytes) res := client.AppendTxSync(txBytes)
printResponse(res, string(res.Data), true)
printResponse(c, res, string(res.Data), true)
return nil return nil
} }
@ -209,14 +217,14 @@ func cmdCheckTx(c *cli.Context) error {
} }
txBytes := stringOrHexToBytes(c.Args()[0]) txBytes := stringOrHexToBytes(c.Args()[0])
res := client.CheckTxSync(txBytes) res := client.CheckTxSync(txBytes)
printResponse(res, string(res.Data), true)
printResponse(c, res, string(res.Data), true)
return nil return nil
} }
// Get application Merkle root hash // Get application Merkle root hash
func cmdCommit(c *cli.Context) error { func cmdCommit(c *cli.Context) error {
res := client.CommitSync() res := client.CommitSync()
printResponse(res, Fmt("%X", res.Data), false)
printResponse(c, res, Fmt("%X", res.Data), false)
return nil return nil
} }
@ -228,13 +236,17 @@ func cmdQuery(c *cli.Context) error {
} }
queryBytes := stringOrHexToBytes(c.Args()[0]) queryBytes := stringOrHexToBytes(c.Args()[0])
res := client.QuerySync(queryBytes) res := client.QuerySync(queryBytes)
printResponse(res, string(res.Data), true)
printResponse(c, res, string(res.Data), true)
return nil 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 { if printCode {
fmt.Printf("-> code: %s\n", res.Code.String()) 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) fmt.Printf("-> log: %s\n", res.Log)
} }
if c.GlobalBool("verbose") {
fmt.Println("")
}
} }
// NOTE: s is interpreted as a string unless prefixed with 0x // NOTE: s is interpreted as a string unless prefixed with 0x


Loading…
Cancel
Save