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

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

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

Request介绍

暂无

代码示例

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

  1. @Override
  2. public Request<?, ParityAddressesResponse> parityImportGethAccounts(
  3. ArrayList<String> gethAddresses) {
  4. return new Request<>(
  5. "parity_importGethAccounts",
  6. gethAddresses,
  7. web3jService,
  8. ParityAddressesResponse.class);
  9. }

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

  1. @SuppressWarnings("unchecked")
  2. private void prepareCall(EthCall ethCall) throws IOException {
  3. Request<?, EthCall> request = mock(Request.class);
  4. when(request.send()).thenReturn(ethCall);
  5. when(web3j.ethCall(any(Transaction.class), eq(DefaultBlockParameterName.LATEST)))
  6. .thenReturn((Request) request);
  7. }

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

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

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

  1. private BigInteger getBlockNumber(
  2. DefaultBlockParameter defaultBlockParameter) throws IOException {
  3. if (defaultBlockParameter instanceof DefaultBlockParameterNumber) {
  4. return ((DefaultBlockParameterNumber) defaultBlockParameter).getBlockNumber();
  5. } else {
  6. EthBlock latestEthBlock = web3j.ethGetBlockByNumber(
  7. defaultBlockParameter, false).send();
  8. return latestEthBlock.getBlock().getNumber();
  9. }
  10. }

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

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

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

  1. @SuppressWarnings("unchecked")
  2. void prepareNonceRequest() throws IOException {
  3. EthGetTransactionCount ethGetTransactionCount = new EthGetTransactionCount();
  4. ethGetTransactionCount.setResult("0x1");
  5. Request<?, EthGetTransactionCount> transactionCountRequest = mock(Request.class);
  6. when(transactionCountRequest.send())
  7. .thenReturn(ethGetTransactionCount);
  8. when(web3j.ethGetTransactionCount(SampleKeys.ADDRESS, DefaultBlockParameterName.PENDING))
  9. .thenReturn((Request) transactionCountRequest);
  10. }

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

  1. @Override
  2. public Request<?, ParityAddressesResponse> parityGetNewDappsAddresses() {
  3. return new Request<>(
  4. "parity_getNewDappsAddresses",
  5. Collections.<String>emptyList(),
  6. web3jService,
  7. ParityAddressesResponse.class);
  8. }

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

  1. boolean unlockAccount() throws Exception {
  2. PersonalUnlockAccount personalUnlockAccount =
  3. web3j.personalUnlockAccount(
  4. ALICE.getAddress(), WALLET_PASSWORD, ACCOUNT_UNLOCK_DURATION)
  5. .sendAsync().get();
  6. return personalUnlockAccount.accountUnlocked();
  7. }

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

  1. @SuppressWarnings("unchecked")
  2. void prepareTransactionReceipt(TransactionReceipt transactionReceipt) throws IOException {
  3. EthGetTransactionReceipt ethGetTransactionReceipt = new EthGetTransactionReceipt();
  4. ethGetTransactionReceipt.setResult(transactionReceipt);
  5. Request<?, EthGetTransactionReceipt> getTransactionReceiptRequest = mock(Request.class);
  6. when(getTransactionReceiptRequest.send())
  7. .thenReturn(ethGetTransactionReceipt);
  8. when(web3j.ethGetTransactionReceipt(TRANSACTION_HASH))
  9. .thenReturn((Request) getTransactionReceiptRequest);
  10. }

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

  1. @Override
  2. public Request<?, BooleanResponse> parityKillAccount(String accountId, String password) {
  3. return new Request<>(
  4. "parity_killAccount",
  5. Arrays.asList(accountId, password),
  6. web3jService,
  7. BooleanResponse.class);
  8. }

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

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

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

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

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

  1. @Override
  2. public Request<?, ParityListRecentDapps> parityListRecentDapps() {
  3. return new Request<>(
  4. "parity_listRecentDapps",
  5. Collections.<String>emptyList(),
  6. web3jService,
  7. ParityListRecentDapps.class);
  8. }

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

  1. private String callSmartContractFunction(
  2. Function function, String contractAddress) throws Exception {
  3. String encodedFunction = FunctionEncoder.encode(function);
  4. org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
  5. Transaction.createEthCallTransaction(
  6. ALICE.getAddress(), contractAddress, encodedFunction),
  7. DefaultBlockParameterName.LATEST)
  8. .sendAsync().get();
  9. return response.getValue();
  10. }
  11. }

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

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

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

  1. @Override
  2. public Request<?, BooleanResponse> minerStop() {
  3. return new Request<>(
  4. "miner_stop",
  5. Collections.<String>emptyList(),
  6. web3jService,
  7. BooleanResponse.class);
  8. }

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

  1. private String callSmartContractFunction(
  2. Function function, String contractAddress) throws Exception {
  3. String encodedFunction = FunctionEncoder.encode(function);
  4. org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
  5. Transaction.createEthCallTransaction(
  6. ALICE.getAddress(), contractAddress, encodedFunction),
  7. DefaultBlockParameterName.LATEST)
  8. .sendAsync().get();
  9. return response.getValue();
  10. }

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

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

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

  1. @Override
  2. public Request<?, NetVersion> netVersion() {
  3. return new Request<>(
  4. "net_version",
  5. Collections.<String>emptyList(),
  6. web3jService,
  7. NetVersion.class);
  8. }

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

  1. private String sendTransaction(
  2. Credentials credentials, String contractAddress, BigInteger gas,
  3. String encodedFunction) throws Exception {
  4. BigInteger nonce = getNonce(credentials.getAddress());
  5. Transaction transaction = Transaction.createFunctionCallTransaction(
  6. credentials.getAddress(), nonce, Transaction.DEFAULT_GAS, gas, contractAddress,
  7. encodedFunction);
  8. org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse =
  9. web3j.ethSendTransaction(transaction).sendAsync().get();
  10. assertFalse(transactionResponse.hasError());
  11. return transactionResponse.getTransactionHash();
  12. }

相关文章