Search in sources :

Example 1 with ReadonlyTransactionManager

use of org.web3j.tx.ReadonlyTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class AccumulatorService method subscribeTo.

public Disposable subscribeTo(QuorumNetworkProperty.Node node, String contractAddress, List<Accumulator.IncEventEventResponse> list) {
    Quorum client = connectionFactory().getConnection(node, POLLING_INTERVAL);
    String address;
    try {
        address = client.ethCoinbase().send().getAddress();
        ReadonlyTransactionManager txManager = new ReadonlyTransactionManager(client, address);
        Accumulator acc = Accumulator.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT);
        return acc.incEventEventFlowable(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST).subscribe(list::add);
    } catch (Exception e) {
        logger.error("accumulator.subscribe()", e);
        throw new RuntimeException(e);
    }
}
Also used : Accumulator(com.quorum.gauge.sol.Accumulator) Quorum(org.web3j.quorum.Quorum) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException)

Example 2 with ReadonlyTransactionManager

use of org.web3j.tx.ReadonlyTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class AccumulatorService method get.

public int get(QuorumNetworkProperty.Node node, String contractAddress) {
    Quorum client = connectionFactory().getConnection(node);
    String address;
    try {
        address = client.ethCoinbase().send().getAddress();
        ReadonlyTransactionManager txManager = new ReadonlyTransactionManager(client, address);
        return Accumulator.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).get().send().intValue();
    } catch (ContractCallException cce) {
        if (cce.getMessage().contains("Empty value (0x)")) {
            return 0;
        }
        logger.error("accumulator.get()", cce);
        throw new RuntimeException(cce);
    } catch (Exception e) {
        logger.error("accumulator.get()", e);
        throw new RuntimeException(e);
    }
}
Also used : Quorum(org.web3j.quorum.Quorum) ContractCallException(org.web3j.tx.exceptions.ContractCallException) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException)

Example 3 with ReadonlyTransactionManager

use of org.web3j.tx.ReadonlyTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class ContractService method readSimpleContractValue.

// Read-only contract
public int readSimpleContractValue(QuorumNode node, String contractAddress) {
    Quorum client = connectionFactory().getConnection(node);
    String address;
    try {
        address = client.ethCoinbase().send().getAddress();
        ReadonlyTransactionManager txManager = new ReadonlyTransactionManager(client, address);
        return SimpleStorage.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).get().send().intValue();
    } catch (ContractCallException cce) {
        if (cce.getMessage().contains("Empty value (0x)")) {
            return 0;
        }
        logger.error("readSimpleContractValue()", cce);
        throw new RuntimeException(cce);
    } catch (Exception e) {
        logger.error("readSimpleContractValue()", e);
        throw new RuntimeException(e);
    }
}
Also used : Quorum(org.web3j.quorum.Quorum) ContractCallException(org.web3j.tx.exceptions.ContractCallException) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException) IOException(java.io.IOException)

Example 4 with ReadonlyTransactionManager

use of org.web3j.tx.ReadonlyTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class NestedContractService method readC2Value.

// Read-only contract
public int readC2Value(QuorumNode node, String contractAddress) {
    Quorum client = connectionFactory().getConnection(node);
    String address;
    try {
        address = client.ethCoinbase().send().getAddress();
        ReadonlyTransactionManager txManager = new ReadonlyTransactionManager(client, address);
        return C2.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).get().send().intValue();
    } catch (ContractCallException cce) {
        if (cce.getMessage().contains("Empty value (0x)")) {
            return 0;
        }
        logger.error("readSimpleContractValue()", cce);
        throw new RuntimeException(cce);
    } catch (Exception e) {
        logger.error("readSimpleContractValue()", e);
        throw new RuntimeException(e);
    }
}
Also used : Quorum(org.web3j.quorum.Quorum) ContractCallException(org.web3j.tx.exceptions.ContractCallException) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException)

Example 5 with ReadonlyTransactionManager

use of org.web3j.tx.ReadonlyTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class ContractService method readGenericStoreContractGetValue.

public int readGenericStoreContractGetValue(QuorumNode node, String contractAddress, String contractName, String methodName) {
    Quorum client = connectionFactory().getConnection(node);
    String address;
    try {
        address = client.ethCoinbase().send().getAddress();
        ReadonlyTransactionManager txManager = new ReadonlyTransactionManager(client, address);
        switch(contractName.toLowerCase().trim()) {
            case "storea":
                switch(methodName.toLowerCase().trim()) {
                    case "geta":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).geta().send().intValue();
                    case "getb":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).getb().send().intValue();
                    case "getc":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).getc().send().intValue();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            case "storeb":
                switch(methodName.toLowerCase().trim()) {
                    case "getb":
                        return Storeb.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).getb().send().intValue();
                    case "getc":
                        return Storeb.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).getc().send().intValue();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            case "storec":
                switch(methodName.toLowerCase().trim()) {
                    case "getc":
                        return Storec.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).getc().send().intValue();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            default:
                throw new Exception("invalid contract name ");
        }
    } catch (Exception e) {
        logger.debug("readStoreContractValue() " + contractName + " " + methodName, e);
        throw new RuntimeException(e);
    }
}
Also used : Quorum(org.web3j.quorum.Quorum) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException) IOException(java.io.IOException)

Aggregations

ReadonlyTransactionManager (org.web3j.tx.ReadonlyTransactionManager)9 Quorum (org.web3j.quorum.Quorum)8 ContractCallException (org.web3j.tx.exceptions.ContractCallException)8 IOException (java.io.IOException)3 Accumulator (com.quorum.gauge.sol.Accumulator)1 BigInteger (java.math.BigInteger)1 CipherException (org.web3j.crypto.CipherException)1 Web3j (org.web3j.protocol.Web3j)1 RlpString (org.web3j.rlp.RlpString)1 StaticGasProvider (org.web3j.tx.gas.StaticGasProvider)1