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

R4R reduce module interdependancy, /client refactor #4415

Merged
merged 5 commits into from
May 28, 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
1 change: 1 addition & 0 deletions .pending/improvements/sdk/4415-clienr-refactor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4415 /client refactor, reduce genutil dependancy on staking
160 changes: 160 additions & 0 deletions client/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// nolint
// autogenerated code using github.com/rigelrozanski/multitool
// aliases generated for the following subdirectories:
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/context
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/flags
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/keys
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/lcd
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/rest
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/rpc
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/tx
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/utils
// ALIASGEN: github.com/cosmos/cosmos-sdk/client/input
package client

import (
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/client/flags"
"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 (
DefaultGasAdjustment = flags.DefaultGasAdjustment
DefaultGasLimit = flags.DefaultGasLimit
GasFlagAuto = flags.GasFlagAuto
BroadcastBlock = flags.BroadcastBlock
BroadcastSync = flags.BroadcastSync
BroadcastAsync = flags.BroadcastAsync
FlagHome = flags.FlagHome
FlagUseLedger = flags.FlagUseLedger
FlagChainID = flags.FlagChainID
FlagNode = flags.FlagNode
FlagHeight = flags.FlagHeight
FlagGasAdjustment = flags.FlagGasAdjustment
FlagTrustNode = flags.FlagTrustNode
FlagFrom = flags.FlagFrom
FlagName = flags.FlagName
FlagAccountNumber = flags.FlagAccountNumber
FlagSequence = flags.FlagSequence
FlagMemo = flags.FlagMemo
FlagFees = flags.FlagFees
FlagGasPrices = flags.FlagGasPrices
FlagBroadcastMode = flags.FlagBroadcastMode
FlagPrintResponse = flags.FlagPrintResponse
FlagDryRun = flags.FlagDryRun
FlagGenerateOnly = flags.FlagGenerateOnly
FlagIndentResponse = flags.FlagIndentResponse
FlagListenAddr = flags.FlagListenAddr
FlagCORS = flags.FlagCORS
FlagMaxOpenConnections = flags.FlagMaxOpenConnections
FlagRPCReadTimeout = flags.FlagRPCReadTimeout
FlagRPCWriteTimeout = flags.FlagRPCWriteTimeout
FlagOutputDocument = flags.FlagOutputDocument
FlagSkipConfirmation = flags.FlagSkipConfirmation
DefaultKeyPass = keys.DefaultKeyPass
FlagAddress = keys.FlagAddress
FlagPublicKey = keys.FlagPublicKey
FlagBechPrefix = keys.FlagBechPrefix
FlagDevice = keys.FlagDevice
OutputFormatText = keys.OutputFormatText
OutputFormatJSON = keys.OutputFormatJSON
MinPassLength = input.MinPassLength
)

var (
// functions aliases
NewCLIContextWithFrom = context.NewCLIContextWithFrom
NewCLIContext = context.NewCLIContext
GetAccountDecoder = context.GetAccountDecoder
GetFromFields = context.GetFromFields
ErrInvalidAccount = context.ErrInvalidAccount
ErrVerifyCommit = context.ErrVerifyCommit
GetCommands = flags.GetCommands
PostCommands = flags.PostCommands
RegisterRestServerFlags = flags.RegisterRestServerFlags
ParseGas = flags.ParseGas
NewCompletionCmd = flags.NewCompletionCmd
MarshalJSON = keys.MarshalJSON
UnmarshalJSON = keys.UnmarshalJSON
Commands = keys.Commands
NewAddNewKey = keys.NewAddNewKey
NewRecoverKey = keys.NewRecoverKey
NewUpdateKeyReq = keys.NewUpdateKeyReq
NewDeleteKeyReq = keys.NewDeleteKeyReq
GetKeyInfo = keys.GetKeyInfo
GetPassphrase = keys.GetPassphrase
ReadPassphraseFromStdin = keys.ReadPassphraseFromStdin
NewKeyBaseFromHomeFlag = keys.NewKeyBaseFromHomeFlag
NewKeyBaseFromDir = keys.NewKeyBaseFromDir
NewInMemoryKeyBase = keys.NewInMemoryKeyBase
NewRestServer = lcd.NewRestServer
ServeCommand = lcd.ServeCommand
WriteGenerateStdTxResponse = rest.WriteGenerateStdTxResponse
BlockCommand = rpc.BlockCommand
GetChainHeight = rpc.GetChainHeight
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
RegisterRPCRoutes = rpc.RegisterRPCRoutes
CLIVersionRequestHandler = rpc.CLIVersionRequestHandler
NodeVersionRequestHandler = rpc.NodeVersionRequestHandler
StatusCommand = rpc.StatusCommand
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn
ValidatorCommand = rpc.ValidatorCommand
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
GetCheckPassword = input.GetCheckPassword
GetConfirmation = input.GetConfirmation
GetString = input.GetString
PrintPrefixed = input.PrintPrefixed

// variable aliases
LineBreak = flags.LineBreak
GasFlagVar = flags.GasFlagVar
)

