Java Code Examples for org.web3j.protocol.core.Request

The following examples show how to use org.web3j.protocol.core.Request. These examples are extracted from open source projects. 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
@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
@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 3
Source Project: eventeum   Source File: Web3jServiceTest.java    License: 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 4
@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 5
Source Project: besu   Source File: NetServicesTransaction.java    License: 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 6
Source Project: client-sdk-java   Source File: JsonRpc2_0Admin.java    License: 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 Project: web3j   Source File: JsonRpc2_0Besu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, EthSendTransaction> privOnChainCreatePrivacyGroup(
        final Base64String privacyGroupId,
        final Credentials credentials,
        final Base64String enclaveKey,
        final List<Base64String> participants)
        throws IOException {
    List<byte[]> participantsAsBytes =
            participants.stream().map(Base64String::raw).collect(Collectors.toList());
    BigInteger transactionCount =
            privGetTransactionCount(credentials.getAddress(), privacyGroupId)
                    .send()
                    .getTransactionCount();
    String addToContractCall =
            OnChainPrivacyTransactionBuilder.getEncodedAddToGroupFunction(
                    enclaveKey, participantsAsBytes);

    String addToPrivacyGroupTransactionPayload =
            OnChainPrivacyTransactionBuilder.buildOnChainPrivateTransaction(
                    privacyGroupId,
                    credentials,
                    enclaveKey,
                    transactionCount,
                    addToContractCall);

    return eeaSendRawTransaction(addToPrivacyGroupTransactionPayload);
}
 
Example 8
Source Project: web3j   Source File: PrivateLogFilter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Optional<Request<?, EthLog>> getFilterLogs(BigInteger filterId) {
    return Optional.of(
            ((Besu) web3j)
                    .privGetFilterLogs(
                            privacyGroupId, Numeric.toHexStringWithPrefix(filterId)));
}
 
Example 9
Source Project: client-sdk-java   Source File: HttpServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsupportedOperationException.class)
public void subscriptionNotSupported() {
    Request<Object, PlatonSubscribe> subscribeRequest = new Request<>(
            "eth_subscribe",
            Arrays.asList("newHeads", Collections.emptyMap()),
            httpService,
            PlatonSubscribe.class);

    httpService.subscribe(
            subscribeRequest,
            "eth_unsubscribe",
            NewHeadsNotification.class
    );
}
 
Example 10
private void configureSyncing(boolean isSyncing) throws IOException {
    EthSyncing ethSyncing = new EthSyncing();
    EthSyncing.Result result = new EthSyncing.Result();
    result.setSyncing(isSyncing);
    ethSyncing.setResult(result);

    when(web3jService.send(any(Request.class), eq(EthSyncing.class)))
            .thenReturn(ethSyncing);
}
 
Example 11
Source Project: web3j   Source File: JsonRpc2_0Besu.java    License: Apache License 2.0 5 votes vote down vote up
public Request<?, BooleanResponse> ibftProposeValidatorVote(
        String address, Boolean validatorAddition) {
    return new Request<>(
            "ibft_proposeValidatorVote",
            Arrays.asList(address, validatorAddition),
            web3jService,
            BooleanResponse.class);
}
 
Example 12
Source Project: client-sdk-java   Source File: JsonRpc2_0Geth.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, PersonalSign> personalSign(
        String message, String accountId, String password) {
    return new Request<>(
            "personal_sign",
            Arrays.asList(message,accountId,password),
            web3jService,
            PersonalSign.class);
}
 
Example 13
Source Project: web3j   Source File: JsonRpc2_0Parity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, NewAccountIdentifier> parityNewAccountFromPhrase(
        String phrase, String password) {
    return new Request<>(
            "parity_newAccountFromPhrase",
            Arrays.asList(phrase, password),
            web3jService,
            NewAccountIdentifier.class);
}
 
