use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ContractService method createClientReceiptContractAsync.
public Observable<EthSendTransactionAsync> createClientReceiptContractAsync(int initialValue, QuorumNode source, String sourceAccount, QuorumNode target, String callbackUrl) {
InputStream binaryStream = ClientReceipt.class.getResourceAsStream("/com.quorum.gauge.sol/ClientReceipt.bin");
if (binaryStream == null) {
throw new IllegalStateException("Can't find resource ClientReceipt.bin");
}
return (sourceAccount != null ? Observable.just(sourceAccount) : accountService.getDefaultAccountAddress(source)).flatMap(fromAddress -> {
try {
String binary = StreamUtils.copyToString(binaryStream, Charset.defaultCharset());
PrivateTransactionAsync tx = new PrivateTransactionAsync(fromAddress, null, DEFAULT_GAS_LIMIT, null, BigInteger.valueOf(0), binary, null, Arrays.asList(privacyService.id(target)), callbackUrl);
Request<?, EthSendTransactionAsync> request = new Request<>("eth_sendTransactionAsync", Arrays.asList(tx), connectionFactory().getWeb3jService(source), EthSendTransactionAsync.class);
return request.flowable().toObservable();
} catch (IOException e) {
logger.error("Unable to construct transaction arguments", e);
throw new RuntimeException(e);
}
});
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class PluginSecurity method invokeMultiple.
@Step("`<clientId>` is responded with <policy> when trying to: <table>")
public void invokeMultiple(String clientId, String policy, Table table) {
boolean expectAuthorized = "success".equalsIgnoreCase(policy);
String token = mustHaveValue(DataStoreFactory.getScenarioDataStore(), clientId, String.class);
Context.storeAccessToken(token);
Map<String, QuorumNetworkProperty.Node> nodeMap = networkProperty.getNodes();
table.getTableRows().stream().map(r -> new ApiCall(r.getCell("callApi"), r.getCell("targetNode"))).onClose(Context::removeAccessToken).forEach(a -> {
if (a.isBatch) {
rpcService.call(nodeMap.get(a.node), a.collector).blockingForEach(batchResponse -> {
assertThat(batchResponse.getResponses()).as("Number of returned responses").hasSize(a.collector.size());
for (ObjectResponse res : batchResponse.getResponses()) {
assertThat(res.getId()).as("Response must have id").isNotZero();
Request r = a.collector.getByID(res.getId());
String description = policy + ": " + r.getMethod() + "@" + a.node;
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
}
});
} else {
rpcService.call(nodeMap.get(a.node), a.name, Collections.emptyList(), ObjectResponse.class).blockingForEach(res -> {
assertThat(res.getId()).as("Response must have ID").isNotZero();
String description = policy + ": " + a.name + "@" + a.node;
if (expectAuthorized) {
assertThat(Optional.ofNullable(res.getError()).orElse(new Response.Error()).getMessage()).as(description).isNullOrEmpty();
}
assertThat(res.hasError()).as(description).isNotEqualTo(expectAuthorized);
if (res.hasError()) {
assertThat(res.getError().getMessage()).as(description).endsWith(policy);
}
});
}
});
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class RaftService method getLeaderWithLocalEnodeInfo.
/**
* Retrieve the enode for the raft leader and compare it with the enode of
* all the peers to convert it into a QuorumNode identity.
*/
public QuorumNode getLeaderWithLocalEnodeInfo(QuorumNode node) {
Request<String, RaftLeader> request = new Request<>("raft_leader", null, connectionFactory().getWeb3jService(node), RaftLeader.class);
RaftLeader response = request.flowable().toObservable().blockingFirst();
String leaderEnode = response.getResult();
logger.debug("Retrieved leader enode: {}", leaderEnode);
Map<String, Node> nodes = connectionFactory().getNetworkProperty().getNodes();
for (Map.Entry<String, Node> nodeEntry : nodes.entrySet()) {
String thisEnode = nodeEntry.getValue().getEnodeUrl();
logger.debug("Retrieved enode info: {}", thisEnode);
if (thisEnode.contains(leaderEnode)) {
return connectionFactory().getNetworkProperty().getQuorumNode(nodeEntry.getValue());
}
}
throw new RuntimeException("Leader enode not found in peers: " + leaderEnode);
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class RaftService method getLeader.
/**
* Retrieve the enode for the raft leader and compare it with the enode of
* all the peers to convert it into a QuorumNode identity.
*/
public QuorumNode getLeader(QuorumNode node) {
Request<String, RaftLeader> request = new Request<>("raft_leader", null, connectionFactory().getWeb3jService(node), RaftLeader.class);
RaftLeader response = request.flowable().toObservable().blockingFirst();
String leaderEnode = response.getResult();
logger.debug("Retrieved leader enode: {}", leaderEnode);
Map<String, Node> nodes = connectionFactory().getNetworkProperty().getNodes();
for (Node n : nodes.values()) {
Request<?, NodeInfo> nodeInfoRequest = new Request<>("admin_nodeInfo", null, connectionFactory().getWeb3jService(n), NodeInfo.class);
NodeInfo nodeInfo = nodeInfoRequest.flowable().toObservable().blockingFirst();
String thisEnode = nodeInfo.getEnode();
logger.debug("Retrieved enode info: {}", thisEnode);
if (thisEnode.contains(leaderEnode)) {
return connectionFactory().getNetworkProperty().getQuorumNode(n);
}
}
throw new RuntimeException("Leader enode not found in peers: " + leaderEnode);
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class TransactionService method sendSignedPrivateTransaction.
public Observable<EthSendTransaction> sendSignedPrivateTransaction(String apiMethod, String txData, QuorumNode from, QuorumNode privateFor, String targetContract) {
Quorum quorumClient = connectionFactory().getConnection(from);
// sleep to allow time for previous tx to be minted so that nonce is updated
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e) {
logger.error("sleep interrupted", e);
}
String fromAddress = accountService.getDefaultAccountAddress(from).blockingFirst();
BigInteger transactionCount = quorumClient.ethGetTransactionCount(fromAddress, DefaultBlockParameterName.LATEST).flowable().toObservable().blockingFirst().getTransactionCount();
ExtendedPrivateTransaction tx = new ExtendedPrivateTransaction(fromAddress, transactionCount, BigInteger.ZERO, DEFAULT_GAS_LIMIT, targetContract, null, txData, null, Arrays.asList(privacyService.id(privateFor)));
List<Object> params = new ArrayList<>(Collections.singletonList(tx));
if ("personal_signTransaction".equals(apiMethod)) {
// add empty password
params.add("");
}
Request<?, EthSignTransaction> request = new Request<>(apiMethod, params, connectionFactory().getWeb3jService(from), EthSignTransaction.class);
Observable<EthSignTransaction> ethSignTransaction = request.flowable().toObservable();
String rawHexString = ethSignTransaction.blockingFirst().getRaw().orElseThrow();
logger.debug("rawHexString", rawHexString);
return quorumClient.ethSendRawPrivateTransaction(rawHexString, Arrays.asList(privacyService.id(privateFor))).flowable().toObservable();
}
Aggregations