Skip to content

Commit cfab9c8

Browse files
committed
refactor: inverted dependecy
1 parent d6e7fb6 commit cfab9c8

11 files changed

Lines changed: 43 additions & 59 deletions

File tree

rpc/backend/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121

2222
"github.com/cosmos/evm/mempool/txpool"
2323
"github.com/cosmos/evm/rpc/types"
24-
"github.com/cosmos/evm/rpc/types/interfaces"
2524
"github.com/cosmos/evm/server/config"
2625
servertypes "github.com/cosmos/evm/server/types"
2726
evmtypes "github.com/cosmos/evm/x/vm/types"
@@ -77,7 +76,7 @@ type EVMBackend interface {
7776
CometBlockByHash(ctx context.Context, blockHash common.Hash) (*tmrpctypes.ResultBlock, error)
7877
BlockNumberFromComet(ctx context.Context, blockNrOrHash types.BlockNumberOrHash) (types.BlockNumber, error)
7978
BlockNumberFromCometByHash(ctx context.Context, blockHash common.Hash) (*big.Int, error)
80-
EthMsgsFromCometBlock(ctx context.Context, block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []interfaces.IMsgEthereumTx
79+
EthMsgsFromCometBlock(ctx context.Context, block *tmrpctypes.ResultBlock, blockRes *tmrpctypes.ResultBlockResults) []evmtypes.IMsgEthereumTx
8180
BlockBloomFromCometBlock(ctx context.Context, blockRes *tmrpctypes.ResultBlockResults) (ethtypes.Bloom, error)
8281
HeaderByNumber(ctx context.Context, blockNum types.BlockNumber) (*ethtypes.Header, error)
8382
HeaderByHash(ctx context.Context, blockHash common.Hash) (*ethtypes.Header, error)

rpc/backend/comet_to_eth.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
1818

1919
rpctypes "github.com/cosmos/evm/rpc/types"
20-
"github.com/cosmos/evm/rpc/types/interfaces"
2120
evmtrace "github.com/cosmos/evm/trace"
2221
evmtypes "github.com/cosmos/evm/x/vm/types"
2322

@@ -107,10 +106,10 @@ func (b *Backend) EthMsgsFromCometBlock(
107106
ctx context.Context,
108107
resBlock *cmtrpctypes.ResultBlock,
109108
blockRes *cmtrpctypes.ResultBlockResults,
110-
) []interfaces.IMsgEthereumTx {
109+
) []evmtypes.IMsgEthereumTx {
111110
_, span := tracer.Start(ctx, "EthMsgsFromCometBlock")
112111
defer span.End()
113-
var result []interfaces.IMsgEthereumTx
112+
var result []evmtypes.IMsgEthereumTx
114113
block := resBlock.Block
115114

116115
txResults := blockRes.TxsResults
@@ -131,7 +130,7 @@ func (b *Backend) EthMsgsFromCometBlock(
131130
}
132131

133132
for _, msg := range tx.GetMsgs() {
134-
ethMsg, ok := msg.(interfaces.IMsgEthereumTx)
133+
ethMsg, ok := msg.(evmtypes.IMsgEthereumTx)
135134
if !ok {
136135
continue
137136
}
@@ -255,7 +254,7 @@ func (b *Backend) ReceiptsFromCometBlock(
255254
ctx context.Context,
256255
resBlock *cmtrpctypes.ResultBlock,
257256
blockRes *cmtrpctypes.ResultBlockResults,
258-
msgs []interfaces.IMsgEthereumTx,
257+
msgs []evmtypes.IMsgEthereumTx,
259258
) (result []*ethtypes.Receipt, err error) {
260259
ctx, span := tracer.Start(ctx, "ReceiptsFromCometBlock")
261260
defer func() { evmtrace.EndSpanErr(span, err) }()

rpc/backend/tx_info.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/cosmos/evm/mempool/txpool"
2424
rpctypes "github.com/cosmos/evm/rpc/types"
25-
"github.com/cosmos/evm/rpc/types/interfaces"
2625
servertypes "github.com/cosmos/evm/server/types"
2726
evmtrace "github.com/cosmos/evm/trace"
2827
"github.com/cosmos/evm/utils"
@@ -54,7 +53,7 @@ func (b *Backend) GetTransactionByHash(ctx context.Context, txHash common.Hash)
5453
}
5554

5655
// the `res.MsgIndex` is inferred from tx index, should be within the bound.
57-
msg, ok := tx.GetMsgs()[res.MsgIndex].(interfaces.IMsgEthereumTx)
56+
msg, ok := tx.GetMsgs()[res.MsgIndex].(evmtypes.IMsgEthereumTx)
5857
if !ok {
5958
return nil, errors.New("invalid ethereum tx")
6059
}
@@ -195,8 +194,8 @@ func (b *Backend) GetTransactionReceipt(ctx context.Context, hash common.Hash) (
195194
return nil, fmt.Errorf("block result not found at height %d: %w", res.Height, err)
196195
}
197196

198-
ethMsg := tx.GetMsgs()[res.MsgIndex].(interfaces.IMsgEthereumTx)
199-
receipts, err := b.ReceiptsFromCometBlock(ctx, resBlock, blockRes, []interfaces.IMsgEthereumTx{ethMsg})
197+
ethMsg := tx.GetMsgs()[res.MsgIndex].(evmtypes.IMsgEthereumTx)
198+
receipts, err := b.ReceiptsFromCometBlock(ctx, resBlock, blockRes, []evmtypes.IMsgEthereumTx{ethMsg})
200199
if err != nil {
201200
return nil, fmt.Errorf("failed to get receipts from comet block")
202201
}
@@ -392,7 +391,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(ctx context.Context, block *cmtr
392391
return nil, nil
393392
}
394393

395-
var msg interfaces.IMsgEthereumTx
394+
var msg evmtypes.IMsgEthereumTx
396395
// find in tx indexer
397396
res, err := b.GetTxByTxIndex(ctx, block.Block.Height, uint(idx))
398397
if err == nil {
@@ -404,7 +403,7 @@ func (b *Backend) GetTransactionByBlockAndIndex(ctx context.Context, block *cmtr
404403

405404
var ok bool
406405
// msgIndex is inferred from tx events, should be within bound.
407-
msg, ok = tx.GetMsgs()[res.MsgIndex].(interfaces.IMsgEthereumTx)
406+
msg, ok = tx.GetMsgs()[res.MsgIndex].(evmtypes.IMsgEthereumTx)
408407
if !ok {
409408
b.Logger.Debug("invalid ethereum tx", "height", block.Block.Header, "index", idx)
410409
return nil, nil

rpc/backend/tx_info_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/cosmos/evm/indexer"
2525
"github.com/cosmos/evm/rpc/backend/mocks"
2626
rpctypes "github.com/cosmos/evm/rpc/types"
27-
"github.com/cosmos/evm/rpc/types/interfaces"
2827
servertypes "github.com/cosmos/evm/server/types"
2928
"github.com/cosmos/evm/testutil/constants"
3029
utiltx "github.com/cosmos/evm/testutil/tx"
@@ -499,7 +498,7 @@ func TestReceiptsFromCometBlock(t *testing.T) {
499498
}
500499
for _, tc := range tcs {
501500
t.Run(tc.name, func(t *testing.T) {
502-
msgs := []interfaces.IMsgEthereumTx{
501+
msgs := []evmtypes.IMsgEthereumTx{
503502
buildMsgEthereumTx(t),
504503
}
505504
expectedTxResult := &servertypes.TxResult{
@@ -590,7 +589,7 @@ func TestReceiptsLogIndexBlockGlobal(t *testing.T) {
590589
mockEVMQueryClient := backend.QueryClient.QueryClient.(*mocks.EVMQueryClient)
591590
mockEVMQueryClient.On("BaseFee", mock.Anything, mock.Anything).Return(&evmtypes.QueryBaseFeeResponse{}, nil)
592591

593-
msgs := []interfaces.IMsgEthereumTx{msg0, msg1}
592+
msgs := []evmtypes.IMsgEthereumTx{msg0, msg1}
594593
receipts, err := backend.ReceiptsFromCometBlock(rpctypes.NewContextWithHeight(1), resBlock, blockRes, msgs)
595594
require.NoError(t, err)
596595
require.Len(t, receipts, 2)

rpc/backend/utils.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
2121

2222
"github.com/cosmos/evm/rpc/types"
23-
"github.com/cosmos/evm/rpc/types/interfaces"
2423
evmtrace "github.com/cosmos/evm/trace"
2524
"github.com/cosmos/evm/utils"
2625
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
@@ -96,7 +95,7 @@ func (b *Backend) getAccountNonce(ctx context.Context, accAddr common.Address, p
9695
// only supports `MsgEthereumTx` style tx
9796
for _, tx := range pendingTxs {
9897
for _, msg := range (*tx).GetMsgs() {
99-
ethMsg, ok := msg.(interfaces.IMsgEthereumTx)
98+
ethMsg, ok := msg.(evmtypes.IMsgEthereumTx)
10099
if !ok {
101100
// not ethereum tx
102101
break
@@ -256,7 +255,7 @@ func (b *Backend) ProcessBlock(
256255
}
257256
txGasUsed := uint64(cometTxResult.GasUsed) // #nosec G115
258257
for _, msg := range tx.GetMsgs() {
259-
ethMsg, ok := msg.(interfaces.IMsgEthereumTx)
258+
ethMsg, ok := msg.(evmtypes.IMsgEthereumTx)
260259
if !ok {
261260
continue
262261
}

rpc/types/events.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
abci "github.com/cometbft/cometbft/abci/types"
1010
cmtrpctypes "github.com/cometbft/cometbft/rpc/core/types"
1111

12-
"github.com/cosmos/evm/rpc/types/interfaces"
1312
"github.com/cosmos/evm/server/types"
1413
evmtypes "github.com/cosmos/evm/x/vm/types"
1514

@@ -134,7 +133,7 @@ func ParseTxResult(result *abci.ExecTxResult, tx sdk.Tx) (*ParsedTxs, error) {
134133
p.Txs[i].Failed = true
135134

136135
// replace gasUsed with gasLimit because that's what's actually deducted.
137-
gasLimit := tx.GetMsgs()[i].(interfaces.IMsgEthereumTx).GetGas()
136+
gasLimit := tx.GetMsgs()[i].(evmtypes.IMsgEthereumTx).GetGas()
138137
p.Txs[i].GasUsed = gasLimit
139138
}
140139
}

rpc/types/interfaces/interface.go

Lines changed: 0 additions & 22 deletions
This file was deleted.

rpc/types/utils.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
cmtrpccore "github.com/cometbft/cometbft/rpc/core/types"
1919
cmttypes "github.com/cometbft/cometbft/types"
2020

21-
"github.com/cosmos/evm/rpc/types/interfaces"
2221
evmtrace "github.com/cosmos/evm/trace"
2322
feemarkettypes "github.com/cosmos/evm/x/feemarket/types"
2423
evmtypes "github.com/cosmos/evm/x/vm/types"
@@ -31,15 +30,15 @@ import (
3130
)
3231

3332
// RawTxToEthTx returns a evm MsgEthereum transaction from raw tx bytes.
34-
func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]interfaces.IMsgEthereumTx, error) {
33+
func RawTxToEthTx(clientCtx client.Context, txBz cmttypes.Tx) ([]evmtypes.IMsgEthereumTx, error) {
3534
tx, err := clientCtx.TxConfig.TxDecoder()(txBz)
3635
if err != nil {
3736
return nil, errorsmod.Wrap(errortypes.ErrJSONUnmarshal, err.Error())
3837
}
3938

40-
ethTxs := make([]interfaces.IMsgEthereumTx, len(tx.GetMsgs()))
39+
ethTxs := make([]evmtypes.IMsgEthereumTx, len(tx.GetMsgs()))
4140
for i, msg := range tx.GetMsgs() {
42-
ethTx, ok := msg.(interfaces.IMsgEthereumTx)
41+
ethTx, ok := msg.(evmtypes.IMsgEthereumTx)
4342
if !ok {
4443
return nil, fmt.Errorf("invalid message type %T, expected %T", msg, &evmtypes.MsgEthereumTx{})
4544
}
@@ -153,7 +152,7 @@ func MakeHeader(
153152
// NewTransactionFromMsg returns a transaction that will serialize to the RPC
154153
// representation, with the given location metadata set (if available).
155154
func NewTransactionFromMsg(
156-
msg interfaces.IMsgEthereumTx,
155+
msg evmtypes.IMsgEthereumTx,
157156
blockHash common.Hash,
158157
blockNumber, blockTime, index uint64,
159158
baseFee *big.Int,
@@ -411,7 +410,7 @@ func RPCMarshalHeader(head *ethtypes.Header, blockHash []byte) map[string]interf
411410
//
412411
// This method refers to go-ethereum v1.16.3 internal package method - RPCMarshalBlock
413412
// (https://github.com/ethereum/go-ethereum/blob/d818a9af7bd5919808df78f31580f59382c53150/internal/ethapi/api.go#L929-L962)
414-
func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, msgs []interfaces.IMsgEthereumTx, inclTx bool, fullTx bool, config *ethparams.ChainConfig) (map[string]interface{}, error) {
413+
func RPCMarshalBlock(block *ethtypes.Block, cmtBlock *cmtrpccore.ResultBlock, msgs []evmtypes.IMsgEthereumTx, inclTx bool, fullTx bool, config *ethparams.ChainConfig) (map[string]interface{}, error) {
415414
blockHash := cmtBlock.BlockID.Hash.Bytes()
416415
fields := RPCMarshalHeader(block.Header(), blockHash)
417416
fields["size"] = hexutil.Uint64(block.Size())

tests/integration/rpc/backend/test_backend_suite.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
rpcbackend "github.com/cosmos/evm/rpc/backend"
2424
"github.com/cosmos/evm/rpc/backend/mocks"
2525
rpctypes "github.com/cosmos/evm/rpc/types"
26-
"github.com/cosmos/evm/rpc/types/interfaces"
2726
"github.com/cosmos/evm/testutil/constants"
2827
"github.com/cosmos/evm/testutil/integration/evm/network"
2928
utiltx "github.com/cosmos/evm/testutil/tx"
@@ -182,9 +181,9 @@ func (s *TestSuite) buildFormattedBlock(
182181
validator sdk.AccAddress,
183182
baseFee *big.Int,
184183
) map[string]interface{} {
185-
var msgs []interfaces.IMsgEthereumTx
184+
var msgs []evmtypes.IMsgEthereumTx
186185
if tx != nil {
187-
msgs = []interfaces.IMsgEthereumTx{tx}
186+
msgs = []evmtypes.IMsgEthereumTx{tx}
188187
}
189188
ethBlock := s.buildEthBlock(blockRes, resBlock, msgs, validator, baseFee)
190189
res, err := rpctypes.RPCMarshalBlock(ethBlock, resBlock, msgs, true, fullTx, s.backend.ChainConfig())
@@ -196,7 +195,7 @@ func (s *TestSuite) buildFormattedBlock(
196195
func (s *TestSuite) buildEthBlock(
197196
blockRes *cmtrpctypes.ResultBlockResults,
198197
resBlock *cmtrpctypes.ResultBlock,
199-
msgs []interfaces.IMsgEthereumTx,
198+
msgs []evmtypes.IMsgEthereumTx,
200199
validator sdk.AccAddress,
201200
baseFee *big.Int,
202201
) *ethtypes.Block {

x/vm/types/msg.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
protov2 "google.golang.org/protobuf/proto"
1414

1515
evmapi "github.com/cosmos/evm/api/cosmos/evm/vm/v1"
16-
"github.com/cosmos/evm/rpc/types/interfaces"
1716

1817
errorsmod "cosmossdk.io/errors"
1918
sdkmath "cosmossdk.io/math"
@@ -31,11 +30,11 @@ import (
3130
)
3231

3332
var (
34-
_ sdk.Msg = &MsgEthereumTx{}
35-
_ sdk.Tx = &MsgEthereumTx{}
36-
_ ante.GasTx = &MsgEthereumTx{}
37-
_ interfaces.IMsgEthereumTx = &MsgEthereumTx{}
38-
_ sdk.Msg = &MsgUpdateParams{}
33+
_ sdk.Msg = &MsgEthereumTx{}
34+
_ sdk.Tx = &MsgEthereumTx{}
35+
_ ante.GasTx = &MsgEthereumTx{}
36+
_ IMsgEthereumTx = &MsgEthereumTx{}
37+
_ sdk.Msg = &MsgUpdateParams{}
3938
)
4039

4140
// message type and route constants

0 commit comments

Comments
 (0)