From 27aa06bb7316ea8adb48daffe289f3076415f47d Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 18 Jan 2018 15:14:08 +0100 Subject: [PATCH] Add basic client cli commands --- examples/chub/client.go | 133 ++++++++++++++++++++++++++++++++++++++++ examples/chub/main.go | 2 +- examples/chub/node.go | 2 +- 3 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 examples/chub/client.go diff --git a/examples/chub/client.go b/examples/chub/client.go new file mode 100644 index 0000000000..6f709dda09 --- /dev/null +++ b/examples/chub/client.go @@ -0,0 +1,133 @@ +package main + +import "github.com/spf13/cobra" + +const ( + // these are needed for every init + flagChainID = "chain-id" + flagNode = "node" + + // one of the following should be provided to verify the connection + flagGenesis = "genesis" + flagCommit = "commit" + flagValHash = "validator-set" + + flagSelect = "select" + flagTags = "tag" + flagAny = "any" + + flagBind = "bind" + flagCORS = "cors" +) + +var ( + statusCmd = &cobra.Command{ + Use: "status", + Short: "Query remote node for status", + RunE: todoNotImplemented, + } + + getCmd = &cobra.Command{ + Use: "get", + Short: "Query ABCI state data", + Long: `Query ABCI state data. +Subcommands should be defined for each particular object to query.`, + Run: help, + } + + postCmd = &cobra.Command{ + Use: "post", + Short: "Create a new transaction and post it to the chain", + Long: `Create a new transaction and post it to the chain. +Subcommands should be defined for each particular transaction type.`, + Run: help, + } +) + +func clientCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "client", + Short: "Interact with the chain via a light-client", + Run: help, + } + cmd.AddCommand( + initClientCommand(), + statusCmd, + blockCommand(), + validatorCommand(), + lineBreak, + txSearchCommand(), + txCommand(), + lineBreak, + getCmd, + postCmd, + lineBreak, + serveCommand(), + ) + return cmd +} + +func initClientCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "init", + Short: "Initialize light client", + RunE: todoNotImplemented, + } + cmd.Flags().StringP(flagChainID, "c", "", "ID of chain we connect to") + cmd.Flags().StringP(flagNode, "n", "tcp://localhost:46657", "node to connect to") + cmd.Flags().String(flagGenesis, "", "genesis file to verify header validity") + cmd.Flags().String(flagCommit, "", "file with trusted and signed header") + cmd.Flags().String(flagValHash, "", "hash of trusted validator set (hex-encoded)") + return cmd +} + +func blockCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "block ", + Short: "Get verified data for a the block at given height", + RunE: todoNotImplemented, + } + cmd.Flags().StringSlice(flagSelect, []string{"header", "tx"}, "fields to return (header|txs|results)") + return cmd +} + +func validatorCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "validatorset ", + Short: "Get the full validator set at given height", + RunE: todoNotImplemented, + } + return cmd +} + +func serveCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "serve", + Short: "Start LCD (light-client daemon), a local REST server", + RunE: todoNotImplemented, + } + // TODO: handle unix sockets also? + cmd.Flags().StringP(flagBind, "b", "localhost:1317", "interface and port that server binds to") + cmd.Flags().String(flagCORS, "", "Set to domains that can make CORS requests (* for all)") + return cmd +} + +func txSearchCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "txs", + Short: "Search for all transactions that match the given tags", + RunE: todoNotImplemented, + } + cmd.Flags().StringSlice(flagTags, nil, "tags that must match (may provide multiple)") + cmd.Flags().Bool(flagAny, false, "Return transactions that match ANY tag, rather than ALL") + return cmd +} + +func txCommand() *cobra.Command { + cmd := &cobra.Command{ + Use: "tx ", + Short: "Matches this txhash over all committed blocks", + RunE: todoNotImplemented, + } + return cmd +} diff --git a/examples/chub/main.go b/examples/chub/main.go index be08229f45..9f69968931 100644 --- a/examples/chub/main.go +++ b/examples/chub/main.go @@ -43,7 +43,7 @@ func main() { chubCmd.AddCommand( nodeCommand(node), keyCommand(), - // clientCmd, + clientCommand(), lineBreak, versionCmd, diff --git a/examples/chub/node.go b/examples/chub/node.go index 3e349738d8..be20b64a27 100644 --- a/examples/chub/node.go +++ b/examples/chub/node.go @@ -33,7 +33,7 @@ func nodeCommand(node app.App) *cobra.Command { cmd := &cobra.Command{ Use: "node", Short: "Run the full node", - RunE: todoNotImplemented, + Run: help, } cmd.AddCommand( initNodeCmd,