Skip to content

Commit be15e90

Browse files
committed
Return JSON-RPC error on eth_call revert
1 parent e2502ea commit be15e90

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

rskj-core/src/main/java/co/rsk/rpc/modules/eth/EthModule.java

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.ethereum.rpc.Web3;
3131
import org.ethereum.rpc.converters.CallArgumentsToByteArray;
3232
import org.ethereum.rpc.dto.CompilationResultDTO;
33+
import org.ethereum.rpc.exception.JsonRpcExecutionErrorException;
3334
import org.ethereum.vm.PrecompiledContracts;
3435
import org.ethereum.vm.program.ProgramResult;
3536
import org.slf4j.Logger;
@@ -103,6 +104,10 @@ public String call(Web3.CallArguments args, String bnOrId) {
103104
try {
104105
Block executionBlock = executionBlockRetriever.getExecutionBlock(bnOrId);
105106
ProgramResult res = callConstant(args, executionBlock);
107+
if (res.isRevert()) {
108+
throw new JsonRpcExecutionErrorException.TransactionReverted();
109+
}
110+
106111
return s = toJsonHex(res.getHReturn());
107112
} finally {
108113
LOGGER.debug("eth_call(): {}", s);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of RskJ
3+
* Copyright (C) 2018 RSK Labs Ltd.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.ethereum.rpc.exception;
20+
21+
public class JsonRpcExecutionErrorException extends RskJsonRpcRequestException {
22+
23+
private JsonRpcExecutionErrorException(String message) {
24+
super(-32015, String.format("VM execution error: %s", message));
25+
}
26+
27+
public static class TransactionReverted extends JsonRpcExecutionErrorException {
28+
29+
public TransactionReverted() {
30+
super("transaction reverted");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)