client: rename CliContext to Context (#6290)
* Refactor CliContext as Context * Fix lint issues * Fix goimports * Fix gov tests * Resolved ci-lint issues * Add changelog * Rename cliCtx to clientCtx * Fix mocks and routes * Add changelog * Update changelog * Apply suggestions from code review Co-authored-by: Alessio Treglia <alessio@tendermint.com> * merge client/rpc/ro{ot,utes}.go * Update docs * client/rpc: remove redundant client/rpc.RegisterRPCRoutes * regenerate mocks * Update ADRs Co-authored-by: Alessio Treglia <alessio@tendermint.com> Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Alessio Treglia
Federico Kunze
mergify[bot]
parent
654b2fdd10
commit
39f53ac22f
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
)
|
||||
|
||||
// GetBroadcastCommand returns the tx broadcast command.
|
||||
@@ -26,28 +26,28 @@ $ <appcli> tx broadcast ./mytxn.json
|
||||
`),
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
|
||||
if cliCtx.Offline {
|
||||
if clientCtx.Offline {
|
||||
return errors.New("cannot broadcast tx during offline mode")
|
||||
}
|
||||
|
||||
stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0])
|
||||
stdTx, err := authclient.ReadStdTxFromFile(clientCtx.Codec, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx)
|
||||
txBytes, err := clientCtx.Codec.MarshalBinaryBare(stdTx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := cliCtx.BroadcastTx(txBytes)
|
||||
res, err := clientCtx.BroadcastTx(txBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cliCtx.PrintOutput(res)
|
||||
return clientCtx.PrintOutput(res)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@@ -31,7 +31,7 @@ func GetDecodeCommand(codec *codec.Codec) *cobra.Command {
|
||||
|
||||
func runDecodeTxString(codec *codec.Codec) func(cmd *cobra.Command, args []string) (err error) {
|
||||
return func(cmd *cobra.Command, args []string) (err error) {
|
||||
cliCtx := context.NewCLIContext().WithCodec(codec).WithOutput(cmd.OutOrStdout())
|
||||
clientCtx := client.NewContext().WithCodec(codec).WithOutput(cmd.OutOrStdout())
|
||||
var txBytes []byte
|
||||
|
||||
if viper.GetBool(flagHex) {
|
||||
@@ -44,11 +44,11 @@ func runDecodeTxString(codec *codec.Codec) func(cmd *cobra.Command, args []strin
|
||||
}
|
||||
|
||||
var stdTx authtypes.StdTx
|
||||
err = cliCtx.Codec.UnmarshalBinaryBare(txBytes, &stdTx)
|
||||
err = clientCtx.Codec.UnmarshalBinaryBare(txBytes, &stdTx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cliCtx.PrintOutput(stdTx)
|
||||
return clientCtx.PrintOutput(stdTx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
)
|
||||
|
||||
// txEncodeRespStr implements a simple Stringer wrapper for a encoded tx.
|
||||
@@ -29,15 +29,15 @@ Read a transaction from <file>, serialize it to the Amino wire protocol, and out
|
||||
If you supply a dash (-) argument in place of an input filename, the command reads from standard input.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
|
||||
stdTx, err := client.ReadStdTxFromFile(cliCtx.Codec, args[0])
|
||||
stdTx, err := authclient.ReadStdTxFromFile(clientCtx.Codec, args[0])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// re-encode it via the Amino wire protocol
|
||||
txBytes, err := cliCtx.Codec.MarshalBinaryBare(stdTx)
|
||||
txBytes, err := clientCtx.Codec.MarshalBinaryBare(stdTx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -46,7 +46,7 @@ If you supply a dash (-) argument in place of an input filename, the command rea
|
||||
txBytesBase64 := base64.StdEncoding.EncodeToString(txBytes)
|
||||
|
||||
response := txEncodeRespStr(txBytesBase64)
|
||||
return cliCtx.PrintOutput(response)
|
||||
return clientCtx.PrintOutput(response)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+12
-13
@@ -9,7 +9,6 @@ import (
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@@ -54,10 +53,10 @@ func QueryParamsCmd(cdc *codec.Codec) *cobra.Command {
|
||||
$ <appcli> query auth params
|
||||
`),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryParams)
|
||||
res, _, err := cliCtx.QueryWithData(route, nil)
|
||||
res, _, err := clientCtx.QueryWithData(route, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -67,7 +66,7 @@ $ <appcli> query auth params
|
||||
return fmt.Errorf("failed to unmarshal params: %w", err)
|
||||
}
|
||||
|
||||
return cliCtx.PrintOutput(params)
|
||||
return clientCtx.PrintOutput(params)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -82,7 +81,7 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
|
||||
Short: "Query for account by address",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
accGetter := types.NewAccountRetriever(authclient.Codec)
|
||||
|
||||
key, err := sdk.AccAddressFromBech32(args[0])
|
||||
@@ -90,12 +89,12 @@ func GetAccountCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
acc, err := accGetter.GetAccount(cliCtx, key)
|
||||
acc, err := accGetter.GetAccount(clientCtx, key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return cliCtx.PrintOutput(acc)
|
||||
return clientCtx.PrintOutput(acc)
|
||||
},
|
||||
}
|
||||
|
||||
@@ -150,14 +149,14 @@ $ %s query txs --%s 'message.sender=cosmos1...&message.action=withdraw_delegator
|
||||
page := viper.GetInt(flags.FlagPage)
|
||||
limit := viper.GetInt(flags.FlagLimit)
|
||||
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
txs, err := authclient.QueryTxsByEvents(cliCtx, tmEvents, page, limit, "")
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
txs, err := authclient.QueryTxsByEvents(clientCtx, tmEvents, page, limit, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var output []byte
|
||||
if cliCtx.Indent {
|
||||
if clientCtx.Indent {
|
||||
output, err = cdc.MarshalJSONIndent(txs, "", " ")
|
||||
} else {
|
||||
output, err = cdc.MarshalJSON(txs)
|
||||
@@ -196,9 +195,9 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
Short: "Query for a transaction by hash in a committed block",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx := context.NewCLIContext().WithCodec(cdc)
|
||||
clientCtx := client.NewContext().WithCodec(cdc)
|
||||
|
||||
output, err := authclient.QueryTx(cliCtx, args[0])
|
||||
output, err := authclient.QueryTx(clientCtx, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -207,7 +206,7 @@ func QueryTxCmd(cdc *codec.Codec) *cobra.Command {
|
||||
return fmt.Errorf("no transaction found with hash %s", args[0])
|
||||
}
|
||||
|
||||
return cliCtx.PrintOutput(output)
|
||||
return clientCtx.PrintOutput(output)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -12,13 +12,13 @@ import (
|
||||
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
@@ -59,7 +59,7 @@ recommended to set such parameters manually.
|
||||
|
||||
func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) (err error) {
|
||||
stdTx, err := client.ReadStdTxFromFile(cdc, args[0])
|
||||
stdTx, err := authclient.ReadStdTxFromFile(cdc, args[0])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -81,11 +81,11 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
|
||||
|
||||
multisigPub := multisigInfo.GetPubKey().(multisig.PubKeyMultisigThreshold)
|
||||
multisigSig := multisig.NewMultisig(len(multisigPub.PubKeys))
|
||||
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)
|
||||
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
|
||||
txBldr := types.NewTxBuilderFromCLI(inBuf)
|
||||
|
||||
if !cliCtx.Offline {
|
||||
accnum, seq, err := types.NewAccountRetriever(client.Codec).GetAccountNumberSequence(cliCtx, multisigInfo.GetAddress())
|
||||
if !clientCtx.Offline {
|
||||
accnum, seq, err := types.NewAccountRetriever(authclient.Codec).GetAccountNumberSequence(clientCtx, multisigInfo.GetAddress())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -119,11 +119,11 @@ func makeMultiSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string)
|
||||
sigOnly := viper.GetBool(flagSigOnly)
|
||||
var json []byte
|
||||
switch {
|
||||
case sigOnly && cliCtx.Indent:
|
||||
case sigOnly && clientCtx.Indent:
|
||||
json, err = cdc.MarshalJSONIndent(newTx.Signatures[0], "", " ")
|
||||
case sigOnly && !cliCtx.Indent:
|
||||
case sigOnly && !clientCtx.Indent:
|
||||
json, err = cdc.MarshalJSON(newTx.Signatures[0])
|
||||
case !sigOnly && cliCtx.Indent:
|
||||
case !sigOnly && clientCtx.Indent:
|
||||
json, err = cdc.MarshalJSONIndent(newTx, "", " ")
|
||||
default:
|
||||
json, err = cdc.MarshalJSON(newTx)
|
||||
|
||||
@@ -73,7 +73,7 @@ func preSignCmd(cmd *cobra.Command, _ []string) {
|
||||
|
||||
func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0])
|
||||
clientCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -91,19 +91,19 @@ func makeSignCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error
|
||||
return err
|
||||
}
|
||||
newTx, err = client.SignStdTxWithSignerAddress(
|
||||
txBldr, cliCtx, multisigAddr, cliCtx.GetFromName(), stdTx, cliCtx.Offline,
|
||||
txBldr, clientCtx, multisigAddr, clientCtx.GetFromName(), stdTx, clientCtx.Offline,
|
||||
)
|
||||
generateSignatureOnly = true
|
||||
} else {
|
||||
appendSig := viper.GetBool(flagAppend) && !generateSignatureOnly
|
||||
newTx, err = client.SignStdTx(txBldr, cliCtx, cliCtx.GetFromName(), stdTx, appendSig, cliCtx.Offline)
|
||||
newTx, err = client.SignStdTx(txBldr, clientCtx, clientCtx.GetFromName(), stdTx, appendSig, clientCtx.Offline)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
json, err := getSignatureJSON(cdc, newTx, cliCtx.Indent, generateSignatureOnly)
|
||||
json, err := getSignatureJSON(cdc, newTx, clientCtx.Indent, generateSignatureOnly)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tendermint/tendermint/crypto/multisig"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/client/context"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
|
||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
@@ -38,12 +38,12 @@ transaction will be not be performed as that will require RPC communication with
|
||||
|
||||
func makeValidateSignaturesCmd(cdc *codec.Codec) func(cmd *cobra.Command, args []string) error {
|
||||
return func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0])
|
||||
clientCtx, txBldr, stdTx, err := readStdTxAndInitContexts(cdc, cmd, args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !printAndValidateSigs(cmd, cliCtx, txBldr.ChainID(), stdTx, cliCtx.Offline) {
|
||||
if !printAndValidateSigs(cmd, clientCtx, txBldr.ChainID(), stdTx, clientCtx.Offline) {
|
||||
return fmt.Errorf("signatures validation failed")
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func makeValidateSignaturesCmd(cdc *codec.Codec) func(cmd *cobra.Command, args [
|
||||
// expected signers. In addition, if offline has not been supplied, the signature is
|
||||
// verified over the transaction sign bytes. Returns false if the validation fails.
|
||||
func printAndValidateSigs(
|
||||
cmd *cobra.Command, cliCtx context.CLIContext, chainID string, stdTx types.StdTx, offline bool,
|
||||
cmd *cobra.Command, clientCtx client.Context, chainID string, stdTx types.StdTx, offline bool,
|
||||
) bool {
|
||||
cmd.Println("Signers:")
|
||||
signers := stdTx.GetSigners()
|
||||
@@ -89,7 +89,7 @@ func printAndValidateSigs(
|
||||
// Validate the actual signature over the transaction bytes since we can
|
||||
// reach out to a full node to query accounts.
|
||||
if !offline && success {
|
||||
acc, err := types.NewAccountRetriever(client.Codec).GetAccount(cliCtx, sigAddr)
|
||||
acc, err := types.NewAccountRetriever(authclient.Codec).GetAccount(clientCtx, sigAddr)
|
||||
if err != nil {
|
||||
cmd.Printf("failed to get account: %s\n", sigAddr)
|
||||
return false
|
||||
@@ -109,7 +109,7 @@ func printAndValidateSigs(
|
||||
multiPK, ok := sig.GetPubKey().(multisig.PubKeyMultisigThreshold)
|
||||
if ok {
|
||||
var multiSig multisig.Multisignature
|
||||
cliCtx.Codec.MustUnmarshalBinaryBare(sig.Signature, &multiSig)
|
||||
clientCtx.Codec.MustUnmarshalBinaryBare(sig.Signature, &multiSig)
|
||||
|
||||
var b strings.Builder
|
||||
b.WriteString("\n MultiSig Signatures:\n")
|
||||
@@ -134,16 +134,16 @@ func printAndValidateSigs(
|
||||
}
|
||||
|
||||
func readStdTxAndInitContexts(cdc *codec.Codec, cmd *cobra.Command, filename string) (
|
||||
context.CLIContext, types.TxBuilder, types.StdTx, error,
|
||||
client.Context, types.TxBuilder, types.StdTx, error,
|
||||
) {
|
||||
stdTx, err := client.ReadStdTxFromFile(cdc, filename)
|
||||
stdTx, err := authclient.ReadStdTxFromFile(cdc, filename)
|
||||
if err != nil {
|
||||
return context.CLIContext{}, types.TxBuilder{}, types.StdTx{}, err
|
||||
return client.Context{}, types.TxBuilder{}, types.StdTx{}, err
|
||||
}
|
||||
|
||||
inBuf := bufio.NewReader(cmd.InOrStdin())
|
||||
cliCtx := context.NewCLIContextWithInput(inBuf).WithCodec(cdc)
|
||||
clientCtx := client.NewContextWithInput(inBuf).WithCodec(cdc)
|
||||
txBldr := types.NewTxBuilderFromCLI(inBuf)
|
||||
|
||||
return cliCtx, txBldr, stdTx, nil
|
||||
return clientCtx, txBldr, stdTx, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user