From 33fded615795716edcfd717721a53610d0d097d9 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Wed, 17 Jul 2024 13:25:55 +0900 Subject: [PATCH] fix to check failed tx --- indexer/abci.go | 2 +- indexer/utils.go | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/indexer/abci.go b/indexer/abci.go index 4f5810b..e8318c4 100644 --- a/indexer/abci.go +++ b/indexer/abci.go @@ -63,7 +63,7 @@ func (e *EVMIndexerImpl) ListenFinalizeBlock(ctx context.Context, req abci.Reque ethTxs = append(ethTxs, ethTx) // extract logs and contract address from tx results - ethLogs, contractAddr, err := extractLogsAndContractAddr(txResults.Data, ethTx.To() == nil) + ethLogs, contractAddr, err := extractLogsAndContractAddr(txStatus, txResults.Data, ethTx.To() == nil) if err != nil { e.logger.Error("failed to extract logs and contract address", "err", err) return err diff --git a/indexer/utils.go b/indexer/utils.go index bdce58f..5a9fb37 100644 --- a/indexer/utils.go +++ b/indexer/utils.go @@ -8,14 +8,21 @@ import ( collcodec "cosmossdk.io/collections/codec" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/gogoproto/proto" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" coretypes "github.com/ethereum/go-ethereum/core/types" + "github.com/initia-labs/minievm/x/evm/types" ) -func extractLogsAndContractAddr(data []byte, isContractCreation bool) ([]*coretypes.Log, *common.Address, error) { +func extractLogsAndContractAddr(txStatus uint64, data []byte, isContractCreation bool) ([]*coretypes.Log, *common.Address, error) { + if txStatus != coretypes.ReceiptStatusSuccessful { + return nil, nil, nil + } + var ethLogs []*coretypes.Log var contractAddr *common.Address @@ -47,6 +54,10 @@ func unpackData(data []byte, resp proto.Message) error { return err } + if len(txMsgData.MsgResponses) == 0 { + return sdkerrors.ErrLogic.Wrap("failed to unpack data; got nil Msg response") + } + msgResp := txMsgData.MsgResponses[0] expectedTypeUrl := sdk.MsgTypeURL(resp) if msgResp.TypeUrl != expectedTypeUrl {