From 446286aab86f4460eabe705c469447f2e9b3f9b9 Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Mon, 24 Sep 2018 15:00:06 +0100 Subject: [PATCH] CLI subcommands reorganization Remove unused SignTxRequstHandler Closes: #1184 --- client/rpc/validators.go | 4 +- client/tx/sign.go | 48 --------------- cmd/gaia/cmd/gaiacli/main.go | 113 +++++++++++++++-------------------- x/auth/client/cli/sign.go | 2 +- x/gov/client/cli/tx.go | 32 +++++----- 5 files changed, 67 insertions(+), 132 deletions(-) delete mode 100644 client/tx/sign.go diff --git a/client/rpc/validators.go b/client/rpc/validators.go index 0583dc054547..84fb3d2db391 100644 --- a/client/rpc/validators.go +++ b/client/rpc/validators.go @@ -1,6 +1,7 @@ package rpc import ( + "bytes" "fmt" "net/http" "strconv" @@ -8,7 +9,6 @@ import ( "github.com/gorilla/mux" "github.com/spf13/cobra" - "bytes" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/context" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,7 +20,7 @@ import ( //ValidatorCommand returns the validator set for a given height func ValidatorCommand() *cobra.Command { cmd := &cobra.Command{ - Use: "validator-set [height]", + Use: "tendermint-validator-set [height]", Short: "Get the full tendermint validator set at given height", Args: cobra.MaximumNArgs(1), RunE: printValidators, diff --git a/client/tx/sign.go b/client/tx/sign.go deleted file mode 100644 index 786c7fa0bd63..000000000000 --- a/client/tx/sign.go +++ /dev/null @@ -1,48 +0,0 @@ -package tx - -import ( - "encoding/json" - "net/http" - - keybase "github.com/cosmos/cosmos-sdk/client/keys" - keys "github.com/cosmos/cosmos-sdk/crypto/keys" -) - -// REST request body for signed txs -// TODO does this need to be exposed? -type SignTxBody struct { - Name string `json:"name"` - Password string `json:"password"` - TxBytes string `json:"tx"` -} - -// sign transaction REST Handler -func SignTxRequstHandler(w http.ResponseWriter, r *http.Request) { - var kb keys.Keybase - var m SignTxBody - - decoder := json.NewDecoder(r.Body) - err := decoder.Decode(&m) - if err != nil { - w.WriteHeader(400) - w.Write([]byte(err.Error())) - return - } - - kb, err = keybase.GetKeyBase() - if err != nil { - w.WriteHeader(500) - w.Write([]byte(err.Error())) - return - } - - //TODO check if account exists - sig, _, err := kb.Sign(m.Name, m.Password, []byte(m.TxBytes)) - if err != nil { - w.WriteHeader(403) - w.Write([]byte(err.Error())) - return - } - - w.Write(sig) -} diff --git a/cmd/gaia/cmd/gaiacli/main.go b/cmd/gaia/cmd/gaiacli/main.go index c61b30056f0a..2a40254ad316 100644 --- a/cmd/gaia/cmd/gaiacli/main.go +++ b/cmd/gaia/cmd/gaiacli/main.go @@ -39,89 +39,72 @@ func main() { // add standard rpc commands rpc.AddCommands(rootCmd) - //Add state commands - tendermintCmd := &cobra.Command{ - Use: "tendermint", - Short: "Tendermint state querying subcommands", + //Add query commands + queryCmd := &cobra.Command{ + Use: "query", + Short: "Querying subcommands", } - tendermintCmd.AddCommand( + queryCmd.AddCommand( rpc.BlockCommand(), rpc.ValidatorCommand(), ) - tx.AddCommands(tendermintCmd, cdc) + tx.AddCommands(queryCmd, cdc) + queryCmd.AddCommand(client.LineBreak) + queryCmd.AddCommand(client.GetCommands( + authcmd.GetAccountCmd("acc", cdc, authcmd.GetAccountDecoder(cdc)), + stakecmd.GetCmdQueryDelegation("stake", cdc), + stakecmd.GetCmdQueryDelegations("stake", cdc), + stakecmd.GetCmdQueryParams("stake", cdc), + stakecmd.GetCmdQueryPool("stake", cdc), + govcmd.GetCmdQueryProposal("gov", cdc), + govcmd.GetCmdQueryProposals("gov", cdc), + stakecmd.GetCmdQueryRedelegation("stake", cdc), + stakecmd.GetCmdQueryRedelegations("stake", cdc), + slashingcmd.GetCmdQuerySigningInfo("slashing", cdc), + stakecmd.GetCmdQueryUnbondingDelegation("stake", cdc), + stakecmd.GetCmdQueryUnbondingDelegations("stake", cdc), + stakecmd.GetCmdQueryValidator("stake", cdc), + stakecmd.GetCmdQueryValidators("stake", cdc), + govcmd.GetCmdQueryVote("gov", cdc), + govcmd.GetCmdQueryVotes("gov", cdc), + )...) - rootCmd.AddCommand( - tendermintCmd, - lcd.ServeCommand(cdc), - client.LineBreak, - ) - - //Add stake commands - stakeCmd := &cobra.Command{ - Use: "stake", - Short: "Stake and validation subcommands", + //Add query commands + txCmd := &cobra.Command{ + Use: "tx", + Short: "Transactions subcommands", } - stakeCmd.AddCommand( - client.GetCommands( - stakecmd.GetCmdQueryValidator("stake", cdc), - stakecmd.GetCmdQueryValidators("stake", cdc), - stakecmd.GetCmdQueryDelegation("stake", cdc), - stakecmd.GetCmdQueryDelegations("stake", cdc), - stakecmd.GetCmdQueryParams("stake", cdc), - stakecmd.GetCmdQueryPool("stake", cdc), - stakecmd.GetCmdQueryUnbondingDelegation("stake", cdc), - stakecmd.GetCmdQueryUnbondingDelegations("stake", cdc), - stakecmd.GetCmdQueryRedelegation("stake", cdc), - stakecmd.GetCmdQueryRedelegations("stake", cdc), - slashingcmd.GetCmdQuerySigningInfo("slashing", cdc), + + //Add auth and bank commands + txCmd.AddCommand( + client.PostCommands( + bankcmd.GetBroadcastCommand(cdc), )...) - stakeCmd.AddCommand( + txCmd.AddCommand( + authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)), + ) + txCmd.AddCommand(client.LineBreak) + + txCmd.AddCommand( client.PostCommands( stakecmd.GetCmdCreateValidator(cdc), stakecmd.GetCmdEditValidator(cdc), stakecmd.GetCmdDelegate(cdc), - stakecmd.GetCmdUnbond("stake", cdc), + govcmd.GetCmdDeposit(cdc), stakecmd.GetCmdRedelegate("stake", cdc), - slashingcmd.GetCmdUnjail(cdc), - )...) - rootCmd.AddCommand( - stakeCmd, - ) - - //Add stake commands - govCmd := &cobra.Command{ - Use: "gov", - Short: "Governance and voting subcommands", - } - govCmd.AddCommand( - client.GetCommands( - govcmd.GetCmdQueryProposal("gov", cdc), - govcmd.GetCmdQueryVote("gov", cdc), - govcmd.GetCmdQueryVotes("gov", cdc), - govcmd.GetCmdQueryProposals("gov", cdc), - )...) - govCmd.AddCommand( - client.PostCommands( + bankcmd.SendTxCmd(cdc), govcmd.GetCmdSubmitProposal(cdc), - govcmd.GetCmdDeposit(cdc), + stakecmd.GetCmdUnbond("stake", cdc), + slashingcmd.GetCmdUnjail(cdc), govcmd.GetCmdVote(cdc), )...) rootCmd.AddCommand( - govCmd, + queryCmd, + txCmd, + lcd.ServeCommand(cdc), + client.LineBreak, ) - //Add auth and bank commands - rootCmd.AddCommand( - client.GetCommands( - authcmd.GetAccountCmd("acc", cdc, authcmd.GetAccountDecoder(cdc)), - authcmd.GetSignCommand(cdc, authcmd.GetAccountDecoder(cdc)), - )...) - rootCmd.AddCommand( - client.PostCommands( - bankcmd.SendTxCmd(cdc), - bankcmd.GetBroadcastCommand(cdc), - )...) - // add proxy, version and key info rootCmd.AddCommand( keys.Commands(), diff --git a/x/auth/client/cli/sign.go b/x/auth/client/cli/sign.go index d8ffae813e44..31648e3de035 100644 --- a/x/auth/client/cli/sign.go +++ b/x/auth/client/cli/sign.go @@ -25,7 +25,7 @@ const ( func GetSignCommand(codec *amino.Codec, decoder auth.AccountDecoder) *cobra.Command { cmd := &cobra.Command{ Use: "sign ", - Short: "Sign transactions", + Short: "Sign transactions generated offline", Long: `Sign transactions created with the --generate-only flag. Read a transaction from , sign it, and print its JSON encoding.`, RunE: makeSignCmd(codec, decoder), diff --git a/x/gov/client/cli/tx.go b/x/gov/client/cli/tx.go index 77364665a129..cf7c57779d17 100644 --- a/x/gov/client/cli/tx.go +++ b/x/gov/client/cli/tx.go @@ -159,7 +159,7 @@ func parseSubmitProposalFlags() (*proposal, error) { func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "deposit", - Short: "deposit tokens for activing proposal", + Short: "Deposit tokens for activing proposal", RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc) cliCtx := context.NewCLIContext(). @@ -205,7 +205,7 @@ func GetCmdDeposit(cdc *codec.Codec) *cobra.Command { func GetCmdVote(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "vote", - Short: "vote for an active proposal, options: Yes/No/NoWithVeto/Abstain", + Short: "Vote for an active proposal, options: Yes/No/NoWithVeto/Abstain", RunE: func(cmd *cobra.Command, args []string) error { txBldr := authtxb.NewTxBuilderFromCLI().WithCodec(cdc) cliCtx := context.NewCLIContext(). @@ -255,8 +255,8 @@ func GetCmdVote(cdc *codec.Codec) *cobra.Command { // GetCmdQueryProposal implements the query proposal command. func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-proposal", - Short: "query proposal details", + Use: "proposal", + Short: "Query details of a single proposal", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID) @@ -289,8 +289,8 @@ func GetCmdQueryProposal(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryProposals implements a query proposals command. func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-proposals", - Short: "query proposals with optional filters", + Use: "proposals", + Short: "Query proposals with optional filters", RunE: func(cmd *cobra.Command, args []string) error { bechDepositerAddr := viper.GetString(flagDepositer) bechVoterAddr := viper.GetString(flagVoter) @@ -368,8 +368,8 @@ func GetCmdQueryProposals(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryVote implements the query proposal vote command. func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-vote", - Short: "query vote", + Use: "vote", + Short: "Query details of a single vote", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID) @@ -407,8 +407,8 @@ func GetCmdQueryVote(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryVotes implements the command to query for proposal votes. func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-votes", - Short: "query votes on a proposal", + Use: "votes", + Short: "Query votes on a proposal", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID) @@ -440,8 +440,8 @@ func GetCmdQueryVotes(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryDeposit implements the query proposal deposit command. func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-deposit", - Short: "query deposit", + Use: "deposit", + Short: "Query details of a deposit", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID) @@ -479,8 +479,8 @@ func GetCmdQueryDeposit(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryDeposits implements the command to query for proposal deposits. func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-deposits", - Short: "query deposits on a proposal", + Use: "deposits", + Short: "Query deposits on a proposal", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID) @@ -511,8 +511,8 @@ func GetCmdQueryDeposits(queryRoute string, cdc *codec.Codec) *cobra.Command { // GetCmdQueryDeposits implements the command to query for proposal deposits. func GetCmdQueryTally(queryRoute string, cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "query-tally", - Short: "get the tally of a proposal vote", + Use: "tally", + Short: "Get the tally of a proposal vote", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) proposalID := viper.GetInt64(flagProposalID)