diff --git a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java index c79e6d1862f..bfa87af15b0 100644 --- a/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java +++ b/rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java @@ -30,6 +30,7 @@ import org.ethereum.rpc.Web3; import org.ethereum.rpc.converters.CallArgumentsToByteArray; import org.ethereum.rpc.dto.CompilationResultDTO; +import org.ethereum.rpc.exception.RskJsonRpcRequestException; import org.ethereum.vm.PrecompiledContracts; import org.ethereum.vm.program.ProgramResult; import org.slf4j.Logger; @@ -103,6 +104,10 @@ public String call(Web3.CallArguments args, String bnOrId) { try { Block executionBlock = executionBlockRetriever.getExecutionBlock(bnOrId); ProgramResult res = callConstant(args, executionBlock); + if (res.isRevert()) { + throw RskJsonRpcRequestException.transactionRevertedExecutionError(); + } + return s = toJsonHex(res.getHReturn()); } finally { LOGGER.debug("eth_call(): {}", s); diff --git a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java index 3d291f403a3..816d79e63a9 100644 --- a/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java +++ b/rskj-core/src/main/java/org/ethereum/rpc/exception/RskJsonRpcRequestException.java @@ -21,4 +21,12 @@ public Integer getCode() { return code; } + public static RskJsonRpcRequestException transactionRevertedExecutionError() { + return executionError("transaction reverted"); + } + + private static RskJsonRpcRequestException executionError(String message) { + return new RskJsonRpcRequestException(-32015, String.format("VM execution error: %s", message)); + } + }