Skip to content

Commit db1899c

Browse files
pulluribBhanu Pullurimacfarla
authored
Expose revert reason field through GraphQL (#7677)
Signed-off-by: Bhanu Pulluri <[email protected]> Co-authored-by: Bhanu Pulluri <[email protected]> Co-authored-by: Sally MacFarlane <[email protected]>
1 parent 5f6f7a0 commit db1899c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/graphql/internal/pojoadapter/TransactionAdapter.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.hyperledger.besu.ethereum.core.BlockHeader;
2727
import org.hyperledger.besu.ethereum.core.LogWithMetadata;
2828
import org.hyperledger.besu.ethereum.core.Transaction;
29+
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
2930
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
3031
import org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput;
3132

@@ -292,6 +293,23 @@ public Optional<Long> getStatus(final DataFetchingEnvironment environment) {
292293
: Optional.of((long) receipt.getStatus()));
293294
}
294295

296+
/**
297+
* Retrieves the revert reason of the transaction, if any.
298+
*
299+
* <p>This method uses the getReceipt method to get the receipt of the transaction. It then checks
300+
* the revert reason of the receipt. It would be an empty Optional for successful transactions.
301+
* Otherwise, it returns an Optional containing the revert reason.
302+
*
303+
* @param environment the data fetching environment.
304+
* @return an Optional containing a Bytes object representing the revert reason of the
305+
* transaction, or an empty Optional .
306+
*/
307+
public Optional<Bytes> getRevertReason(final DataFetchingEnvironment environment) {
308+
return getReceipt(environment)
309+
.map(TransactionReceiptWithMetadata::getReceipt)
310+
.flatMap(TransactionReceipt::getRevertReason);
311+
}
312+
295313
/**
296314
* Retrieves the gas used by the transaction.
297315
*

ethereum/api/src/main/resources/schema.graphqls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ type Transaction {
579579
BlobVersionedHashes is a set of hash outputs from the blobs in the transaction.
580580
"""
581581
blobVersionedHashes: [Bytes32!]
582+
583+
"""Reason returned when transaction fails."""
584+
revertReason: Bytes
582585
}
583586

584587
"""EIP-4895"""

0 commit comments

Comments
 (0)