use of org.web3j.protocol.core.Request in project web3j by web3j.
the class JsonRpc2_0Rx method replayBlocksFlowableSync.
private Flowable<EthBlock> replayBlocksFlowableSync(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock, boolean containsFullTransactionObjects, boolean isAscending) {
BigInteger startBlockNumber;
BigInteger endBlockNumber;
try {
startBlockNumber = getBlockNumber(startBlock);
endBlockNumber = getBlockNumber(endBlock);
} catch (IOException e) {
return Flowable.error(e);
}
return Flowables.range(startBlockNumber, endBlockNumber, isAscending).map(DefaultBlockParameterNumber::new).map(number -> web3j.ethGetBlockByNumber(number, containsFullTransactionObjects)).flatMap(Request::flowable);
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class WebSocketService method processBatchRequestReply.
private void processBatchRequestReply(String replyStr, ArrayNode replyJson) throws IOException {
long replyId = getReplyId(replyJson.get(0));
WebSocketRequests webSocketRequests = (WebSocketRequests) getAndRemoveRequest(replyId);
try {
// rollback request id of first batch elt
((ObjectNode) replyJson.get(0)).put("id", webSocketRequests.getOriginId());
List<Request<?, ? extends Response<?>>> requests = webSocketRequests.getRequests();
List<Response<?>> responses = new ArrayList<>(replyJson.size());
for (int i = 0; i < replyJson.size(); i++) {
Response<?> response = objectMapper.treeToValue(replyJson.get(i), requests.get(i).getResponseType());
responses.add(response);
}
sendReplyToListener(webSocketRequests, new BatchResponse(requests, responses));
} catch (IllegalArgumentException e) {
sendExceptionToListener(replyStr, webSocketRequests, e);
}
}
use of org.web3j.protocol.core.Request in project web3j by web3j.
the class Filter method getInitialFilterLogs.
private void getInitialFilterLogs() {
try {
Optional<Request<?, EthLog>> maybeRequest = this.getFilterLogs(this.filterId);
EthLog ethLog = null;
if (maybeRequest.isPresent()) {
ethLog = maybeRequest.get().send();
} else {
ethLog = new EthLog();
ethLog.setResult(Collections.emptyList());
}
if (ethLog.hasError()) {
throwException(ethLog.getError());
}
process(ethLog.getLogs());
} catch (IOException e) {
throwException(e);
}
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ExtensionService method updateParties.
public Observable<QuorumUpdateParties> updateParties(final QuorumNetworkProperty.Node initiator, final String address, final Set<QuorumNetworkProperty.Node> allNodes, final PrivacyFlag privacyFlag) {
final List<String> privateFor = allNodes.stream().filter(n -> !n.equals(initiator)).map(n -> privacyService.id(n)).collect(Collectors.toList());
final PrivateTransaction transactionArgs = new EnhancedPrivateTransaction(accountService.getDefaultAccountAddress(initiator).blockingFirst(), null, null, null, BigInteger.ZERO, null, null, privateFor, singletonList(privacyFlag));
return new Request<>("quorumExtension_updateParties", Stream.of(address, transactionArgs).collect(Collectors.toList()), connectionFactory().getWeb3jService(initiator), QuorumUpdateParties.class).flowable().toObservable();
}
use of org.web3j.protocol.core.Request in project quorum-acceptance-tests by ConsenSys.
the class ContractCodeReaderService method execute.
private <T> Observable<T> execute(QuorumNetworkProperty.Node node, Function function, String contractAddress, Class<T> outputType) {
Quorum client = connectionFactory().getConnection(node);
return client.ethCoinbase().flowable().toObservable().map(Response::getResult).flatMap(address -> {
Request<?, EthCall> req = client.ethCall(Transaction.createEthCallTransaction(address, contractAddress, FunctionEncoder.encode(function)), DefaultBlockParameterName.LATEST);
return req.flowable().toObservable();
}).map(ec -> {
if (ec.hasError()) {
throw new ContractCallException(ec.getError().getMessage());
}
List<Type> values = FunctionReturnDecoder.decode(ec.getValue(), function.getOutputParameters());
Type result;
if (!values.isEmpty()) {
result = values.get(0);
} else {
throw new ContractCallException("Empty value (0x) returned from contract");
}
Object value = result.getValue();
if (outputType.isAssignableFrom(value.getClass())) {
return (T) value;
} else {
throw new ContractCallException("Unable to convert response: " + value + " of type " + result + " to expected type: " + outputType.getSimpleName());
}
});
}
Aggregations