From 95bd7563d406a72a3631ef0e76583947929cb850 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 22 Jun 2021 15:49:25 +0800 Subject: [PATCH] rpc: extract msg from cosmos tx (#163) Closes #162 --- ethereum/rpc/eth_api.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ethereum/rpc/eth_api.go b/ethereum/rpc/eth_api.go index 33b8e608c..1fd9364ab 100644 --- a/ethereum/rpc/eth_api.go +++ b/ethereum/rpc/eth_api.go @@ -678,7 +678,11 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*rpctypes.RPCTran return nil, fmt.Errorf("failed to decode tx: %w", err) } - msg, ok := tx.(*evmtypes.MsgEthereumTx) + if len(tx.GetMsgs()) != 1 { + e.logger.Debugln("invalid tx") + return nil, fmt.Errorf("invalid tx type: %T", tx) + } + msg, ok := tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx) if !ok { e.logger.Debugln("invalid tx") return nil, fmt.Errorf("invalid tx type: %T", tx) @@ -763,7 +767,11 @@ func (e *PublicEthAPI) GetTransactionByBlockNumberAndIndex(blockNum rpctypes.Blo return nil, fmt.Errorf("failed to decode tx: %w", err) } - msg, ok := tx.(*evmtypes.MsgEthereumTx) + if len(tx.GetMsgs()) != 1 { + e.logger.Debugln("invalid tx") + return nil, fmt.Errorf("invalid tx type: %T", tx) + } + msg, ok := tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx) if !ok { e.logger.Debugln("invalid tx") return nil, fmt.Errorf("invalid tx type: %T", tx) @@ -805,7 +813,11 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter return nil, fmt.Errorf("failed to decode tx: %w", err) } - msg, ok := tx.(*evmtypes.MsgEthereumTx) + if len(tx.GetMsgs()) != 1 { + e.logger.Debugln("invalid tx") + return nil, fmt.Errorf("invalid tx type: %T", tx) + } + msg, ok := tx.GetMsgs()[0].(*evmtypes.MsgEthereumTx) if !ok { e.logger.Debugln("invalid tx") return nil, fmt.Errorf("invalid tx type: %T", tx)