Search in sources :

Example 1 with RawDeployedContractTarget

use of com.quorum.gauge.common.RawDeployedContractTarget in project quorum-acceptance-tests by ConsenSys.

the class RawContractService method createNRawSimplePrivateContract.

public List<Observable<RawDeployedContractTarget>> createNRawSimplePrivateContract(int count, WalletData wallet, QuorumNode source, QuorumNode[] targetNodes) throws IOException, CipherException {
    try {
        Quorum client = connectionFactory().getConnection(source);
        Credentials credentials = WalletUtils.loadCredentials(wallet.getWalletPass(), wallet.getWalletPath());
        String fromAddress = credentials.getAddress();
        BigInteger transactionCount = client.ethGetTransactionCount(fromAddress, DefaultBlockParameterName.LATEST).flowable().toObservable().blockingFirst().getTransactionCount();
        Enclave enclave = buildEnclave(source, client);
        List<Observable<RawDeployedContractTarget>> allObservableContracts = new ArrayList<>();
        int counter = 0;
        for (QuorumNode targetNode : targetNodes) {
            RawPrivateContract[] rawPrivateContracts = new RawPrivateContract[count];
            for (int j = 0; j < count; j++) {
                int arbitraryValue = new Random().nextInt(50) + 1;
                String payload = base64SimpleStorageConstructorBytecode(arbitraryValue);
                SendResponse storeRawResponse = enclave.storeRawRequest(payload, privacyService.id(source), Collections.emptyList());
                String tmHash = base64ToHex(storeRawResponse.getKey());
                RawTransaction tx = RawTransaction.createContractTransaction(transactionCount.add(BigInteger.valueOf(counter)), BigInteger.ZERO, DEFAULT_GAS_LIMIT, BigInteger.ZERO, tmHash);
                counter++;
                rawPrivateContracts[j] = new RawPrivateContract(sign(tx, credentials), arbitraryValue, targetNode);
            }
            allObservableContracts.add(Observable.fromArray(rawPrivateContracts).flatMap(raw -> sendRawPrivateTransaction(source, raw.rawTransaction, targetNode).map(b -> transactionService.waitForTransactionReceipt(targetNode, b.getTransactionHash())).map(receipt -> new RawDeployedContractTarget(raw.value, raw.node, receipt)).subscribeOn(Schedulers.io())));
        }
        return allObservableContracts;
    } catch (IOException e) {
        logger.error("RawTransaction - private", e);
        throw e;
    } catch (CipherException e) {
        logger.error("RawTransaction - private - bad credentials", e);
        throw e;
    }
}
Also used : UnixDomainSocketFactory(org.web3j.quorum.UnixDomainSocketFactory) RetryWithDelay(com.quorum.gauge.common.RetryWithDelay) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Constellation(org.web3j.quorum.enclave.Constellation) Credentials(org.web3j.crypto.Credentials) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) RlpList(org.web3j.rlp.RlpList) Schedulers(io.reactivex.schedulers.Schedulers) BigInteger(java.math.BigInteger) URI(java.net.URI) RawDeployedContractTarget(com.quorum.gauge.common.RawDeployedContractTarget) Quorum(org.web3j.quorum.Quorum) Contract(org.web3j.tx.Contract) SneakyWrapper(com.quorum.gauge.sol.SneakyWrapper) QuorumNode(com.quorum.gauge.common.QuorumNode) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) ContractCallException(org.web3j.tx.exceptions.ContractCallException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClientReceipt(com.quorum.gauge.sol.ClientReceipt) TransactionEncoder(org.web3j.crypto.TransactionEncoder) Collectors(java.util.stream.Collectors) EthGetTransactionReceipt(org.web3j.protocol.core.methods.response.EthGetTransactionReceipt) SendResponse(org.web3j.quorum.enclave.SendResponse) CipherException(org.web3j.crypto.CipherException) Web3j(org.web3j.protocol.Web3j) EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) TransactionManager(org.web3j.tx.TransactionManager) RlpEncoder(org.web3j.rlp.RlpEncoder) java.util(java.util) FunctionEncoder(org.web3j.abi.FunctionEncoder) Response(org.web3j.protocol.core.Response) Request(org.web3j.protocol.core.Request) FillTransactionResponse(com.quorum.gauge.ext.filltx.FillTransactionResponse) ReadonlyTransactionManager(org.web3j.tx.ReadonlyTransactionManager) Charset(java.nio.charset.Charset) Service(org.springframework.stereotype.Service) EnclaveService(org.web3j.quorum.enclave.protocol.EnclaveService) WalletUtils(org.web3j.crypto.WalletUtils) Observable(io.reactivex.Observable) RlpDecoder(org.web3j.rlp.RlpDecoder) StreamUtils(org.springframework.util.StreamUtils) RlpString(org.web3j.rlp.RlpString) Logger(org.slf4j.Logger) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) PrivateFillTransaction(com.quorum.gauge.ext.filltx.PrivateFillTransaction) IOException(java.io.IOException) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) SimpleStorage(com.quorum.gauge.sol.SimpleStorage) RawTransaction(org.web3j.crypto.RawTransaction) File(java.io.File) SimpleStorageDelegate(com.quorum.gauge.sol.SimpleStorageDelegate) Tessera(org.web3j.quorum.enclave.Tessera) OkHttpClient(okhttp3.OkHttpClient) Enclave(org.web3j.quorum.enclave.Enclave) RawTransactionManager(org.web3j.tx.RawTransactionManager) Numeric(org.web3j.utils.Numeric) WalletData(com.quorum.gauge.common.config.WalletData) Function(org.web3j.abi.datatypes.Function) InputStream(java.io.InputStream) Quorum(org.web3j.quorum.Quorum) RawDeployedContractTarget(com.quorum.gauge.common.RawDeployedContractTarget) SendResponse(org.web3j.quorum.enclave.SendResponse) RlpString(org.web3j.rlp.RlpString) IOException(java.io.IOException) Observable(io.reactivex.Observable) Enclave(org.web3j.quorum.enclave.Enclave) CipherException(org.web3j.crypto.CipherException) RawTransaction(org.web3j.crypto.RawTransaction) BigInteger(java.math.BigInteger) QuorumNode(com.quorum.gauge.common.QuorumNode) Credentials(org.web3j.crypto.Credentials)

Aggregations

QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)1 QuorumNode (com.quorum.gauge.common.QuorumNode)1 RawDeployedContractTarget (com.quorum.gauge.common.RawDeployedContractTarget)1 RetryWithDelay (com.quorum.gauge.common.RetryWithDelay)1 WalletData (com.quorum.gauge.common.config.WalletData)1 PrivateClientTransactionManager (com.quorum.gauge.ext.PrivateClientTransactionManager)1 FillTransactionResponse (com.quorum.gauge.ext.filltx.FillTransactionResponse)1 PrivateFillTransaction (com.quorum.gauge.ext.filltx.PrivateFillTransaction)1 ClientReceipt (com.quorum.gauge.sol.ClientReceipt)1 SimpleStorage (com.quorum.gauge.sol.SimpleStorage)1 SimpleStorageDelegate (com.quorum.gauge.sol.SimpleStorageDelegate)1 SneakyWrapper (com.quorum.gauge.sol.SneakyWrapper)1 Observable (io.reactivex.Observable)1 Schedulers (io.reactivex.schedulers.Schedulers)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1