Skip to content

Commit

Permalink
Merge pull request #50 from fullkomnun/handle_contract_call_reverts
Browse files Browse the repository at this point in the history
Handle contract calls reverts properly
  • Loading branch information
josh-richardson authored Sep 17, 2020
2 parents 1e9444f + 07c528b commit aa929f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/web3j/quorum/tx/ClientTransactionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.DefaultBlockParameter;
import org.web3j.protocol.core.methods.request.Transaction;
import org.web3j.protocol.core.methods.response.EthCall;
import org.web3j.protocol.core.methods.response.EthGetCode;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.quorum.Quorum;
import org.web3j.quorum.methods.request.PrivateTransaction;
import org.web3j.tx.ContractErrorUtil;
import org.web3j.tx.TransactionManager;

/** TransactionManager implementation for using a Quorum node to transact. */
Expand Down Expand Up @@ -112,11 +114,13 @@ public EthSendTransaction sendTransaction(
@Override
public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter)
throws IOException {
return quorum.ethCall(
Transaction.createEthCallTransaction(getFromAddress(), to, data),
defaultBlockParameter)
.send()
.getValue();
EthCall ethCall =
quorum.ethCall(
Transaction.createEthCallTransaction(getFromAddress(), to, data),
defaultBlockParameter)
.send();
ContractErrorUtil.assertCallNotReverted(ethCall);
return ethCall.getValue();
}

@Override
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/org/web3j/tx/ContractErrorUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2020 Web3 Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
@file:JvmName("ContractErrorUtil")

package org.web3j.tx

import org.web3j.protocol.core.methods.response.EthCall

fun assertCallNotReverted(ethCall: EthCall) = TransactionManager.assertCallNotReverted(ethCall)

0 comments on commit aa929f4

Please sign in to comment.