type (
CLIContext = context.CLIContext
GasSetting = flags.GasSetting
AddNewKey = keys.AddNewKey
RecoverKey = keys.RecoverKey
UpdateKeyReq = keys.UpdateKeyReq
DeleteKeyReq = keys.DeleteKeyReq
RestServer = lcd.RestServer
ValidatorOutput = rpc.ValidatorOutput
ResultValidatorsOutput = rpc.ResultValidatorsOutput
BroadcastReq = tx.BroadcastReq
EncodeResp = tx.EncodeResp
GasEstimateResponse = utils.GasEstimateResponse
)
11 changes: 4 additions & 7 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ import (
"path"
"strconv"

"github.com/tendermint/tendermint/libs/cli"

toml "github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"github.com/spf13/viper"

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

const (
flagGet = "get"

// DefaultKeyPass contains the default key password for genesis transactions
DefaultKeyPass = "12345678"
)

var configDefaults = map[string]string{
Expand All @@ -38,15 +35,15 @@ func ConfigCmd(defaultCLIHome string) *cobra.Command {
Args: cobra.RangeArgs(0, 2),
}

cmd.Flags().String(cli.HomeFlag, defaultCLIHome,
cmd.Flags().String(flags.FlagHome, defaultCLIHome,
"set client's home directory for configuration")
cmd.Flags().Bool(flagGet, false,
"print configuration value or its default if unset")
return cmd
}

func runConfigCmd(cmd *cobra.Command, args []string) error {
cfgFile, err := ensureConfFile(viper.GetString(cli.HomeFlag))
cfgFile, err := ensureConfFile(viper.GetString(flags.FlagHome))
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/cli"

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

// For https://github.com/cosmos/cosmos-sdk/issues/3899
Expand All @@ -19,7 +20,7 @@ func Test_runConfigCmdTwiceWithShorterNodeValue(t *testing.T) {
configHome, cleanup := tmpDir(t)
defer cleanup()
_ = os.RemoveAll(filepath.Join(configHome, "config"))
viper.Set(cli.HomeFlag, configHome)
viper.Set(flags.FlagHome, configHome)

// Init command config
cmd := ConfigCmd(configHome)
Expand Down
8 changes: 4 additions & 4 deletions client/context/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package context
import (
"fmt"

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

Expand All @@ -13,13 +13,13 @@ import (
// defined.
func (ctx CLIContext) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) {
switch ctx.BroadcastMode {
case client.BroadcastSync:
case flags.BroadcastSync:
res, err = ctx.BroadcastTxSync(txBytes)

case client.BroadcastAsync:
case flags.BroadcastAsync:
res, err = ctx.BroadcastTxAsync(txBytes)

case client.BroadcastBlock:
case flags.BroadcastBlock:
res, err = ctx.BroadcastTxCommit(txBytes)

default:
Expand Down
40 changes: 20 additions & 20 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/codec"
cryptokeys "github.com/cosmos/cosmos-sdk/crypto/keys"
Expand Down Expand Up @@ -65,66 +65,66 @@ func NewCLIContextWithFrom(from string) CLIContext {
var nodeURI string
var rpc rpcclient.Client

genOnly := viper.GetBool(client.FlagGenerateOnly)
genOnly := viper.GetBool(flags.FlagGenerateOnly)
fromAddress, fromName, err := GetFromFields(from, genOnly)
if err != nil {
fmt.Printf("failed to get from fields: %v", err)
os.Exit(1)
}

if !genOnly {
nodeURI = viper.GetString(client.FlagNode)
nodeURI = viper.GetString(flags.FlagNode)
if nodeURI != "" {
rpc = rpcclient.NewHTTP(nodeURI, "/websocket")
}
}

// We need to use a single verifier for all contexts
if verifier == nil || verifierHome != viper.GetString(cli.HomeFlag) {
if verifier == nil || verifierHome != viper.GetString(flags.FlagHome) {
verifier = createVerifier()
verifierHome = viper.GetString(cli.HomeFlag)
verifierHome = viper.GetString(flags.FlagHome)
}

return CLIContext{
Client: rpc,
Output: os.Stdout,
NodeURI: nodeURI,
AccountStore: auth.StoreKey,
From: viper.GetString(client.FlagFrom),
From: viper.GetString(flags.FlagFrom),
OutputFormat: viper.GetString(cli.OutputFlag),
Height: viper.GetInt64(client.FlagHeight),
TrustNode: viper.GetBool(client.FlagTrustNode),
UseLedger: viper.GetBool(client.FlagUseLedger),
BroadcastMode: viper.GetString(client.FlagBroadcastMode),
PrintResponse: viper.GetBool(client.FlagPrintResponse),
Height: viper.GetInt64(flags.FlagHeight),
TrustNode: viper.GetBool(flags.FlagTrustNode),
UseLedger: viper.GetBool(flags.FlagUseLedger),
BroadcastMode: viper.GetString(flags.FlagBroadcastMode),
PrintResponse: viper.GetBool(flags.FlagPrintResponse),
Verifier: verifier,
Simulate: viper.GetBool(client.FlagDryRun),
Simulate: viper.GetBool(flags.FlagDryRun),
GenerateOnly: genOnly,
FromAddress: fromAddress,
FromName: fromName,
Indent: viper.GetBool(client.FlagIndentResponse),
SkipConfirm: viper.GetBool(client.FlagSkipConfirmation),
Indent: viper.GetBool(flags.FlagIndentResponse),
SkipConfirm: viper.GetBool(flags.FlagSkipConfirmation),
}
}

// NewCLIContext returns a new initialized CLIContext with parameters from the
// command line using Viper.
func NewCLIContext() CLIContext { return NewCLIContextWithFrom(viper.GetString(client.FlagFrom)) }
func NewCLIContext() CLIContext { return NewCLIContextWithFrom(viper.GetString(flags.FlagFrom)) }

func createVerifier() tmlite.Verifier {
trustNodeDefined := viper.IsSet(client.FlagTrustNode)
trustNodeDefined := viper.IsSet(flags.FlagTrustNode)
if !trustNodeDefined {
return nil
}

trustNode := viper.GetBool(client.FlagTrustNode)
trustNode := viper.GetBool(flags.FlagTrustNode)
if trustNode {
return nil
}

chainID := viper.GetString(client.FlagChainID)
home := viper.GetString(cli.HomeFlag)
nodeURI := viper.GetString(client.FlagNode)
chainID := viper.GetString(flags.FlagChainID)
home := viper.GetString(flags.FlagHome)
nodeURI := viper.GetString(flags.FlagNode)

var errMsg bytes.Buffer
if chainID == "" {
Expand Down
8 changes: 3 additions & 5 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package context

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"strings"

"github.com/pkg/errors"

"strings"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
cmn "github.com/tendermint/tendermint/libs/common"
Expand All @@ -19,6 +15,8 @@ import (
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
)

// GetNode returns an RPC client. If the context's client is not defined, an
Expand Down
9 changes: 0 additions & 9 deletions client/errors.go

This file was deleted.

5 changes: 4 additions & 1 deletion client/flags.go → client/flags/flags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package client
package flags

import (
"fmt"
Expand All @@ -7,6 +7,8 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/viper"

tmcli "github.com/tendermint/tendermint/libs/cli"
)

// nolint
Expand All @@ -28,6 +30,7 @@ const (
// immediately.
BroadcastAsync = "async"

FlagHome = tmcli.HomeFlag
FlagUseLedger = "ledger"
FlagChainID = "chain-id"
FlagNode = "node"
Expand Down
Loading