org.web3j.utils.Numeric.encodeQuantity()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.7k)|赞(0)|评价(0)|浏览(124)

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

Numeric.encodeQuantity介绍

暂无

代码示例

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

  1. private String convert(BigInteger value) {
  2. if (value != null) {
  3. return Numeric.encodeQuantity(value);
  4. } else {
  5. return null;
  6. }
  7. }
  8. }

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

  1. private static String convert(BigInteger value) {
  2. if (value != null) {
  3. return Numeric.encodeQuantity(value);
  4. } else {
  5. return null; // we don't want the field to be encoded if not present
  6. }
  7. }
  8. }

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

  1. @Override
  2. @JsonValue
  3. public String getValue() {
  4. return Numeric.encodeQuantity(blockNumber);
  5. }

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

  1. @Override
  2. public Request<?, EthBlock> ethGetUncleByBlockHashAndIndex(
  3. String blockHash, BigInteger transactionIndex) {
  4. return new Request<>(
  5. "eth_getUncleByBlockHashAndIndex",
  6. Arrays.asList(
  7. blockHash,
  8. Numeric.encodeQuantity(transactionIndex)),
  9. web3jService,
  10. EthBlock.class);
  11. }

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

  1. @Override
  2. public Request<?, EthTransaction> ethGetTransactionByBlockHashAndIndex(
  3. String blockHash, BigInteger transactionIndex) {
  4. return new Request<>(
  5. "eth_getTransactionByBlockHashAndIndex",
  6. Arrays.asList(
  7. blockHash,
  8. Numeric.encodeQuantity(transactionIndex)),
  9. web3jService,
  10. EthTransaction.class);
  11. }

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

  1. @Override
  2. public Request<?, EthGetStorageAt> ethGetStorageAt(
  3. String address, BigInteger position, DefaultBlockParameter defaultBlockParameter) {
  4. return new Request<>(
  5. "eth_getStorageAt",
  6. Arrays.asList(
  7. address,
  8. Numeric.encodeQuantity(position),
  9. defaultBlockParameter.getValue()),
  10. web3jService,
  11. EthGetStorageAt.class);
  12. }

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

  1. @Override
  2. public Request<?, EthBlock> ethGetUncleByBlockNumberAndIndex(
  3. DefaultBlockParameter defaultBlockParameter, BigInteger uncleIndex) {
  4. return new Request<>(
  5. "eth_getUncleByBlockNumberAndIndex",
  6. Arrays.asList(
  7. defaultBlockParameter.getValue(),
  8. Numeric.encodeQuantity(uncleIndex)),
  9. web3jService,
  10. EthBlock.class);
  11. }

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

  1. @Override
  2. public Request<?, EthTransaction> ethGetTransactionByBlockNumberAndIndex(
  3. DefaultBlockParameter defaultBlockParameter, BigInteger transactionIndex) {
  4. return new Request<>(
  5. "eth_getTransactionByBlockNumberAndIndex",
  6. Arrays.asList(
  7. defaultBlockParameter.getValue(),
  8. Numeric.encodeQuantity(transactionIndex)),
  9. web3jService,
  10. EthTransaction.class);
  11. }

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

  1. @Test
  2. public void testQuantityEncode() {
  3. assertThat(Numeric.encodeQuantity(BigInteger.valueOf(0)), is("0x0"));
  4. assertThat(Numeric.encodeQuantity(BigInteger.valueOf(1)), is("0x1"));
  5. assertThat(Numeric.encodeQuantity(BigInteger.valueOf(1024)), is("0x400"));
  6. assertThat(Numeric.encodeQuantity(
  7. BigInteger.valueOf(Long.MAX_VALUE)), is("0x7fffffffffffffff"));
  8. assertThat(Numeric.encodeQuantity(
  9. new BigInteger("204516877000845695339750056077105398031")),
  10. is("0x99dc848b94efc27edfad28def049810f"));
  11. }

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

  1. @Test(expected = MessageEncodingException.class)
  2. public void testQuantityEncodeNegative() {
  3. Numeric.encodeQuantity(BigInteger.valueOf(-1));
  4. }

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

  1. private EthBlock createBlockWithTransactions(int blockNumber, List<Transaction> transactions) {
  2. EthBlock ethBlock = new EthBlock();
  3. EthBlock.Block block = new EthBlock.Block();
  4. block.setNumber(Numeric.encodeQuantity(BigInteger.valueOf(blockNumber)));
  5. List<EthBlock.TransactionResult> transactionResults =
  6. transactions.stream()
  7. .map(it -> (EthBlock.TransactionResult<Transaction>) () -> it)
  8. .collect(Collectors.toList());
  9. block.setTransactions(transactionResults);
  10. ethBlock.setResult(block);
  11. return ethBlock;
  12. }

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

  1. private void configureLatestBlock(long timestamp) throws IOException {
  2. EthBlock.Block block = new EthBlock.Block();
  3. block.setTimestamp(Numeric.encodeQuantity(BigInteger.valueOf(timestamp)));
  4. EthBlock ethBlock = new EthBlock();
  5. ethBlock.setResult(block);
  6. when(web3jService.send(any(Request.class), eq(EthBlock.class)))
  7. .thenReturn(ethBlock);
  8. }

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

  1. private EthBlock createBlock(int number) {
  2. EthBlock ethBlock = new EthBlock();
  3. EthBlock.Block block = new EthBlock.Block();
  4. block.setNumber(Numeric.encodeQuantity(BigInteger.valueOf(number)));
  5. ethBlock.setResult(block);
  6. return ethBlock;
  7. }

代码示例来源:origin: web3j/web3j-spring-boot-starter

  1. Mockito.when(web3j.ethBlockNumber().sendAsync()).thenReturn(supplyAsync(() -> {
  2. EthBlockNumber ethBlockNumber = new EthBlockNumber();
  3. ethBlockNumber.setResult(Numeric.encodeQuantity(blockNumber));
  4. return ethBlockNumber;
  5. }));
  6. Mockito.when(web3j.netPeerCount().sendAsync()).thenReturn(supplyAsync(() -> {
  7. NetPeerCount netPeerCount = new NetPeerCount();
  8. netPeerCount.setResult(Numeric.encodeQuantity(netPeer));
  9. return netPeerCount;
  10. }));

相关文章