Skip to content

Commit

Permalink
Fix transaction status for EVM compatibility (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanliqun authored Aug 6, 2024
1 parent 1859e63 commit c52f7b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions rpc/cfxbridge/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Conflux-Chain/go-conflux-sdk/types/cmptutil"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
gethTypes "github.com/ethereum/go-ethereum/core/types"
ethTypes "github.com/openweb3/web3go/types"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -84,9 +85,9 @@ func ConvertTxStatusNullable(value *uint64) (status *hexutil.Uint64) {
}

switch {
case *value == 0: // eth tx status `failed`
case *value == gethTypes.ReceiptStatusFailed: // eth tx status `failed`
status = &txnStatusFailed
case *value == 1: // eth tx status `success`
case *value == gethTypes.ReceiptStatusSuccessful: // eth tx status `success`
status = &txnStatusSuccess
default:
logrus.WithField("ethTxStatus", *value).Error("Unexpected tx status from eth space")
Expand Down
14 changes: 14 additions & 0 deletions sync/sync_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,20 @@ func (syncer *EthSyncer) convertToEpochData(ethData *store.EthData) *store.Epoch
epochData.ReceiptExts[txHash] = store.ExtractEthReceiptExt(rcpt)
}

// Transaction `status` field is not a standard field for evm-compatible chain, so we have
// to manually fill this field from their receipt.
for i := range pivotBlock.Transactions {
if pivotBlock.Transactions[i].Status != nil {
continue
}

txnHash := pivotBlock.Transactions[i].Hash
if rcpt, ok := epochData.Receipts[txnHash]; ok && rcpt != nil {
txnStatus := rcpt.OutcomeStatus
pivotBlock.Transactions[i].Status = &txnStatus
}
}

return epochData
}

Expand Down

0 comments on commit c52f7b5

Please sign in to comment.