diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ca67bb764..372dbc4ac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (rpc) [#516](https://github.com/crypto-org-chain/ethermint/pull/516) Avoid method eth_chainId crashed due to nil pointer on IsEIP155 check. * (cli) [#524](https://github.com/crypto-org-chain/ethermint/pull/524) Allow tx evm raw run for generate only when offline with evm-denom flag. * (rpc) [#527](https://github.com/crypto-org-chain/ethermint/pull/527) Fix balance consistency between trace-block and state machine. +* (cli) [#537](https://github.com/crypto-org-chain/ethermint/pull/537) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer. ### Improvements diff --git a/app/app.go b/app/app.go index f3033bbba6..112f7f1b11 100644 --- a/app/app.go +++ b/app/app.go @@ -23,6 +23,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "sort" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" @@ -31,6 +32,7 @@ import ( "cosmossdk.io/core/appmodule" runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" "github.com/cosmos/cosmos-sdk/server" + sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/gogoproto/proto" "github.com/gorilla/mux" @@ -75,6 +77,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -380,6 +383,21 @@ func NewEthermintApp( authAddr, logger, ) + // optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper) + enabledSignModes := slices.Clone(authtx.DefaultSignModes) + enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL) + txConfigOpts := authtx.ConfigOptions{ + EnabledSignModes: enabledSignModes, + TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper), + } + txConfig, err := authtx.NewTxConfigWithOptions( + appCodec, + txConfigOpts, + ) + if err != nil { + panic(err) + } + app.txConfig = txConfig app.StakingKeeper = stakingkeeper.NewKeeper( appCodec, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), diff --git a/cmd/ethermintd/root.go b/cmd/ethermintd/root.go index 9b87971820..02501654da 100644 --- a/cmd/ethermintd/root.go +++ b/cmd/ethermintd/root.go @@ -19,6 +19,7 @@ import ( "errors" "io" "os" + "slices" "github.com/spf13/cobra" @@ -43,6 +44,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/client/debug" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/cosmos/cosmos-sdk/types/tx/signing" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -65,14 +67,13 @@ const ( ChainID = "ethermint_9000-1" ) -type emptyAppOptions struct{} - -func (ao emptyAppOptions) Get(_ string) interface{} { return nil } - // NewRootCmd creates a new root command for simd. It is called once in the // main function. func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) { - tempApp := app.NewEthermintApp(cmtlog.NewNopLogger(), dbm.NewMemDB(), nil, true, emptyAppOptions{}) + tempApp := app.NewEthermintApp( + cmtlog.NewNopLogger(), dbm.NewMemDB(), nil, true, + simtestutil.NewAppOptionsWithFlagHome(app.DefaultNodeHome), + ) encodingConfig := tempApp.EncodingConfig() initClientCtx := client.Context{}. WithCodec(encodingConfig.Codec). @@ -86,6 +87,11 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) { WithKeyringOptions(hd.EthSecp256k1Option()). WithViper(EnvPrefix) + initClientCtx, err := clientcfg.ReadDefaultValuesFromDefaultClientConfig(initClientCtx) + if err != nil { + panic(err) + } + eip712.SetEncodingConfig(encodingConfig) rootCmd := &cobra.Command{ @@ -96,6 +102,7 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) { cmd.SetOut(cmd.OutOrStdout()) cmd.SetErr(cmd.ErrOrStderr()) + initClientCtx = initClientCtx.WithCmdContext(cmd.Context()) initClientCtx, err := client.ReadPersistentCommandFlags(initClientCtx, cmd.Flags()) if err != nil { return err @@ -110,8 +117,10 @@ func NewRootCmd() (*cobra.Command, ethermint.EncodingConfig) { // sets the RPC client needed for SIGN_MODE_TEXTUAL. This sign mode // is only available if the client is online. if !initClientCtx.Offline { + enabledSignModes := slices.Clone(tx.DefaultSignModes) + enabledSignModes = append(enabledSignModes, signing.SignMode_SIGN_MODE_TEXTUAL) txConfigOpts := tx.ConfigOptions{ - EnabledSignModes: append(tx.DefaultSignModes, signing.SignMode_SIGN_MODE_TEXTUAL), + EnabledSignModes: enabledSignModes, TextualCoinMetadataQueryFn: txmodule.NewGRPCCoinMetadataQueryFn(initClientCtx), } txConfig, err := tx.NewTxConfigWithOptions( diff --git a/tests/integration_tests/test_batch.py b/tests/integration_tests/test_batch.py index 80181d45c0..b43934a5b4 100644 --- a/tests/integration_tests/test_batch.py +++ b/tests/integration_tests/test_batch.py @@ -119,3 +119,15 @@ def test_multisig(ethermint, tmp_path): cli.account(multi_addr)["account"]["value"]["base_account"]["address"] == acc["address"] ) + + +def test_textual(ethermint): + cli = ethermint.cosmos_cli() + rsp = cli.transfer( + cli.address("validator"), + cli.address("signer2"), + "1aphoton", + sign_mode="textual", + ) + print("mm-rsp", rsp) + assert rsp["code"] == 0, rsp["raw_log"]