Skip to content

Commit

Permalink
Merge PR cosmos#4555: Move client/{tx,rest,utils} into x/auth/client
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio authored and alexanderbez committed Jun 15, 2019
1 parent 941effc commit 73700df
Show file tree
Hide file tree
Showing 51 changed files with 620 additions and 640 deletions.
2 changes: 2 additions & 0 deletions .pending/breaking/sdk/4488-client-s-tx-res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#4488 Decouple client tx, REST, and ultil packages from auth. These packages have
been restructured and retrofitted into the `x/auth` module.
28 changes: 0 additions & 28 deletions client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/input"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/lcd"
"github.com/cosmos/cosmos-sdk/client/rest"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/client/utils"
)

const (
Expand Down Expand Up @@ -94,7 +91,6 @@ var (
NewInMemoryKeyBase = keys.NewInMemoryKeyBase
NewRestServer = lcd.NewRestServer
ServeCommand = lcd.ServeCommand
WriteGenerateStdTxResponse = rest.WriteGenerateStdTxResponse
BlockCommand = rpc.BlockCommand
GetChainHeight = rpc.GetChainHeight
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
Expand All @@ -109,27 +105,6 @@ var (
GetValidators = rpc.GetValidators
ValidatorSetRequestHandlerFn = rpc.ValidatorSetRequestHandlerFn
LatestValidatorSetRequestHandlerFn = rpc.LatestValidatorSetRequestHandlerFn
BroadcastTxRequest = tx.BroadcastTxRequest
GetBroadcastCommand = tx.GetBroadcastCommand
EncodeTxRequestHandlerFn = tx.EncodeTxRequestHandlerFn
GetEncodeCommand = tx.GetEncodeCommand
SearchTxCmd = tx.SearchTxCmd
QueryTxCmd = tx.QueryTxCmd
QueryTxsByTagsRequestHandlerFn = tx.QueryTxsByTagsRequestHandlerFn
QueryTxRequestHandlerFn = tx.QueryTxRequestHandlerFn
RegisterTxRoutes = tx.RegisterTxRoutes
SearchTxs = tx.SearchTxs
ValidateTxResult = tx.ValidateTxResult
GenerateOrBroadcastMsgs = utils.GenerateOrBroadcastMsgs
CompleteAndBroadcastTxCLI = utils.CompleteAndBroadcastTxCLI
EnrichWithGas = utils.EnrichWithGas
CalculateGas = utils.CalculateGas
PrintUnsignedStdTx = utils.PrintUnsignedStdTx
SignStdTx = utils.SignStdTx
SignStdTxWithSignerAddress = utils.SignStdTxWithSignerAddress
ReadStdTxFromFile = utils.ReadStdTxFromFile
GetTxEncoder = utils.GetTxEncoder
PrepareTxBuilder = utils.PrepareTxBuilder
BufferStdin = input.BufferStdin
OverrideStdin = input.OverrideStdin
GetPassword = input.GetPassword
Expand All @@ -153,7 +128,4 @@ type (
RestServer = lcd.RestServer
ValidatorOutput = rpc.ValidatorOutput
ResultValidatorsOutput = rpc.ResultValidatorsOutput
BroadcastReq = tx.BroadcastReq
EncodeResp = tx.EncodeResp
GasEstimateResponse = utils.GasEstimateResponse
)
38 changes: 38 additions & 0 deletions client/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package client

import (
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// ValidateCmd returns unknown command error or Help display if help flag set
func ValidateCmd(cmd *cobra.Command, args []string) error {
var cmds []string
var help bool

// construct array of commands and search for help flag
for _, arg := range args {
if arg == "--help" || arg == "-h" {
help = true
} else if len(arg) > 0 && !(arg[0] == '-') {
cmds = append(cmds, arg)
}
}

if !help && len(cmds) > 0 {
err := fmt.Sprintf("unknown command \"%s\" for \"%s\"", cmds[0], cmd.CalledAs())

// build suggestions for unknown argument
if suggestions := cmd.SuggestionsFor(cmds[0]); len(suggestions) > 0 {
err += "\n\nDid you mean this?\n"
for _, s := range suggestions {
err += fmt.Sprintf("\t%v\n", s)
}
}
return errors.New(err)
}

return cmd.Help()
}
50 changes: 50 additions & 0 deletions client/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package client_test

import (
"testing"

"github.com/spf13/cobra"
"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client"
)

func TestValidateCmd(t *testing.T) {
// setup root and subcommands
rootCmd := &cobra.Command{
Use: "root",
}
queryCmd := &cobra.Command{
Use: "query",
}
rootCmd.AddCommand(queryCmd)

// command being tested
distCmd := &cobra.Command{
Use: "distr",
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
}
queryCmd.AddCommand(distCmd)

commissionCmd := &cobra.Command{
Use: "commission",
}
distCmd.AddCommand(commissionCmd)

tests := []struct {
reason string
args []string
wantErr bool
}{
{"misspelled command", []string{"comission"}, true},
{"no command provided", []string{}, false},
{"help flag", []string{"comission", "--help"}, false},
{"shorthand help flag", []string{"comission", "-h"}, false},
}

for _, tt := range tests {
err := client.ValidateCmd(distCmd, tt.args)
require.Equal(t, tt.wantErr, err != nil, tt.reason)
}
}
5 changes: 0 additions & 5 deletions client/rest/errors.go

This file was deleted.

1 change: 0 additions & 1 deletion client/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ import (
// Register routes
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router) {
RegisterRPCRoutes(cliCtx, r)
RegisterTxRoutes(cliCtx, r)
}
95 changes: 0 additions & 95 deletions client/tx/broadcast.go

This file was deleted.

Loading

0 comments on commit 73700df

Please sign in to comment.