fix(simapp): do not overwrite tx options (#17920)

This commit is contained in:
Julien Robert 2023-09-29 12:03:24 +02:00 committed by GitHub
parent c889a07ef2
commit b478f26888
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 748 additions and 443 deletions

View File

@ -2723,9 +2723,9 @@ const (
SignMode_SIGN_MODE_DIRECT SignMode = 1
// SIGN_MODE_TEXTUAL is a future signing mode that will verify some
// human-readable textual representation on top of the binary representation
// from SIGN_MODE_DIRECT. It is currently experimental, and should be used
// for testing purposes only, until Textual is fully released. Please follow
// the tracking issue https://github.com/cosmos/cosmos-sdk/issues/11970.
// from SIGN_MODE_DIRECT.
//
// Since: cosmos-sdk 0.50
SignMode_SIGN_MODE_TEXTUAL SignMode = 2
// SIGN_MODE_DIRECT_AUX specifies a signing mode which uses
// SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not

File diff suppressed because it is too large Load Diff

View File

@ -35,8 +35,6 @@ const (
// SignModeDirectAux is the value of the --sign-mode flag for SIGN_MODE_DIRECT_AUX
SignModeDirectAux = "direct-aux"
// SignModeTextual is the value of the --sign-mode flag for SIGN_MODE_TEXTUAL.
// Choosing this flag will result in an error for now, as Textual should be
// used only for TESTING purposes for now.
SignModeTextual = "textual"
// SignModeEIP191 is the value of the --sign-mode flag for SIGN_MODE_EIP_191
SignModeEIP191 = "eip-191"

View File

@ -25,9 +25,9 @@ enum SignMode {
// SIGN_MODE_TEXTUAL is a future signing mode that will verify some
// human-readable textual representation on top of the binary representation
// from SIGN_MODE_DIRECT. It is currently experimental, and should be used
// for testing purposes only, until Textual is fully released. Please follow
// the tracking issue https://github.com/cosmos/cosmos-sdk/issues/11970.
// from SIGN_MODE_DIRECT.
//
// Since: cosmos-sdk 0.50
SIGN_MODE_TEXTUAL = 2;
// SIGN_MODE_DIRECT_AUX specifies a signing mode which uses

View File

@ -40,6 +40,7 @@ func NewRootCmd() *cobra.Command {
initClientCtx := client.Context{}.
WithCodec(encodingConfig.Codec).
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).

View File

@ -31,12 +31,10 @@ import (
// NewRootCmd creates a new root command for simd. It is called once in the main function.
func NewRootCmd() *cobra.Command {
var (
interfaceRegistry codectypes.InterfaceRegistry
appCodec codec.Codec
txConfig client.TxConfig
txConfigOpts tx.ConfigOptions
autoCliOpts autocli.AppOptions
moduleBasicManager module.BasicManager
clientCtx *client.Context
initClientCtx *client.Context
)
if err := depinject.Inject(
@ -50,12 +48,10 @@ func NewRootCmd() *cobra.Command {
ProvideKeyring,
),
),
&interfaceRegistry,
&appCodec,
&txConfig,
&txConfigOpts,
&autoCliOpts,
&moduleBasicManager,
&clientCtx,
&initClientCtx,
); err != nil {
panic(err)
}
@ -69,35 +65,32 @@ func NewRootCmd() *cobra.Command {
cmd.SetOut(cmd.OutOrStdout())
cmd.SetErr(cmd.ErrOrStderr())
initClientCtx := *clientCtx
initClientCtx = initClientCtx.WithCmdContext(cmd.Context())
initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags())
clientCtx := *initClientCtx
clientCtx = clientCtx.WithCmdContext(cmd.Context())
clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, cmd.Flags())
if err != nil {
return err
}
customClientTemplate, customClientConfig := initClientConfig()
initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig)
clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig)
if err != nil {
return err
}
// This needs to go after CreateClientConfig, as that function
// sets the RPC client needed for SIGN_MODE_TEXTUAL.
enabledSignModes := append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx),
}
// This needs to go after CreateClientConfig, as that function sets the RPC client needed for SIGN_MODE_TEXTUAL.
txConfigOpts.EnabledSignModes = append(txConfigOpts.EnabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts.TextualCoinMetadataQueryFn = txmodule.NewGRPCCoinMetadataQueryFn(clientCtx)
txConfigWithTextual, err := tx.NewTxConfigWithOptions(
codec.NewProtoCodec(interfaceRegistry),
codec.NewProtoCodec(clientCtx.InterfaceRegistry),
txConfigOpts,
)
if err != nil {
return err
}
initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual)
if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil {
clientCtx = clientCtx.WithTxConfig(txConfigWithTextual)
if err := client.SetCmdClientContextHandler(clientCtx, cmd); err != nil {
return err
}
@ -108,7 +101,7 @@ func NewRootCmd() *cobra.Command {
},
}
initRootCmd(rootCmd, txConfig, interfaceRegistry, appCodec, moduleBasicManager)
initRootCmd(rootCmd, initClientCtx.TxConfig, initClientCtx.InterfaceRegistry, initClientCtx.Codec, moduleBasicManager)
if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
@ -120,6 +113,7 @@ func NewRootCmd() *cobra.Command {
func ProvideClientContext(
appCodec codec.Codec,
interfaceRegistry codectypes.InterfaceRegistry,
txConfig client.TxConfig,
legacyAmino *codec.LegacyAmino,
addressCodec address.Codec,
validatorAddressCodec runtime.ValidatorAddressCodec,
@ -127,9 +121,10 @@ func ProvideClientContext(
) *client.Context {
var err error
initClientCtx := client.Context{}.
clientCtx := client.Context{}.
WithCodec(appCodec).
WithInterfaceRegistry(interfaceRegistry).
WithTxConfig(txConfig).
WithLegacyAmino(legacyAmino).
WithInput(os.Stdin).
WithAccountRetriever(types.AccountRetriever{}).
@ -141,12 +136,12 @@ func ProvideClientContext(
// Read the config to overwrite the default values with the values from the config file
customClientTemplate, customClientConfig := initClientConfig()
initClientCtx, err = config.CreateClientConfig(initClientCtx, customClientTemplate, customClientConfig)
clientCtx, err = config.CreateClientConfig(clientCtx, customClientTemplate, customClientConfig)
if err != nil {
panic(err)
}
return &initClientCtx
return &clientCtx
}
func ProvideKeyring(clientCtx *client.Context, addressCodec address.Codec) (clientv2keyring.Keyring, error) {

View File

@ -43,9 +43,9 @@ const (
SignMode_SIGN_MODE_DIRECT SignMode = 1
// SIGN_MODE_TEXTUAL is a future signing mode that will verify some
// human-readable textual representation on top of the binary representation
// from SIGN_MODE_DIRECT. It is currently experimental, and should be used
// for testing purposes only, until Textual is fully released. Please follow
// the tracking issue https://github.com/cosmos/cosmos-sdk/issues/11970.
// from SIGN_MODE_DIRECT.
//
// Since: cosmos-sdk 0.50
SignMode_SIGN_MODE_TEXTUAL SignMode = 2
// SIGN_MODE_DIRECT_AUX specifies a signing mode which uses
// SignDocDirectAux. As opposed to SIGN_MODE_DIRECT, this sign mode does not

View File

@ -55,8 +55,9 @@ type ModuleInputs struct {
type ModuleOutputs struct {
depinject.Out
TxConfig client.TxConfig
BaseAppOption runtime.BaseAppOption
TxConfig client.TxConfig
TxConfigOptions tx.ConfigOptions
BaseAppOption runtime.BaseAppOption
}
func ProvideProtoRegistry() txsigning.ProtoFileResolver {
@ -129,7 +130,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
app.SetTxEncoder(txConfig.TxEncoder())
}
return ModuleOutputs{TxConfig: txConfig, BaseAppOption: baseAppOption}
return ModuleOutputs{TxConfig: txConfig, TxConfigOptions: txConfigOptions, BaseAppOption: baseAppOption}
}
func newAnteHandler(txConfig client.TxConfig, in ModuleInputs) (sdk.AnteHandler, error) {