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;
}
}
Aggregations