org.web3j.protocol.core.Request类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.web3j.protocol.core.Request类的一些代码示例,展示了Request类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request类的具体详情如下:
包路径:org.web3j.protocol.core.Request
类名称:Request

Request介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

@Override
public Request<?, ParityAddressesResponse> parityImportGethAccounts(
    ArrayList<String> gethAddresses) {
  return new Request<>(
      "parity_importGethAccounts",
      gethAddresses,
      web3jService,
      ParityAddressesResponse.class);
}

代码示例来源:origin: web3j/web3j

@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);
}

代码示例来源:origin: web3j/web3j

private Optional<TransactionReceipt> sendTransactionReceiptRequest(
    String transactionHash) throws Exception {
  EthGetTransactionReceipt transactionReceipt =
      web3j.ethGetTransactionReceipt(transactionHash).sendAsync().get();
  return transactionReceipt.getTransactionReceipt();
}

代码示例来源:origin: web3j/web3j

private BigInteger getBlockNumber(
    DefaultBlockParameter defaultBlockParameter) throws IOException {
  if (defaultBlockParameter instanceof DefaultBlockParameterNumber) {
    return ((DefaultBlockParameterNumber) defaultBlockParameter).getBlockNumber();
  } else {
    EthBlock latestEthBlock = web3j.ethGetBlockByNumber(
        defaultBlockParameter, false).send();
    return latestEthBlock.getBlock().getNumber();
  }
}

代码示例来源:origin: web3j/web3j

private BigInteger estimateGas(String encodedFunction) throws Exception {
  EthEstimateGas ethEstimateGas = web3j.ethEstimateGas(
      Transaction.createEthCallTransaction(ALICE.getAddress(), null, encodedFunction))
      .sendAsync().get();
  // this was coming back as 50,000,000 which is > the block gas limit of 4,712,388
  // see eth.getBlock("latest")
  return ethEstimateGas.getAmountUsed().divide(BigInteger.valueOf(100));
}

代码示例来源:origin: web3j/web3j

@SuppressWarnings("unchecked")
void prepareNonceRequest() throws IOException {
  EthGetTransactionCount ethGetTransactionCount = new EthGetTransactionCount();
  ethGetTransactionCount.setResult("0x1");
  Request<?, EthGetTransactionCount> transactionCountRequest = mock(Request.class);
  when(transactionCountRequest.send())
      .thenReturn(ethGetTransactionCount);
  when(web3j.ethGetTransactionCount(SampleKeys.ADDRESS, DefaultBlockParameterName.PENDING))
      .thenReturn((Request) transactionCountRequest);
}

代码示例来源:origin: web3j/web3j

@Override
public Request<?, ParityAddressesResponse> parityGetNewDappsAddresses() {
  return new Request<>(
      "parity_getNewDappsAddresses",
      Collections.<String>emptyList(),
      web3jService,
      ParityAddressesResponse.class);
}

代码示例来源:origin: web3j/web3j

boolean unlockAccount() throws Exception {
  PersonalUnlockAccount personalUnlockAccount =
      web3j.personalUnlockAccount(
          ALICE.getAddress(), WALLET_PASSWORD, ACCOUNT_UNLOCK_DURATION)
          .sendAsync().get();
  return personalUnlockAccount.accountUnlocked();
}

代码示例来源:origin: web3j/web3j

@SuppressWarnings("unchecked")
void prepareTransactionReceipt(TransactionReceipt transactionReceipt) throws IOException {
  EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt();
  ethGetTransactionReceipt.setResult(transactionReceipt);
  Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class);
  when(getTransactionReceiptRequest.send())
      .thenReturn(ethGetTransactionReceipt);
  when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH))
      .thenReturn((Request) getTransactionReceiptRequest);
}

代码示例来源:origin: web3j/web3j

@Override
public Request<?, BooleanResponse> parityKillAccount(String accountId, String password) {
  return new Request<>(
      "parity_killAccount",
      Arrays.asList(accountId, password),
      web3jService,
      BooleanResponse.class);
}

代码示例来源:origin: web3j/web3j

