org.web3j.protocol.core.Request Java Examples

The following examples show how to use org.web3j.protocol.core.Request. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenEmptyToAddress() {
  final Request<Object, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withTo(""));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(sendTransaction.request(transactionBuilder.missingTo()));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #2
Source File: ContractTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test(expected = RuntimeException.class)
@SuppressWarnings("unchecked")
public void testInvalidTransactionReceipt() throws Throwable {
    prepareNonceRequest();
    prepareTransactionRequest();

    EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt();
    ethGetTransactionReceipt.setError(new Response.Error(1, "Invalid transaction receipt"));

    Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class);
    when(getTransactionReceiptRequest.sendAsync())
            .thenReturn(Async.run(() -> ethGetTransactionReceipt));
    when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH))
            .thenReturn((Request) getTransactionReceiptRequest);

    testErrorScenario();
}
 
Example #3
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenValueIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withValue(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withValue(FIELD_VALUE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #4
Source File: NetServicesTransaction.java    From besu with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Map<String, String>> execute(final NodeRequests requestFactories) {
  CustomRequestFactory.NetServicesResponse netServicesResponse = null;
  try {
    final CustomRequestFactory netServicesJsonRpcRequestFactory = requestFactories.custom();
    final Request<?, CustomRequestFactory.NetServicesResponse> request =
        netServicesJsonRpcRequestFactory.netServices();

    netServicesResponse = request.send();
  } catch (final Exception e) {
    throw new RuntimeException(e);
  }
  if (netServicesResponse.hasError()) {
    throw new RuntimeException(netServicesResponse.getError().getMessage());
  }
  return netServicesResponse.getResult();
}
 
Example #5
Source File: Web3jServiceTest.java    From eventeum with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws IOException {
    mockWeb3j = mock(Web3j.class);
    mockBlockManagement = mock(EventBlockManagementService.class);
    mockContractEventDetailsFactory = mock(ContractEventDetailsFactory.class);
    mockContractEventDetails = mock(ContractEventDetails.class);
    mockBlockSubscriptionStrategy = mock(BlockSubscriptionStrategy.class);

    when(mockBlockManagement.getLatestBlockForEvent(any(ContractEventFilter.class))).thenReturn(BLOCK_NUMBER);

    //Wire up getBlockNumber
    final Request<?, EthBlockNumber> mockRequest = mock(Request.class);
    final EthBlockNumber blockNumber = new EthBlockNumber();
    blockNumber.setResult("0x0");
    when(mockRequest.send()).thenReturn(blockNumber);
    doReturn(mockRequest).when(mockWeb3j).ethBlockNumber();

    underTest = new Web3jService("test", mockWeb3j, mockContractEventDetailsFactory,
            mockBlockManagement, mockBlockSubscriptionStrategy, new DummyAsyncTaskService());
}
 
Example #6
Source File: JsonRpc2_0Admin.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, NewAccountIdentifier> personalNewAccount(String password) {
    return new Request<>(
            "personal_newAccount",
            Arrays.asList(password),
            web3jService,
            NewAccountIdentifier.class);
}
 
Example #7
Source File: JsonRpc2_0Besu.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PrivGetPrivacyPrecompileAddress> privGetPrivacyPrecompileAddress() {
    return new Request<>(
            "priv_getPrivacyPrecompileAddress",
            Collections.emptyList(),
            web3jService,
            PrivGetPrivacyPrecompileAddress.class);
}
 
Example #8
Source File: JsonRpc2_0Parity.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, ParityFullTraceResponse> traceCall(
        Transaction transaction, List<String> traces, DefaultBlockParameter blockParameter) {
    return new Request<>(
            "trace_call",
            Arrays.asList(transaction, traces, blockParameter),
            web3jService,
            ParityFullTraceResponse.class);
}
 
Example #9
Source File: JsonRpc2_0Geth.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, BooleanResponse> personalLockAccount(String accountId) {
    return new Request<>(
            "personal_lockAccount",
            Arrays.asList(accountId),
            web3jService,
            BooleanResponse.class);
}
 
Example #10
Source File: PrivacyRequestFactory.java    From besu with Apache License 2.0 5 votes vote down vote up
public Request<?, GetCodeResponse> privGetCode(
    final String privacyGroupId, final String contractAddress, final String blockParameter) {
  return new Request<>(
      "priv_getCode",
      List.of(privacyGroupId, contractAddress, blockParameter),
      web3jService,
      GetCodeResponse.class);
}
 
Example #11
Source File: PrivCallAcceptanceTest.java    From besu with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnEmptyResultWithNonExistingPrivacyGroup() throws IOException {

  final String privacyGroupId =
      minerNode.execute(
          privacyTransactions.createPrivacyGroup(
              "myGroupName", "my group description", minerNode));

  final EventEmitter eventEmitter =
      minerNode.execute(
          privateContractTransactions.createSmartContractWithPrivacyGroupId(
              EventEmitter.class,
              minerNode.getTransactionSigningKey(),
              POW_CHAIN_ID,
              minerNode.getEnclaveKey(),
              privacyGroupId));

  privateContractVerifier
      .validPrivateContractDeployed(
          eventEmitter.getContractAddress(), minerNode.getAddress().toString())
      .verify(eventEmitter);

  final String invalidPrivacyGroup = constructInvalidString(privacyGroupId);
  final Request<Object, EthCall> privCall =
      privCall(invalidPrivacyGroup, eventEmitter, false, false);

  final EthCall result = privCall.send();

  assertThat(result.getResult()).isEqualTo("0x");
}
 
Example #12
Source File: JsonRpc2_0Quorum.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, ExecStatusInfo> quorumPermissionUpdateNodeStatus(
        String orgId, String enodeId, int action, PrivateTransaction transaction) {
    return new Request<>(
            "quorumPermission_updateNodeStatus",
            Arrays.asList(orgId, enodeId, action, transaction),
            web3jService,
            ExecStatusInfo.class);
}
 
Example #13
Source File: JsonRpc2_0Admin.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PlatonSendTransaction> personalSendTransaction(
        Transaction transaction, String passphrase) {
    return new Request<>(
            "personal_sendTransaction",
            Arrays.asList(transaction, passphrase),
            web3jService,
            PlatonSendTransaction.class);
}
 
Example #14
Source File: JsonRpc2_0Parity.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, ParityAddressesResponse> parityImportGethAccounts(
        ArrayList<String> gethAddresses) {
    return new Request<>(
            "parity_importGethAccounts",
            gethAddresses,
            web3jService,
            ParityAddressesResponse.class);
}
 
Example #15
Source File: JsonRpc2_0Parity.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request<?, NewAccountIdentifier> parityNewAccountFromWallet(
        WalletFile walletFile, String password) {
    return new Request<>(
            "parity_newAccountFromWallet",
            Arrays.asList(walletFile, password),
            web3jService,
            NewAccountIdentifier.class);
}
 
Example #16
Source File: JsonRpc2_0RxTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testReplayBlocksObservable() throws Exception {

    List<EthBlock> ethBlocks = Arrays.asList(createBlock(0), createBlock(1), createBlock(2));

    OngoingStubbing<EthBlock> stubbing =
            when(web3jService.send(any(Request.class), eq(EthBlock.class)));
    for (EthBlock ethBlock : ethBlocks) {
        stubbing = stubbing.thenReturn(ethBlock);
    }

    Observable<EthBlock> observable = web3j.replayBlocksObservable(
            new DefaultBlockParameterNumber(BigInteger.ZERO),
            new DefaultBlockParameterNumber(BigInteger.valueOf(2)),
            false);

    CountDownLatch transactionLatch = new CountDownLatch(ethBlocks.size());
    CountDownLatch completedLatch = new CountDownLatch(1);

    List<EthBlock> results = new ArrayList<>(ethBlocks.size());
    Subscription subscription = observable.subscribe(
            result -> {
                results.add(result);
                transactionLatch.countDown();
            },
            throwable -> fail(throwable.getMessage()),
            () -> completedLatch.countDown());

    transactionLatch.await(1, TimeUnit.SECONDS);
    assertThat(results, equalTo(ethBlocks));

    subscription.unsubscribe();

    completedLatch.await(1, TimeUnit.SECONDS);
    assertTrue(subscription.isUnsubscribed());
}
 
Example #17
Source File: Ibft2RequestFactory.java    From besu with Apache License 2.0 5 votes vote down vote up
Request<?, SignersBlockResponse> validatorsAtBlock(final String blockNumber) {
  return new Request<>(
      "ibft_getValidatorsByBlockNumber",
      singletonList(blockNumber),
      web3jService,
      SignersBlockResponse.class);
}
 
Example #18
Source File: JsonRpc2_0Besu.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, EthGetCode> privGetCode(
        final String privacyGroupId,
        final String address,
        final DefaultBlockParameter defaultBlockParameter) {
    ArrayList<String> result =
            new ArrayList<>(
                    Arrays.asList(privacyGroupId, address, defaultBlockParameter.getValue()));
    return new Request<>("priv_getCode", result, web3jService, EthGetCode.class);
}
 
Example #19
Source File: JsonRpc2_0Parity.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Request<?, BooleanResponse> paritySetDappAddresses(
        String dAppId, ArrayList<String> availableAccountIds) {
    return new Request<>(
            "parity_setDappAddresses",
            Arrays.asList(dAppId, availableAccountIds),
            web3jService,
            BooleanResponse.class);
}
 
Example #20
Source File: MinerRequestFactory.java    From besu with Apache License 2.0 5 votes vote down vote up
Request<?, org.web3j.protocol.core.methods.response.VoidResponse> minerStop() {
  return new Request<>(
      "miner_stop",
      null,
      web3jService,
      org.web3j.protocol.core.methods.response.VoidResponse.class);
}
 
Example #21
Source File: WebSocketService.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Response> CompletableFuture<T> sendAsync(
        Request request, Class<T> responseType) {

    CompletableFuture<T> result = new CompletableFuture<>();
    long requestId = request.getId();
    requestForId.put(requestId, new WebSocketRequest<>(result, responseType));
    try {
        sendRequest(request, requestId);
    } catch (IOException e) {
        closeRequest(requestId, e);
    }

    return result;
}
 
Example #22
Source File: JsonRpc2_0Besu.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PrivFindPrivacyGroup> privOnChainFindPrivacyGroup(
        final List<Base64String> addresses) {
    return new Request<>(
            "privx_findOnChainPrivacyGroup",
            Collections.singletonList(addresses),
            web3jService,
            PrivFindPrivacyGroup.class);
}
 
Example #23
Source File: JsonRpc2_0Quorum.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, ExecStatusInfo> quorumPermissionRemoveRole(
        String orgId, String roleId, PrivateTransaction transaction) {
    return new Request<>(
            "quorumPermission_removeRole",
            Arrays.asList(orgId, roleId, transaction),
            web3jService,
            ExecStatusInfo.class);
}
 
Example #24
Source File: JsonRpc2_0Quorum.java    From web3j-quorum with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PermissionNodeList> quorumPermissionGetNodeList() {
    return new Request<>(
            "quorumPermission_nodeList",
            Collections.emptyList(),
            web3jService,
            PermissionNodeList.class);
}
 
Example #25
Source File: PollingTransactionReceiptProcessorTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private static <T extends Response<?>> Request<String, T> requestReturning(T response) {
    Request<String, T> request = mock(Request.class);
    try {
        when(request.send()).thenReturn(response);
    } catch (IOException e) {
        // this will never happen
    }
    return request;
}
 
Example #26
Source File: JsonRpc2_0Geth.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Flowable<PendingTransactionNotification> newPendingTransactionsNotifications() {
    return web3jService.subscribe(
            new Request<>(
                    "eth_subscribe",
                    Arrays.asList("newPendingTransactions"),
                    web3jService,
                    EthSubscribe.class),
            "eth_unsubscribe",
            PendingTransactionNotification.class);
}
 
Example #27
Source File: IpcServiceTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testSend() throws IOException {
    when(ioFacade.read())
            .thenReturn(
                    "{\"jsonrpc\":\"2.0\",\"id\":1,"
                            + "\"result\":\"Geth/v1.5.4-stable-b70acf3c/darwin/go1.7.3\"}\n");

    ipcService.send(new Request(), Web3ClientVersion.class);

    verify(ioFacade).write("{\"jsonrpc\":\"2.0\",\"method\":null,\"params\":null,\"id\":0}");
}
 
Example #28
Source File: JsonRpc2_0Geth.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, BooleanResponse> personalLockAccount(String accountId) {
    return new Request<>(
            "personal_lockAccount",
            Arrays.asList(accountId),
            web3jService,
            BooleanResponse.class);
}
 
Example #29
Source File: JsonRpc2_0Besu.java    From web3j with Apache License 2.0 5 votes vote down vote up
public Request<?, EthAccounts> ibftGetValidatorsByBlockHash(String blockHash) {
    return new Request<>(
            "ibft_getValidatorsByBlockHash",
            Arrays.asList(blockHash),
            web3jService,
            EthAccounts.class);
}
 
Example #30
Source File: JsonRpc2_0Admin.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PersonalListAccounts> personalListAccounts() {
    return new Request<>(
            "personal_listAccounts",
            Collections.<String>emptyList(),
            web3jService,
            PersonalListAccounts.class);
}