Merge branch 'roy/upgrade-to-v0.46' of github.com:vulcanize/chiba-clonk into roy/upgrade-to-v0.46

This commit is contained in:
Sai Kumar 2022-05-16 20:18:06 +05:30
commit 49cd996e80
9 changed files with 53 additions and 63 deletions

View File

@ -17,20 +17,11 @@ import (
"github.com/tharsis/ethermint/ethereum/eip712"
ethermint "github.com/tharsis/ethermint/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
)
var ethermintCodec codec.ProtoCodecMarshaler
func init() {
registry := codectypes.NewInterfaceRegistry()
ethermint.RegisterInterfaces(registry)
ethermintCodec = codec.NewProtoCodec(registry)
}
// Eip712SigVerificationMiddleware Verify all signatures for a tx and return an error if any are invalid. Note,
// the Eip712SigVerificationMiddleware middleware will not get executed on ReCheck.
//

View File

@ -5,22 +5,17 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/std"
sdk "github.com/cosmos/cosmos-sdk/types"
cryptocodec "github.com/tharsis/ethermint/crypto/codec"
ethermint "github.com/tharsis/ethermint/types"
)
// RegisterLegacyAminoCodec registers Interfaces from types, crypto, and SDK std.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
sdk.RegisterLegacyAminoCodec(cdc)
cryptocodec.RegisterCrypto(cdc)
codec.RegisterEvidences(cdc)
std.RegisterLegacyAminoCodec(cdc)
}
// RegisterInterfaces registers Interfaces from types, crypto, and SDK std.
func RegisterInterfaces(interfaceRegistry codectypes.InterfaceRegistry) {
sdk.RegisterInterfaces(interfaceRegistry)
std.RegisterInterfaces(interfaceRegistry)
cryptocodec.RegisterInterfaces(interfaceRegistry)
ethermint.RegisterInterfaces(interfaceRegistry)

View File

@ -391,7 +391,7 @@ func (api *PublicFilterAPI) Logs(ctx context.Context, crit filters.FilterCriteri
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
return
}
@ -467,7 +467,7 @@ func (api *PublicFilterAPI) NewFilter(criteria filters.FilterCriteria) (rpc.ID,
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
return
}

View File

@ -10,6 +10,7 @@ import (
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
tmquery "github.com/tendermint/tendermint/libs/pubsub/query"
coretypes "github.com/tendermint/tendermint/rpc/coretypes"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
tmtypes "github.com/tendermint/tendermint/types"
@ -27,7 +28,7 @@ import (
var (
txEvents = tmtypes.QueryForEvent(tmtypes.EventTxValue).String()
evmEvents = fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTx, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)
evmEvents = tmquery.MustCompile(fmt.Sprintf("%s='%s' AND %s.%s='%s'", tmtypes.EventTypeKey, tmtypes.EventTxValue, sdk.EventTypeMessage, sdk.AttributeKeyModule, evmtypes.ModuleName)).String()
headerEvents = tmtypes.QueryForEvent(tmtypes.EventNewBlockHeaderValue).String()
)

View File

@ -536,7 +536,7 @@ func (api *pubSubAPI) subscribeLogs(wsConn *wsConn, subID rpc.ID, extra interfac
continue
}
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data)
txResponse, err := evmtypes.DecodeTxResponse(dataTx.TxResult.Result.Data, api.clientCtx.Codec)
if err != nil {
api.logger.Error("failed to decode tx response", "error", err.Error())
return

View File

@ -19,8 +19,7 @@ var _ types.MsgServer = &Keeper{}
// EthereumTx implements the gRPC MsgServer interface. It receives a transaction which is then
// executed (i.e applied) against the go-ethereum EVM. The provided SDK Context is set to the Keeper
// so that it can implements and call the StateDB methods without receiving it as a function
// parameter.
// so that it can call the StateDB methods without receiving it as a function parameter.
func (k *Keeper) EthereumTx(goCtx context.Context, msg *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

View File

@ -1,7 +1,6 @@
package types
import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@ -10,9 +9,8 @@ import (
proto "github.com/gogo/protobuf/proto"
)
var ModuleCdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry())
type (
TxResponse interface{}
ExtensionOptionsEthereumTxI interface{}
)
@ -22,11 +20,6 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
(*sdk.Msg)(nil),
&MsgEthereumTx{},
)
registry.RegisterInterface(
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
(*ExtensionOptionsEthereumTxI)(nil),
&ExtensionOptionsEthereumTx{},
)
registry.RegisterImplementations(
(*tx.TxExtensionOptionI)(nil),
&ExtensionOptionsEthereumTx{},
@ -38,6 +31,16 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
&AccessListTx{},
&LegacyTx{},
)
registry.RegisterInterface(
"ethermint.evm.v1.MsgEthereumTxResponse",
(*TxResponse)(nil),
&MsgEthereumTxResponse{},
)
registry.RegisterInterface(
"ethermint.evm.v1.ExtensionOptionsEthereumTx",
(*ExtensionOptionsEthereumTxI)(nil),
&ExtensionOptionsEthereumTx{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

View File

@ -6,8 +6,8 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
@ -18,25 +18,27 @@ const maxBitLen = 256
var EmptyCodeHash = crypto.Keccak256(nil)
// DecodeTxResponse decodes an protobuf-encoded byte slice into TxResponse
func DecodeTxResponse(in []byte) (*MsgEthereumTxResponse, error) {
func DecodeTxResponse(in []byte, cdc codec.Codec) (*MsgEthereumTxResponse, error) {
var txMsgData sdk.TxMsgData
if err := proto.Unmarshal(in, &txMsgData); err != nil {
if err := txMsgData.Unmarshal(in); err != nil {
return nil, err
}
data := txMsgData.GetData()
if len(data) == 0 {
return &MsgEthereumTxResponse{}, nil
responses := txMsgData.GetMsgResponses()
if len(responses) == 0 {
return nil, nil
}
var res MsgEthereumTxResponse
err := proto.Unmarshal(data[0].GetData(), &res)
if err != nil {
return nil, sdkerrors.Wrap(err, "failed to unmarshal tx response message data")
if err := cdc.UnpackAny(responses[0], new(TxResponse)); err != nil {
return nil, fmt.Errorf("failed to unmarshal tx response message: %w", err)
}
return &res, nil
msgval := responses[0].GetCachedValue()
res, ok := msgval.(*MsgEthereumTxResponse)
if !ok {
return nil, fmt.Errorf("tx response message has invalid type: %T", msgval)
}
return res, nil
}
// EncodeTransactionLogs encodes TransactionLogs slice into a protobuf-encoded byte slice.
@ -44,16 +46,6 @@ func EncodeTransactionLogs(res *TransactionLogs) ([]byte, error) {
return proto.Marshal(res)
}
// DecodeTxResponse decodes an protobuf-encoded byte slice into TransactionLogs
func DecodeTransactionLogs(data []byte) (TransactionLogs, error) {
var logs TransactionLogs
err := proto.Unmarshal(data, &logs)
if err != nil {
return TransactionLogs{}, err
}
return logs, nil
}
// UnwrapEthereumMsg extract MsgEthereumTx from wrapping sdk.Tx
func UnwrapEthereumMsg(tx *sdk.Tx, ethHash common.Hash) (*MsgEthereumTx, error) {
if tx == nil {

View File

@ -5,23 +5,33 @@ import (
"math/big"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
proto "github.com/gogo/protobuf/proto"
"github.com/tharsis/ethermint/app"
"github.com/tharsis/ethermint/encoding"
evmtypes "github.com/tharsis/ethermint/x/evm/types"
"github.com/stretchr/testify/require"
"github.com/ethereum/go-ethereum/common"
)
var testCodec codec.Codec
func init() {
registry := codectypes.NewInterfaceRegistry()
evmtypes.RegisterInterfaces(registry)
testCodec = codec.NewProtoCodec(registry)
}
func TestEvmDataEncoding(t *testing.T) {
ret := []byte{0x5, 0x8}
data := &evmtypes.MsgEthereumTxResponse{
resp := &evmtypes.MsgEthereumTxResponse{
Hash: common.BytesToHash([]byte("hash")).String(),
Logs: []*evmtypes.Log{{
Data: []byte{1, 2, 3, 4},
@ -30,21 +40,20 @@ func TestEvmDataEncoding(t *testing.T) {
Ret: ret,
}
enc, err := proto.Marshal(data)
any, err := codectypes.NewAnyWithValue(resp)
require.NoError(t, err)
txData := &sdk.TxMsgData{
Data: []*sdk.MsgData{{MsgType: evmtypes.TypeMsgEthereumTx, Data: enc}},
MsgResponses: []*codectypes.Any{any},
}
txDataBz, err := proto.Marshal(txData)
txDataBz, err := txData.Marshal()
require.NoError(t, err)
res, err := evmtypes.DecodeTxResponse(txDataBz)
decoded, err := evmtypes.DecodeTxResponse(txDataBz, testCodec)
require.NoError(t, err)
require.NotNil(t, res)
require.Equal(t, data.Logs, res.Logs)
require.Equal(t, ret, res.Ret)
require.NotNil(t, decoded)
require.Equal(t, resp.Logs, decoded.Logs)
require.Equal(t, ret, decoded.Ret)
}
func TestUnwrapEthererumMsg(t *testing.T) {