Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move client/{tx,rest,utils} into x/auth/client #4555

Merged
merged 8 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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