@Test(expected = RuntimeException.class)
@SuppressWarnings("unchecked")
public void testInvalidTransactionResponse() throws Throwable {
  prepareNonceRequest();
  EthSendTransaction ethSendTransaction = new EthSendTransaction();
  ethSendTransaction.setError(new Response.Error(1, "Invalid transaction"));
  Request<?, EthSendTransaction> rawTransactionRequest = mock(Request.class);
  when(rawTransactionRequest.sendAsync()).thenReturn(Async.run(() -> ethSendTransaction));
  when(web3j.ethSendRawTransaction(any(String.class)))
      .thenReturn((Request) rawTransactionRequest);
  testErrorScenario();
}

代码示例来源:origin: web3j/web3j

@Test
public void testParitySetAccountMeta() throws Exception {
  Map<String, Object> meta = new HashMap<>(1);
  meta.put("foo", "bar");
  web3j.paritySetAccountMeta("0xfc390d8a8ddb591b010fda52f4db4945742c3809", meta).send();
  verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_setAccountMeta\","
      + "\"params\":[\"0xfc390d8a8ddb591b010fda52f4db4945742c3809\",{\"foo\":\"bar\"}],"
      + "\"id\":1}");
}

代码示例来源:origin: web3j/web3j

@Override
public Request<?, ParityListRecentDapps> parityListRecentDapps() {
  return new Request<>(
      "parity_listRecentDapps",
      Collections.<String>emptyList(),
      web3jService,
      ParityListRecentDapps.class);
}

代码示例来源:origin: web3j/web3j

private String callSmartContractFunction(
      Function function, String contractAddress) throws Exception {

    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
        Transaction.createEthCallTransaction(
            ALICE.getAddress(), contractAddress, encodedFunction),
        DefaultBlockParameterName.LATEST)
        .sendAsync().get();

    return response.getValue();
  }
}

代码示例来源:origin: web3j/web3j

@Test
public void testParityListAccountsWithAccountOffsetNoBlockTag() throws Exception {
  BigInteger maxQuantityReturned = BigInteger.valueOf(100);
  web3j.parityListAccounts(maxQuantityReturned,
      "0x407d73d8a49eeb85d32cf465507dd71d507100c1", null).send();
  //CHECKSTYLE:OFF
  verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
      + "\"params\":[100,\"0x407d73d8a49eeb85d32cf465507dd71d507100c1\"],\"id\":1}");
  //CHECKSTYLE:ON
}

代码示例来源:origin: web3j/web3j

@Override
public Request<?, BooleanResponse> minerStop() {
  return new Request<>(
      "miner_stop",
      Collections.<String>emptyList(),
      web3jService,
      BooleanResponse.class);
}

代码示例来源:origin: web3j/web3j

private String callSmartContractFunction(
    Function function, String contractAddress) throws Exception {
  String encodedFunction = FunctionEncoder.encode(function);
  org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
      Transaction.createEthCallTransaction(
          ALICE.getAddress(), contractAddress, encodedFunction),
      DefaultBlockParameterName.LATEST)
      .sendAsync().get();
  return response.getValue();
}

代码示例来源:origin: web3j/web3j

@Test
public void testParityListAccountsNoAccountOffsetNoBlockTag() throws Exception {
  BigInteger maxQuantityReturned = BigInteger.valueOf(100);
  web3j.parityListAccounts(maxQuantityReturned, null, null).send();
  verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"parity_listAccounts\","
      + "\"params\":[100,null],\"id\":1}");
}

代码示例来源:origin: web3j/web3j

@Override
public Request<?, NetVersion> netVersion() {
  return new Request<>(
      "net_version",
      Collections.<String>emptyList(),
      web3jService,
      NetVersion.class);
}

代码示例来源:origin: web3j/web3j

private String sendTransaction(
    Credentials credentials, String contractAddress, BigInteger gas,
    String encodedFunction) throws Exception {
  BigInteger nonce = getNonce(credentials.getAddress());
  Transaction transaction = Transaction.createFunctionCallTransaction(
      credentials.getAddress(), nonce, Transaction.DEFAULT_GAS, gas, contractAddress,
      encodedFunction);
  org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse =
      web3j.ethSendTransaction(transaction).sendAsync().get();
  assertFalse(transactionResponse.hasError());
  return transactionResponse.getTransactionHash();
}

相关文章

微信公众号

最新文章

更多