Skip to content

Commit

Permalink
Problem: unsuppored sign mode SIGN_MODE_TEXTUAL in bank transfer (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe authored Oct 4, 2024
1 parent b16b489 commit c4cef0f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"sort"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]),
Expand Down
21 changes: 15 additions & 6 deletions cmd/ethermintd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"errors"
"io"
"os"
"slices"

"github.com/spf13/cobra"

Expand All @@ -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"
Expand All @@ -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).
Expand All @@ -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{
Expand All @@ -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
Expand All @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions tests/integration_tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit c4cef0f

Please sign in to comment.