Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
encoding: rm MsgEthereumTx custom support in TxConfig (#714)
Browse files Browse the repository at this point in the history
* remove MsgEthereumTx support in TxConfig

Closes: #711

* changelog
  • Loading branch information
yihuang committed Nov 2, 2021
1 parent 19bc44a commit d1446fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 58 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [tharsis#671](https://github.com/tharsis/ethermint/pull/671) Don't pass base fee externally for `EthCall`/`EthEstimateGas` apis.
* (evm) [tharsis#674](https://github.com/tharsis/ethermint/pull/674) Refactor `ApplyMessage`, remove
`ApplyNativeMessage`.
* (rpc) [tharsis#714](https://github.com/tharsis/ethermint/pull/714) remove `MsgEthereumTx` support in `TxConfig`

## [v0.7.2] - 2021-10-24

Expand Down
53 changes: 2 additions & 51 deletions encoding/config.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package encoding

import (
"github.com/cosmos/cosmos-sdk/client"
amino "github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/simapp/params"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"

ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/cosmos/cosmos-sdk/x/auth/tx"

enccodec "github.com/tharsis/ethermint/encoding/codec"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)

// MakeConfig creates an EncodingConfig for testing
Expand All @@ -24,7 +19,7 @@ func MakeConfig(mb module.BasicManager) params.EncodingConfig {
encodingConfig := params.EncodingConfig{
InterfaceRegistry: interfaceRegistry,
Marshaler: marshaler,
TxConfig: NewTxConfig(marshaler),
TxConfig: tx.NewTxConfig(marshaler, tx.DefaultSignModes),
Amino: cdc,
}

Expand All @@ -34,47 +29,3 @@ func MakeConfig(mb module.BasicManager) params.EncodingConfig {
mb.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}

type txConfig struct {
cdc amino.ProtoCodecMarshaler
client.TxConfig
}

// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The
// first enabled sign mode will become the default sign mode.
func NewTxConfig(marshaler amino.ProtoCodecMarshaler) client.TxConfig {
return &txConfig{
marshaler,
authtx.NewTxConfig(marshaler, authtx.DefaultSignModes),
}
}

// TxEncoder overwrites sdk.TxEncoder to support MsgEthereumTx
func (g txConfig) TxEncoder() sdk.TxEncoder {
return func(tx sdk.Tx) ([]byte, error) {
msg, ok := tx.(*evmtypes.MsgEthereumTx)
if ok {
return msg.AsTransaction().MarshalBinary()
}
return g.TxConfig.TxEncoder()(tx)
}
}

// TxDecoder overwrites sdk.TxDecoder to support MsgEthereumTx
func (g txConfig) TxDecoder() sdk.TxDecoder {
return func(txBytes []byte) (sdk.Tx, error) {
tx := &ethtypes.Transaction{}

err := tx.UnmarshalBinary(txBytes)
if err == nil {
msg := &evmtypes.MsgEthereumTx{}
err := msg.FromEthereumTx(tx)
if err != nil {
return nil, err
}
return msg, nil
}

return g.TxConfig.TxDecoder()(txBytes)
}
}
9 changes: 2 additions & 7 deletions encoding/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,8 @@ func TestTxEncoding(t *testing.T) {

cfg := encoding.MakeConfig(app.ModuleBasics)

bz, err := cfg.TxConfig.TxEncoder()(msg)
require.NoError(t, err, "encoding failed")

tx, err := cfg.TxConfig.TxDecoder()(bz)
require.NoError(t, err, "decoding failed")
require.IsType(t, &evmtypes.MsgEthereumTx{}, tx)
require.Equal(t, msg.Data, tx.(*evmtypes.MsgEthereumTx).Data)
_, err = cfg.TxConfig.TxEncoder()(msg)
require.Error(t, err, "encoding failed")

// FIXME: transaction hashing is hardcoded on Terndermint:
// See https://github.com/tendermint/tendermint/issues/6539 for reference
Expand Down

0 comments on commit d1446fc

Please sign in to comment.