encoding: rm MsgEthereumTx
custom support in TxConfig
(#714)
* remove MsgEthereumTx support in TxConfig Closes: #711 * changelog
This commit is contained in:
parent
19bc44a226
commit
d1446fc1f4
@ -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
|
||||
|
||||
|
@ -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
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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 := ðtypes.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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user