Search in sources :

Example 1 with PrivateClientTransactionManager

use of com.quorum.gauge.ext.PrivateClientTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class AccumulatorService method createAccumulatorPrivateContract.

public Observable<? extends Accumulator> createAccumulatorPrivateContract(QuorumNetworkProperty.Node source, List<QuorumNetworkProperty.Node> targets, BigInteger gas, int initVal, List<PrivacyFlag> flags) {
    Quorum client = connectionFactory().getConnection(source);
    final List<String> privateFor;
    if (null != targets) {
        privateFor = targets.stream().filter(Objects::nonNull).map(q -> privacyService.id(q)).collect(Collectors.toList());
    } else {
        privateFor = null;
    }
    return accountService.getDefaultAccountAddress(source).flatMap(address -> {
        PrivateClientTransactionManager clientTransactionManager = new PrivateClientTransactionManager(client, address, null, privateFor, flags, DEFAULT_MAX_RETRY, DEFAULT_SLEEP_DURATION_IN_MILLIS);
        return Accumulator.deploy(client, clientTransactionManager, BigInteger.valueOf(0), gas, BigInteger.valueOf(initVal)).flowable().toObservable();
    });
}
Also used : Quorum(org.web3j.quorum.Quorum) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager)

Example 2 with PrivateClientTransactionManager

use of com.quorum.gauge.ext.PrivateClientTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class AccumulatorService method incAccumulatorPrivate.

public Observable<TransactionReceipt> incAccumulatorPrivate(final QuorumNetworkProperty.Node source, final List<QuorumNetworkProperty.Node> target, final String contractAddress, final BigInteger gasLimit, final int increment, final List<PrivacyFlag> flags) {
    final Quorum client = connectionFactory().getConnection(source);
    final BigInteger value = BigInteger.valueOf(increment);
    final List<String> privateFor = target.stream().map(q -> privacyService.id(q)).collect(Collectors.toList());
    return accountService.getDefaultAccountAddress(source).flatMap(acctAddress -> {
        PrivateClientTransactionManager txManager = new PrivateClientTransactionManager(client, acctAddress, null, privateFor, flags, DEFAULT_MAX_RETRY, DEFAULT_SLEEP_DURATION_IN_MILLIS);
        Accumulator accumulator = Accumulator.load(contractAddress, client, txManager, BigInteger.ZERO, gasLimit);
        return accumulator.inc(value).flowable().toObservable();
    });
}
Also used : Quorum(org.web3j.quorum.Quorum) Logger(org.slf4j.Logger) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) LoggerFactory(org.slf4j.LoggerFactory) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) ContractCallException(org.web3j.tx.exceptions.ContractCallException) Autowired(org.springframework.beans.factory.annotation.Autowired) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) Collectors(java.util.stream.Collectors) Accumulator(com.quorum.gauge.sol.Accumulator) Objects(java.util.Objects) Disposable(io.reactivex.disposables.Disposable) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) List(java.util.List) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Accumulator(com.quorum.gauge.sol.Accumulator) Quorum(org.web3j.quorum.Quorum) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) BigInteger(java.math.BigInteger)

Example 3 with PrivateClientTransactionManager

use of com.quorum.gauge.ext.PrivateClientTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class ContractService method createSimpleContract.

public Observable<? extends Contract> createSimpleContract(int initialValue, Node source, String ethAccount, String privateFromAliases, List<String> privateForAliases, List<PrivacyFlag> flags, BigInteger gas) {
    if (CollectionUtils.isEmpty(flags)) {
        flags = emptyList();
    }
    Quorum client = connectionFactory().getConnection(source);
    List<PrivacyFlag> finalFlags = flags;
    return accountService.getAccountAddress(source, ethAccount).flatMap(address -> {
        PrivateClientTransactionManager clientTransactionManager = new PrivateClientTransactionManager(client, address, privacyService.id(privateFromAliases), privateForAliases.stream().map(privacyService::id).collect(Collectors.toList()), finalFlags);
        return SimpleStorage.deploy(client, clientTransactionManager, BigInteger.valueOf(0), gas, BigInteger.valueOf(initialValue)).flowable().toObservable();
    });
}
Also used : Quorum(org.web3j.quorum.Quorum) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag)

Example 4 with PrivateClientTransactionManager

use of com.quorum.gauge.ext.PrivateClientTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class ContractService method setGenericStoreContractSetValue.

