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

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

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

Numeric.prependHexPrefix介绍

暂无

代码示例

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

  1. public Transaction(String from, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit,
  2. String to, BigInteger value, String data) {
  3. this.from = from;
  4. this.to = to;
  5. this.gas = gasLimit;
  6. this.gasPrice = gasPrice;
  7. this.value = value;
  8. if (data != null) {
  9. this.data = Numeric.prependHexPrefix(data);
  10. }
  11. this.nonce = nonce;
  12. }

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

  1. public static Credentials create(ECKeyPair ecKeyPair) {
  2. String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
  3. return new Credentials(ecKeyPair, address);
  4. }

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

  1. @Test
  2. public void testPrependHexPrefix() {
  3. assertThat(Numeric.prependHexPrefix(""), is("0x"));
  4. assertThat(Numeric.prependHexPrefix("0x0123456789abcdef"), is("0x0123456789abcdef"));
  5. assertThat(Numeric.prependHexPrefix("0x"), is("0x"));
  6. assertThat(Numeric.prependHexPrefix("0123456789abcdef"), is("0x0123456789abcdef"));
  7. }

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

  1. @SuppressWarnings("unchecked")
  2. private void prepareEthGetCode(String binary) throws IOException {
  3. EthGetCode ethGetCode = new EthGetCode();
  4. ethGetCode.setResult(Numeric.prependHexPrefix(binary));
  5. Request<?, EthGetCode> ethGetCodeRequest = mock(Request.class);
  6. when(ethGetCodeRequest.send())
  7. .thenReturn(ethGetCode);
  8. when(web3j.ethGetCode(ADDRESS, DefaultBlockParameterName.LATEST))
  9. .thenReturn((Request) ethGetCodeRequest);
  10. }

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

  1. @Test
  2. public void testIsValidPrivateKey() {
  3. assertTrue(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING));
  4. assertTrue(isValidPrivateKey(Numeric.prependHexPrefix(SampleKeys.PRIVATE_KEY_STRING)));
  5. assertFalse(isValidPrivateKey(""));
  6. assertFalse(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING + "a"));
  7. assertFalse(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING.substring(1)));
  8. }

代码示例来源:origin: org.web3j/crypto

  1. public static Credentials create(ECKeyPair ecKeyPair) {
  2. String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
  3. return new Credentials(ecKeyPair, address);
  4. }

代码示例来源:origin: ethjava/web3j-sample

  1. private static void decodeMessage(String signedData) {
  2. //样例 https://ropsten.etherscan.io/tx/0xfd8acd10d72127f29f0a01d8bcaf0165665b5598781fe01ca4bceaa6ab9f2cb0
  3. try {
  4. System.out.println(signedData);
  5. System.out.println("解密 start " + System.currentTimeMillis());
  6. RlpList rlpList = RlpDecoder.decode(Numeric.hexStringToByteArray(signedData));
  7. List<RlpType> values = ((RlpList) rlpList.getValues().get(0)).getValues();
  8. BigInteger nonce = Numeric.toBigInt(((RlpString) values.get(0)).getBytes());
  9. BigInteger gasPrice = Numeric.toBigInt(((RlpString) values.get(1)).getBytes());
  10. BigInteger gasLimit = Numeric.toBigInt(((RlpString) values.get(2)).getBytes());
  11. String to = Numeric.toHexString(((RlpString) values.get(3)).getBytes());
  12. BigInteger value = Numeric.toBigInt(((RlpString) values.get(4)).getBytes());
  13. String data = Numeric.toHexString(((RlpString) values.get(5)).getBytes());
  14. RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
  15. RlpString v = (RlpString) values.get(6);
  16. RlpString r = (RlpString) values.get(7);
  17. RlpString s = (RlpString) values.get(8);
  18. Sign.SignatureData signatureData = new Sign.SignatureData(
  19. v.getBytes()[0],
  20. Numeric.toBytesPadded(Numeric.toBigInt(r.getBytes()), 32),
  21. Numeric.toBytesPadded(Numeric.toBigInt(s.getBytes()), 32));
  22. BigInteger pubKey = Sign.signedMessageToKey(TransactionEncoder.encode(rawTransaction), signatureData);
  23. System.out.println("publicKey " + pubKey.toString(16));
  24. String address = Numeric.prependHexPrefix(Keys.getAddress(pubKey));
  25. System.out.println("address " + address);
  26. System.out.println("解密 end " + System.currentTimeMillis());
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. }
  30. }

相关文章