Skip to content

Commit

Permalink
refactor(client/v2,simapp): align and simplify sign mode wiring (#19216)
Browse files Browse the repository at this point in the history
(cherry picked from commit bff1d82)

# Conflicts:
#	client/v2/autocli/builder.go
#	client/v2/autocli/msg.go
#	simapp/simd/cmd/root.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Jan 24, 2024
1 parent 8dcd61b commit ff8f4f8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
3 changes: 2 additions & 1 deletion client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements

* [#19060](https://github.com/cosmos/cosmos-sdk/pull/19060) Use client context from root (or enhanced) command in autocli commands.
* Note, the given command must have a `client.Context` in its context.
* Note, the given command must have a `client.Context` in its context.
* [#19216](https://github.com/cosmos/cosmos-sdk/pull/19216) Do not overwrite TxConfig, use directly the one provided in context. TxConfig should always be set in the `client.Context` in `root.go` of an app.

### Bug Fixes

Expand Down
4 changes: 0 additions & 4 deletions client/v2/autocli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ type AppOptions struct {

// ClientCtx contains the necessary information needed to execute the commands.
ClientCtx client.Context

// TxConfigOptions are the transactions config options.
TxConfigOpts tx.ConfigOptions
}

// EnhanceRootCommand enhances the provided root command with autocli AppOptions,
Expand Down Expand Up @@ -78,7 +75,6 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error {
ConsensusAddressCodec: appOptions.ConsensusAddressCodec,
Keyring: appOptions.Keyring,
},
TxConfigOpts: appOptions.TxConfigOpts,
GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) {
return client.GetClientQueryContext(cmd)
},
Expand Down
6 changes: 3 additions & 3 deletions client/v2/autocli/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"google.golang.org/grpc"

"cosmossdk.io/client/v2/autocli/flag"
<<<<<<< HEAD

authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
=======
>>>>>>> bff1d823f (refactor(client/v2,simapp): align and simplify sign mode wiring (#19216))
)

// Builder manages options for building CLI commands.
Expand All @@ -18,9 +21,6 @@ type Builder struct {
// from a given context.
GetClientConn func(*cobra.Command) (grpc.ClientConnInterface, error)

// TxConfigOptions is required to support sign mode textual
TxConfigOpts authtx.ConfigOptions

// AddQueryConnFlags and AddTxConnFlags are functions that add flags to query and transaction commands
AddQueryConnFlags func(*cobra.Command)
AddTxConnFlags func(*cobra.Command)
Expand Down
23 changes: 23 additions & 0 deletions client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,26 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/autocli/flag"
"cosmossdk.io/client/v2/internal/util"
<<<<<<< HEAD

"github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
=======
addresscodec "cosmossdk.io/core/address"

// the following will be extracted to a separate module
// https://github.com/cosmos/cosmos-sdk/issues/14403
authtypes "cosmossdk.io/x/auth/types"
govcli "cosmossdk.io/x/gov/client/cli"
govtypes "cosmossdk.io/x/gov/types"

"github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
>>>>>>> bff1d823f (refactor(client/v2,simapp): align and simplify sign mode wiring (#19216))
)

// BuildMsgCommand builds the msg commands for all the provided modules. If a custom command is provided for a
Expand Down Expand Up @@ -121,6 +134,7 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
clientCtx = clientCtx.WithCmdContext(cmd.Context())
clientCtx = clientCtx.WithOutput(cmd.OutOrStdout())

<<<<<<< HEAD
// enable sign mode textual
// the config is always overwritten as we need to have set the flags to the client context
// this ensures that the context has the correct client.
Expand All @@ -137,6 +151,15 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
}

clientCtx = clientCtx.WithTxConfig(txConfig)
=======
fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor())))
addressCodec := b.Builder.AddressCodec

// handle gov proposals commands
skipProposal, _ := cmd.Flags().GetBool(flags.FlagNoProposal)
if options.GovProposal && !skipProposal {
return b.handleGovProposal(options, cmd, input, clientCtx, addressCodec, fd)
>>>>>>> bff1d823f (refactor(client/v2,simapp): align and simplify sign mode wiring (#19216))
}

// set signer to signer field if empty
Expand Down
8 changes: 7 additions & 1 deletion simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ import (
"cosmossdk.io/log"
"cosmossdk.io/simapp"
"cosmossdk.io/simapp/params"
<<<<<<< HEAD
dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cobra"
=======
"cosmossdk.io/x/auth/tx"
authtxconfig "cosmossdk.io/x/auth/tx/config"
"cosmossdk.io/x/auth/types"
>>>>>>> bff1d823f (refactor(client/v2,simapp): align and simplify sign mode wiring (#19216))

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand Down Expand Up @@ -72,7 +78,7 @@ func NewRootCmd() *cobra.Command {
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx),
}
txConfig, err := tx.NewTxConfigWithOptions(
initClientCtx.Codec,
Expand Down
2 changes: 1 addition & 1 deletion simapp/simd/cmd/root_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func ProvideClientContext(
// Read the config again to overwrite the default values with the values from the config file
clientCtx, _ = config.ReadFromClientConfig(clientCtx)

// re-create the tx config grpc instead of bank keeper
// textual is enabled by default, we need to re-create the tx config grpc instead of bank keeper.
txConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx)
txConfig, err := tx.NewTxConfigWithOptions(clientCtx.Codec, txConfigOpts)
if err != nil {
Expand Down

0 comments on commit ff8f4f8

Please sign in to comment.