From 1bc33eba9da10d94a1e5398c55a34cec0f1eb47b Mon Sep 17 00:00:00 2001 From: Marri Harish Date: Mon, 23 Sep 2024 22:29:17 +0530 Subject: [PATCH] autocli: fix unjail transaction signing issue (#193) --- cmd/omniflixhubd/cmd/root.go | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/cmd/omniflixhubd/cmd/root.go b/cmd/omniflixhubd/cmd/root.go index 79ceb94..f39e837 100644 --- a/cmd/omniflixhubd/cmd/root.go +++ b/cmd/omniflixhubd/cmd/root.go @@ -35,8 +35,11 @@ import ( "github.com/cosmos/cosmos-sdk/server" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/tx/signing" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtxconfig "github.com/cosmos/cosmos-sdk/x/auth/tx/config" "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/crisis" genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli" @@ -104,9 +107,29 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { if err != nil { return err } - if err := client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { + + // This needs to go after ReadFromClientConfig, as that function + // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode + // is only available if the client is online. + if !initClientCtx.Offline { + txConfigOpts := tx.ConfigOptions{ + EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL), + TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), + } + txConfigWithTextual, err := tx.NewTxConfigWithOptions( + initClientCtx.Codec, + txConfigOpts, + ) + if err != nil { + return err + } + initClientCtx = initClientCtx.WithTxConfig(txConfigWithTextual) + } + + if err = client.SetCmdClientContextHandler(initClientCtx, cmd); err != nil { return err } + appTemplate, appConfig := initAppConfig() customTMConfig := initCometBftConfig() return server.InterceptConfigsPreRunHandler(cmd, appTemplate, appConfig, customTMConfig) @@ -116,7 +139,8 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) { initRootCmd(rootCmd, encodingConfig, tempApp) // must need as part of cosmos-sdk 0.50.x migration - if err := autoCliOpts(initClientCtx, tempApp).EnhanceRootCommand(rootCmd); err != nil { + autocliOptions := autoCliOpts(initClientCtx, tempApp) + if err := autocliOptions.EnhanceRootCommand(rootCmd); err != nil { panic(err) } @@ -345,5 +369,9 @@ func autoCliOpts(initClientCtx client.Context, tempApp *app.OmniFlixApp) autocli ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ClientCtx: initClientCtx, + TxConfigOpts: tx.ConfigOptions{ + EnabledSignModes: tx.DefaultSignModes, + TextualCoinMetadataQueryFn: authtxconfig.NewGRPCCoinMetadataQueryFn(initClientCtx), + }, } }