Skip to content

Commit

Permalink
Merge pull request #724 from rsksmart/eth_call_revert
Browse files Browse the repository at this point in the history
Return JSON-RPC error on eth_call revert
  • Loading branch information
aeidelman authored and Diego López León committed Jan 4, 2019
2 parents 7fac998 + 3f9e20d commit 745fe8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}

0 comments on commit 745fe8b

Please sign in to comment.