refactor(client/v2,simapp): align and simplify sign mode wiring (#19216)

This commit is contained in:
Julien Robert 2024-01-24 11:52:07 +01:00 committed by GitHub
parent 61c367d9d1
commit bff1d823f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 5 additions and 35 deletions

View File

@ -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

View File

@ -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)
},

View File

@ -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)

View File

@ -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

View File

@ -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,

View File

@ -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 {