Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

feat(pkg): TryParsingCustomErrorFromReceipt returns nil #778

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions bindings/encoding/custom_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ import (
"github.com/ethereum/go-ethereum/core/types"
)

// BlockHashContractCallerAndTransactionReader represents a contract caller and transaction reader.
type BlockHashContractCallerAndTransactionReader interface {
// BlockHashContractCallerAndChainReader represents a contract caller and chain reader.
type BlockHashContractCallerAndChainReader interface {
bind.BlockHashContractCaller
ethereum.TransactionReader
ethereum.ChainReader
}

// TryParsingCustomErrorFromReceipt tries to parse the custom error from the given receipt.
func TryParsingCustomErrorFromReceipt(
ctx context.Context,
rpc BlockHashContractCallerAndTransactionReader,
rpc BlockHashContractCallerAndChainReader,
from common.Address,
receipt *types.Receipt,
) error {
// Get the block header of the receipt.
header, err := rpc.HeaderByHash(ctx, receipt.BlockHash)
if err != nil {
return err
}

// Fetch the raw transaction.
tx, _, err := rpc.TransactionByHash(ctx, receipt.TxHash)
if err != nil {
Expand All @@ -42,7 +49,7 @@ func TryParsingCustomErrorFromReceipt(
AccessList: tx.AccessList(),
BlobGasFeeCap: tx.BlobGasFeeCap(),
BlobHashes: tx.BlobHashes(),
}, receipt.BlockHash)
}, header.ParentHash)

return TryParsingCustomError(err)
}
Expand Down
Loading