use of org.web3j.quorum.enclave.SendResponse 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;
}
}
use of org.web3j.quorum.enclave.SendResponse in project quorum-acceptance-tests by ConsenSys.
the class RawContractService method createRawSimplePrivateContractUsingEthApi.
public Observable<EthSendTransaction> createRawSimplePrivateContractUsingEthApi(String apiMethod, int initialValue, QuorumNode source, QuorumNode target) {
Quorum client = connectionFactory().getConnection(source);
Enclave enclave = buildEnclave(source, client);
String payload = base64SimpleStorageConstructorBytecode(initialValue);
SendResponse storeRawResponse = enclave.storeRawRequest(payload, privacyService.id(source), Collections.emptyList());
String tmHash = base64ToHex(storeRawResponse.getKey());
return transactionService.sendSignedPrivateTransaction(apiMethod, tmHash, source, target, null);
}
use of org.web3j.quorum.enclave.SendResponse in project quorum-acceptance-tests by ConsenSys.
the class RawContractService method updateRawSimplePrivateContractUsingEthApi.
public Observable<EthGetTransactionReceipt> updateRawSimplePrivateContractUsingEthApi(String apiMethod, int newValue, String contractAddress, QuorumNode source, QuorumNode target) {
Quorum client = connectionFactory().getConnection(source);
Enclave enclave = buildEnclave(source, client);
String payload = base64SimpleStorageSetBytecode(newValue);
SendResponse storeRawResponse = enclave.storeRawRequest(payload, privacyService.id(source), Collections.emptyList());
String tmHash = base64ToHex(storeRawResponse.getKey());
EthSendTransaction sendTransactionResponse = transactionService.sendSignedPrivateTransaction(apiMethod, tmHash, source, target, contractAddress).blockingFirst();
Optional<String> responseError = Optional.ofNullable(sendTransactionResponse.getError()).map(Response.Error::getMessage);
responseError.ifPresent(e -> logger.error("EthSendTransaction error: {}", e));
logger.debug("sent tx: {}", sendTransactionResponse.getTransactionHash());
return transactionService.getTransactionReceipt(source, sendTransactionResponse.getTransactionHash()).map(ethGetTransactionReceipt -> {
if (ethGetTransactionReceipt.getTransactionReceipt().isPresent()) {
return ethGetTransactionReceipt;
} else {
throw new RuntimeException("retry");
}
}).retryWhen(new RetryWithDelay(20, 3000));
}
Aggregations