Example 14
@SuppressWarnings("unchecked")
private void prepareCall(EthCall ethCall) throws IOException {
    Request<?, EthCall> request = mock(Request.class);
    when(request.send()).thenReturn(ethCall);

    when(web3j.ethCall(any(Transaction.class), eq(DefaultBlockParameterName.LATEST)))
            .thenReturn((Request) request);
}
 
Example 15
Source Project: web3j   Source File: EnsResolverTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testResolve() throws Exception {
    configureSyncing(false);
    configureLatestBlock(System.currentTimeMillis() / 1000); // block timestamp is in seconds

    NetVersion netVersion = new NetVersion();
    netVersion.setResult(Long.toString(ChainIdLong.MAINNET));

    String resolverAddress =
            "0x0000000000000000000000004c641fb9bad9b60ef180c31f56051ce826d21a9a";
    String contractAddress =
            "0x00000000000000000000000019e03255f667bdfd50a32722df860b1eeaf4d635";

    EthCall resolverAddressResponse = new EthCall();
    resolverAddressResponse.setResult(resolverAddress);

    EthCall contractAddressResponse = new EthCall();
    contractAddressResponse.setResult(contractAddress);

    when(web3jService.send(any(Request.class), eq(NetVersion.class))).thenReturn(netVersion);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(resolverAddressResponse);
    when(web3jService.send(any(Request.class), eq(EthCall.class)))
            .thenReturn(contractAddressResponse);

    assertEquals(
            ensResolver.resolve("web3j.eth"), ("0x19e03255f667bdfd50a32722df860b1eeaf4d635"));
}
 
Example 16
Source Project: web3j   Source File: JsonRpc2_0Besu.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, EthAccounts> cliqueGetSigners(DefaultBlockParameter defaultBlockParameter) {
    return new Request<>(
            "clique_getSigners",
            Arrays.asList(defaultBlockParameter.getValue()),
            web3jService,
            EthAccounts.class);
}
 
Example 17
Source Project: web3j   Source File: JsonRpc2_0Parity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Request<?, BooleanResponse> paritySetNewDappsAddresses(
        ArrayList<String> availableAccountIds) {
    return new Request<>(
            "parity_setNewDappsAddresses",
            Arrays.asList(availableAccountIds),
            web3jService,
            BooleanResponse.class);
}
 
Example 18
@Override
public Request<?, EthSendTransaction> personalSendTransaction(
        Transaction transaction, String passphrase) {
    return new Request<>(
            "personal_sendTransaction",
            Arrays.asList(transaction, passphrase),
            web3jService,
            EthSendTransaction.class);
}
 
Example 19
@Override
public Request<?, PersonalEcRecover> personalEcRecover(
        String hexMessage, String signedMessage) {
    return new Request<>(
            "personal_ecRecover",
            Arrays.asList(hexMessage,signedMessage),
            web3jService,
            PersonalEcRecover.class);
}
 
Example 20
@Override
public Request<?, ParityFullTraceResponse> traceReplayTransaction(
        String hash, List<String> traceTypes) {
    return new Request<>(
        "trace_replayTransaction",
        Arrays.asList(hash, traceTypes),
        web3jService,
        ParityFullTraceResponse.class);
}
 
Example 21
Source Project: client-sdk-java   Source File: JsonRpc2_0Admin.java    License: 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);
}
 
Example 22
Source Project: web3j   Source File: JsonRpc2_0Besu.java    License: 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 23
Source Project: web3j   Source File: JsonRpc2_0Geth.java    License: 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 24
Source Project: web3j   Source File: IpcServiceTest.java    License: 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 25
Source Project: web3j   Source File: JsonRpc2_0Geth.java    License: 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 26
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 27
Source Project: web3j-quorum   Source File: JsonRpc2_0Quorum.java    License: 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 28
Source Project: web3j-quorum   Source File: JsonRpc2_0Quorum.java    License: 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 29
Source Project: web3j   Source File: JsonRpc2_0Besu.java    License: 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 30
Source Project: web3j   Source File: JsonRpc2_0Parity.java    License: 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);
}