Search in sources :

Example 16 with Request

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);
}
Also used : BackpressureStrategy(io.reactivex.BackpressureStrategy) EthBlock(org.web3j.protocol.core.methods.response.EthBlock) PendingTransactionFilter(org.web3j.protocol.core.filters.PendingTransactionFilter) FlowableEmitter(io.reactivex.FlowableEmitter) BlockFilter(org.web3j.protocol.core.filters.BlockFilter) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) IOException(java.io.IOException) DefaultBlockParameter(org.web3j.protocol.core.DefaultBlockParameter) Flowables(org.web3j.utils.Flowables) Collectors(java.util.stream.Collectors) Request(org.web3j.protocol.core.Request) LogFilter(org.web3j.protocol.core.filters.LogFilter) Transaction(org.web3j.protocol.core.methods.response.Transaction) DefaultBlockParameterNumber(org.web3j.protocol.core.DefaultBlockParameterNumber) List(java.util.List) Scheduler(io.reactivex.Scheduler) Log(org.web3j.protocol.core.methods.response.Log) Flowable(io.reactivex.Flowable) Web3j(org.web3j.protocol.Web3j) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BigInteger(java.math.BigInteger) Schedulers(io.reactivex.schedulers.Schedulers) Request(org.web3j.protocol.core.Request) BigInteger(java.math.BigInteger) DefaultBlockParameterNumber(org.web3j.protocol.core.DefaultBlockParameterNumber) IOException(java.io.IOException)

Example 17 with Request

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);
    }
}
Also used : Response(org.web3j.protocol.core.Response) BatchResponse(org.web3j.protocol.core.BatchResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BatchResponse(org.web3j.protocol.core.BatchResponse) Request(org.web3j.protocol.core.Request) BatchRequest(org.web3j.protocol.core.BatchRequest) ArrayList(java.util.ArrayList)

Example 18 with Request

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);
    }
}
Also used : Request(org.web3j.protocol.core.Request) EthLog(org.web3j.protocol.core.methods.response.EthLog) IOException(java.io.IOException)

Example 19 with Request

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();
}
Also used : PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) Collections.emptyList(java.util.Collections.emptyList) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Collectors(java.util.stream.Collectors) Request(org.web3j.protocol.core.Request) Collections.singletonList(java.util.Collections.singletonList) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Service(org.springframework.stereotype.Service) com.quorum.gauge.ext.contractextension(com.quorum.gauge.ext.contractextension) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) PrivateTransaction(org.web3j.quorum.methods.request.PrivateTransaction) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) EnhancedPrivateTransaction(com.quorum.gauge.ext.EnhancedPrivateTransaction) Request(org.web3j.protocol.core.Request)

Example 20 with Request

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());
        }
    });
}
Also used : Response(org.web3j.protocol.core.Response) Transaction(org.web3j.protocol.core.methods.request.Transaction) Arrays(java.util.Arrays) PrivacyFlag(com.quorum.gauge.common.PrivacyFlag) Autowired(org.springframework.beans.factory.annotation.Autowired) FunctionEncoder(org.web3j.abi.FunctionEncoder) Response(org.web3j.protocol.core.Response) Uint32(org.web3j.abi.datatypes.generated.Uint32) FUNC_GETLASTCODESIZE(com.quorum.gauge.sol.ContractCodeReader.FUNC_GETLASTCODESIZE) Request(org.web3j.protocol.core.Request) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) DynamicBytes(org.web3j.abi.datatypes.DynamicBytes) Service(org.springframework.stereotype.Service) FUNC_GETCODESIZE(com.quorum.gauge.sol.ContractCodeReader.FUNC_GETCODESIZE) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) FunctionReturnDecoder(org.web3j.abi.FunctionReturnDecoder) Type(org.web3j.abi.datatypes.Type) FUNC_GETCODEHASH(com.quorum.gauge.sol.ContractCodeReader.FUNC_GETCODEHASH) Quorum(org.web3j.quorum.Quorum) Contract(org.web3j.tx.Contract) TypeReference(org.web3j.abi.TypeReference) EthCall(org.web3j.protocol.core.methods.response.EthCall) FUNC_GETCODE(com.quorum.gauge.sol.ContractCodeReader.FUNC_GETCODE) QuorumNetworkProperty(com.quorum.gauge.common.QuorumNetworkProperty) DefaultBlockParameterName(org.web3j.protocol.core.DefaultBlockParameterName) ContractCallException(org.web3j.tx.exceptions.ContractCallException) PrivateClientTransactionManager(com.quorum.gauge.ext.PrivateClientTransactionManager) Collectors(java.util.stream.Collectors) List(java.util.List) Bytes32(org.web3j.abi.datatypes.generated.Bytes32) Function(org.web3j.abi.datatypes.Function) ContractCodeReader(com.quorum.gauge.sol.ContractCodeReader) Quorum(org.web3j.quorum.Quorum) Type(org.web3j.abi.datatypes.Type) ContractCallException(org.web3j.tx.exceptions.ContractCallException) Request(org.web3j.protocol.core.Request)

Aggregations

Request (org.web3j.protocol.core.Request)25 Test (org.junit.jupiter.api.Test)8 Response (org.web3j.protocol.core.Response)8 BigInteger (java.math.BigInteger)7 Collectors (java.util.stream.Collectors)7 Transaction (org.web3j.protocol.core.methods.request.Transaction)7 QuorumNetworkProperty (com.quorum.gauge.common.QuorumNetworkProperty)6 List (java.util.List)6 Service (org.springframework.stereotype.Service)6 DefaultBlockParameter (org.web3j.protocol.core.DefaultBlockParameter)6 PrivacyFlag (com.quorum.gauge.common.PrivacyFlag)5 QuorumNode (com.quorum.gauge.common.QuorumNode)5 Observable (io.reactivex.Observable)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 EthCall (org.web3j.protocol.core.methods.response.EthCall)5 Node (com.quorum.gauge.common.QuorumNetworkProperty.Node)3 EnhancedPrivateTransaction (com.quorum.gauge.ext.EnhancedPrivateTransaction)3 com.quorum.gauge.ext.contractextension (com.quorum.gauge.ext.contractextension)3 IOException (java.io.IOException)3 Collections.emptyList (java.util.Collections.emptyList)3