From bff1d823f5c57057de1b8e7e91cbe1d0c31dac49 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 24 Jan 2024 11:52:07 +0100 Subject: [PATCH] refactor(client/v2,simapp): align and simplify sign mode wiring (#19216) --- client/v2/CHANGELOG.md | 3 ++- client/v2/autocli/app.go | 5 ----- client/v2/autocli/builder.go | 4 ---- client/v2/autocli/msg.go | 22 ---------------------- simapp/simd/cmd/root.go | 4 ++-- simapp/simd/cmd/root_v2.go | 2 +- 6 files changed, 5 insertions(+), 35 deletions(-) diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index ca9f5f529e..3d2b21baa3 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -47,7 +47,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 diff --git a/client/v2/autocli/app.go b/client/v2/autocli/app.go index 31c2a5b176..9f3207e53a 100644 --- a/client/v2/autocli/app.go +++ b/client/v2/autocli/app.go @@ -10,7 +10,6 @@ import ( "cosmossdk.io/client/v2/autocli/keyring" "cosmossdk.io/core/appmodule" "cosmossdk.io/depinject" - "cosmossdk.io/x/auth/tx" "github.com/cosmos/cosmos-sdk/client" sdkflags "github.com/cosmos/cosmos-sdk/client/flags" @@ -41,9 +40,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, @@ -71,7 +67,6 @@ func (appOptions AppOptions) EnhanceRootCommand(rootCmd *cobra.Command) error { ValidatorAddressCodec: appOptions.ClientCtx.ValidatorAddressCodec, ConsensusAddressCodec: appOptions.ClientCtx.ConsensusAddressCodec, }, - TxConfigOpts: appOptions.TxConfigOpts, GetClientConn: func(cmd *cobra.Command) (grpc.ClientConnInterface, error) { return client.GetClientQueryContext(cmd) }, diff --git a/client/v2/autocli/builder.go b/client/v2/autocli/builder.go index b9981ab6c0..81604f0d81 100644 --- a/client/v2/autocli/builder.go +++ b/client/v2/autocli/builder.go @@ -5,7 +5,6 @@ import ( "google.golang.org/grpc" "cosmossdk.io/client/v2/autocli/flag" - authtx "cosmossdk.io/x/auth/tx" ) // Builder manages options for building CLI commands. @@ -17,9 +16,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) diff --git a/client/v2/autocli/msg.go b/client/v2/autocli/msg.go index 4b1078861f..e9f07d668f 100644 --- a/client/v2/autocli/msg.go +++ b/client/v2/autocli/msg.go @@ -16,8 +16,6 @@ import ( "cosmossdk.io/client/v2/internal/flags" "cosmossdk.io/client/v2/internal/util" addresscodec "cosmossdk.io/core/address" - authtx "cosmossdk.io/x/auth/tx" - authtxconfig "cosmossdk.io/x/auth/tx/config" // the following will be extracted to a separate module // https://github.com/cosmos/cosmos-sdk/issues/14403 @@ -27,8 +25,6 @@ import ( "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" ) // BuildMsgCommand builds the msg commands for all the provided modules. If a custom command is provided for a @@ -130,24 +126,6 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor clientCtx = clientCtx.WithCmdContext(cmd.Context()) clientCtx = clientCtx.WithOutput(cmd.OutOrStdout()) - // 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. - if !clientCtx.Offline { - b.TxConfigOpts.EnabledSignModes = append(b.TxConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) - b.TxConfigOpts.TextualCoinMetadataQueryFn = authtxconfig.NewGRPCCoinMetadataQueryFn(clientCtx) - - txConfig, err := authtx.NewTxConfigWithOptions( - codec.NewProtoCodec(clientCtx.InterfaceRegistry), - b.TxConfigOpts, - ) - if err != nil { - return err - } - - clientCtx = clientCtx.WithTxConfig(txConfig) - } - fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor()))) addressCodec := b.Builder.AddressCodec diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index fbc9ab430a..d66a4accfd 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -12,7 +12,7 @@ import ( "cosmossdk.io/simapp" "cosmossdk.io/simapp/params" "cosmossdk.io/x/auth/tx" - txmodule "cosmossdk.io/x/auth/tx/config" + authtxconfig "cosmossdk.io/x/auth/tx/config" "cosmossdk.io/x/auth/types" "github.com/cosmos/cosmos-sdk/client" @@ -79,7 +79,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, diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 48f5039ab9..252656fdc2 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -125,7 +125,7 @@ func ProvideClientContext( panic(err) } - // 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 {