public Observable<TransactionReceipt> setGenericStoreContractSetValue(QuorumNetworkProperty.Node node, String contractAddress, String contractName, String methodName, int value, boolean isPrivate, QuorumNode target, PrivacyFlag privacyType) {
    Quorum client = connectionFactory().getConnection(node);
    String fromAddress = accountService.getDefaultAccountAddress(node).blockingFirst();
    TransactionManager txManager;
    if (isPrivate) {
        txManager = new PrivateClientTransactionManager(client, fromAddress, null, Arrays.asList(privacyService.id(target)), Arrays.asList(privacyType));
    } else {
        txManager = new PrivateClientTransactionManager(client, fromAddress, null, null, List.of(PrivacyFlag.StandardPrivate));
    }
    try {
        switch(contractName.toLowerCase().trim()) {
            case "storea":
                switch(methodName.toLowerCase().trim()) {
                    case "seta":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).seta(BigInteger.valueOf(value)).flowable().toObservable();
                    case "setb":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).setb(BigInteger.valueOf(value)).flowable().toObservable();
                    case "setc":
                        return Storea.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).setc(BigInteger.valueOf(value)).flowable().toObservable();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            case "storeb":
                switch(methodName.toLowerCase().trim()) {
                    case "setb":
                        return Storeb.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).setb(BigInteger.valueOf(value)).flowable().toObservable();
                    case "setc":
                        return Storeb.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).setc(BigInteger.valueOf(value)).flowable().toObservable();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            case "storec":
                switch(methodName.toLowerCase().trim()) {
                    case "setc":
                        return Storec.load(contractAddress, client, txManager, BigInteger.valueOf(0), DEFAULT_GAS_LIMIT).setc(BigInteger.valueOf(value)).flowable().toObservable();
                    default:
                        throw new Exception("invalid method name " + methodName + " for contract " + contractName);
                }
            default:
                throw new Exception("invalid contract name " + contractName);
        }
    } catch (Exception e) {
        logger.debug("setStoreContractValue() " + contractName + " " + methodName, e);
        throw new RuntimeException(e);
    }
}
Also used : Quorum(org.web3j.quorum.Quorum) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) ClientTransactionManager(org.web3j.quorum.tx.ClientTransactionManager) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) TransactionManager(org.web3j.tx.TransactionManager) ContractCallException(org.web3j.tx.exceptions.ContractCallException) IOException(java.io.IOException)

Example 5 with PrivateClientTransactionManager

use of com.quorum.gauge.ext.PrivateClientTransactionManager in project quorum-acceptance-tests by ConsenSys.

the class ContractService method updatePublicSimpleStorageContract.

public Observable<TransactionReceipt> updatePublicSimpleStorageContract(final int newValue, final String contractAddress, final Node source, String ethAccount) {
    final Quorum client = connectionFactory().getConnection(source);
    final BigInteger value = BigInteger.valueOf(newValue);
    return accountService.getAccountAddress(source, ethAccount).map(address -> new PrivateClientTransactionManager(client, address, null, null, Collections.emptyList())).flatMap(txManager -> SimpleStorage.load(contractAddress, client, txManager, BigInteger.ZERO, DEFAULT_GAS_LIMIT).set(value).flowable().toObservable());
}
Also used : Transaction(org.web3j.protocol.core.methods.request.Transaction) Arrays(java.util.Arrays) EthChainId(com.quorum.gauge.ext.EthChainId) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) FunctionEncoder(org.web3j.abi.FunctionEncoder) Response(org.web3j.protocol.core.Response) Request(org.web3j.protocol.core.Request) FUNC_GET(com.quorum.gauge.sol.SimpleStorage.FUNC_GET) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) Uint256(org.web3j.abi.datatypes.generated.Uint256) Charset(java.nio.charset.Charset) Service(org.springframework.stereotype.Service) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) ClientTransactionManager(org.web3j.quorum.tx.ClientTransactionManager) FunctionReturnDecoder(org.web3j.abi.FunctionReturnDecoder) com.quorum.gauge.sol(com.quorum.gauge.sol) Type(org.web3j.abi.datatypes.Type) Node(com.quorum.gauge.common.QuorumNetworkProperty.Node) StreamUtils(org.springframework.util.StreamUtils) Quorum(org.web3j.quorum.Quorum) EthSendTransactionAsync(com.quorum.gauge.ext.EthSendTransactionAsync) Contract(org.web3j.tx.Contract) Logger(org.slf4j.Logger) EthStorageRoot(com.quorum.gauge.ext.EthStorageRoot) TypeReference(org.web3j.abi.TypeReference) Collections.emptyList(java.util.Collections.emptyList) QuorumNode(com.quorum.gauge.common.QuorumNode) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) PrivateTransactionAsync(com.quorum.gauge.ext.PrivateTransactionAsync) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) ContractCallException(org.web3j.tx.exceptions.ContractCallException) DefaultBlockParameter(org.web3j.protocol.core.DefaultBlockParameter) IOException(java.io.IOException) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Web3j(org.web3j.protocol.Web3j) CollectionUtils(org.springframework.util.CollectionUtils) EthFilter(org.web3j.protocol.core.methods.request.EthFilter) TransactionManager(org.web3j.tx.TransactionManager) Function(org.web3j.abi.datatypes.Function) org.web3j.protocol.core.methods.response(org.web3j.protocol.core.methods.response) Collections(java.util.Collections) InputStream(java.io.InputStream) Quorum(org.web3j.quorum.Quorum) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) BigInteger(java.math.BigInteger)

Aggregations

PrivateClientTransactionManager (com.quorum.gauge.ext.PrivateClientTransactionManager)15 Quorum (org.web3j.quorum.Quorum)15 ReadonlyTransactionManager (org.web3j.tx.ReadonlyTransactionManager)12 ContractCallException (org.web3j.tx.exceptions.ContractCallException)12 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)11 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)11 Observable (io.reactivex.Observable)11 BigInteger (java.math.BigInteger)11 Collectors (java.util.stream.Collectors)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 Autowired (org.springframework.beans.factory.annotation.Autowired)11 Service (org.springframework.stereotype.Service)11 TransactionManager (org.web3j.tx.TransactionManager)11 QuorumNode (com.quorum.gauge.common.QuorumNode)10 List (java.util.List)10 Contract (org.web3j.tx.Contract)10 EthChainId (com.quorum.gauge.ext.EthChainId)9 Collections (java.util.Collections)9 IOException (java.io.IOException)7