Skip to content

Commit

Permalink
fix to check failed tx
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jul 17, 2024
1 parent 5e9f4ac commit 33fded6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion indexer/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion indexer/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 33fded6

Please sign in to comment.