Expose revert reason field through GraphQL (#7677)

Signed-off-by: Bhanu Pulluri <bhanu.pulluri@kaleido.io>
Co-authored-by: Bhanu Pulluri <bhanu.pulluri@kaleido.io>
Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>
pull/7716/head
Bhanu Pulluri 2 months ago committed by GitHub
parent 5f6f7a077a
commit db1899c227
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java
  2. 3
      ethereum/api/src/main/resources/schema.graphqls

@ -26,6 +26,7 @@ import org.hyperledger.besu.ethereum.api.query.TransactionWithMetadata;
import org.hyperledger.besu.ethereum.core.BlockHeader; import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.LogWithMetadata; import org.hyperledger.besu.ethereum.core.LogWithMetadata;
import org.hyperledger.besu.ethereum.core.Transaction; import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput; import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
@ -292,6 +293,23 @@ public class TransactionAdapter extends AdapterBase {
: Optional.of((long) receipt.getStatus())); : Optional.of((long) receipt.getStatus()));
} }
/**
* Retrieves the revert reason of the transaction, if any.
*
* <p>This method uses the getReceipt method to get the receipt of the transaction. It then checks
* the revert reason of the receipt. It would be an empty Optional for successful transactions.
* Otherwise, it returns an Optional containing the revert reason.
*
* @param environment the data fetching environment.
* @return an Optional containing a Bytes object representing the revert reason of the
* transaction, or an empty Optional .
*/
public Optional<Bytes> getRevertReason(final DataFetchingEnvironment environment) {
return getReceipt(environment)
.map(TransactionReceiptWithMetadata::getReceipt)
.flatMap(TransactionReceipt::getRevertReason);
}
/** /**
* Retrieves the gas used by the transaction. * Retrieves the gas used by the transaction.
* *

@ -579,6 +579,9 @@ type Transaction {
BlobVersionedHashes is a set of hash outputs from the blobs in the transaction. BlobVersionedHashes is a set of hash outputs from the blobs in the transaction.
""" """
blobVersionedHashes: [Bytes32!] blobVersionedHashes: [Bytes32!]
"""Reason returned when transaction fails."""
revertReason: Bytes
} }
"""EIP-4895""" """EIP-4895"""

Loading…
Cancel
Save