本文整理了Java中org.web3j.utils.Numeric.prependHexPrefix()
方法的一些代码示例,展示了Numeric.prependHexPrefix()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Numeric.prependHexPrefix()
方法的具体详情如下:
包路径:org.web3j.utils.Numeric
类名称:Numeric
方法名:prependHexPrefix
暂无
代码示例来源:origin: web3j/web3j
public Transaction(String from, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit,
String to, BigInteger value, String data) {
this.from = from;
this.to = to;
this.gas = gasLimit;
this.gasPrice = gasPrice;
this.value = value;
if (data != null) {
this.data = Numeric.prependHexPrefix(data);
}
this.nonce = nonce;
}
代码示例来源:origin: web3j/web3j
public static Credentials create(ECKeyPair ecKeyPair) {
String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
return new Credentials(ecKeyPair, address);
}
代码示例来源:origin: web3j/web3j
@Test
public void testPrependHexPrefix() {
assertThat(Numeric.prependHexPrefix(""), is("0x"));
assertThat(Numeric.prependHexPrefix("0x0123456789abcdef"), is("0x0123456789abcdef"));
assertThat(Numeric.prependHexPrefix("0x"), is("0x"));
assertThat(Numeric.prependHexPrefix("0123456789abcdef"), is("0x0123456789abcdef"));
}
代码示例来源:origin: web3j/web3j
@SuppressWarnings("unchecked")
private void prepareEthGetCode(String binary) throws IOException {
EthGetCode ethGetCode = new EthGetCode();
ethGetCode.setResult(Numeric.prependHexPrefix(binary));
Request<?, EthGetCode> ethGetCodeRequest = mock(Request.class);
when(ethGetCodeRequest.send())
.thenReturn(ethGetCode);
when(web3j.ethGetCode(ADDRESS, DefaultBlockParameterName.LATEST))
.thenReturn((Request) ethGetCodeRequest);
}
代码示例来源:origin: web3j/web3j
@Test
public void testIsValidPrivateKey() {
assertTrue(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING));
assertTrue(isValidPrivateKey(Numeric.prependHexPrefix(SampleKeys.PRIVATE_KEY_STRING)));
assertFalse(isValidPrivateKey(""));
assertFalse(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING + "a"));
assertFalse(isValidPrivateKey(SampleKeys.PRIVATE_KEY_STRING.substring(1)));
}
代码示例来源:origin: org.web3j/crypto
public static Credentials create(ECKeyPair ecKeyPair) {
String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair));
return new Credentials(ecKeyPair, address);
}
代码示例来源:origin: ethjava/web3j-sample
private static void decodeMessage(String signedData) {
//样例 https://ropsten.etherscan.io/tx/0xfd8acd10d72127f29f0a01d8bcaf0165665b5598781fe01ca4bceaa6ab9f2cb0
try {
System.out.println(signedData);
System.out.println("解密 start " + System.currentTimeMillis());
RlpList rlpList = RlpDecoder.decode(Numeric.hexStringToByteArray(signedData));
List<RlpType> values = ((RlpList) rlpList.getValues().get(0)).getValues();
BigInteger nonce = Numeric.toBigInt(((RlpString) values.get(0)).getBytes());
BigInteger gasPrice = Numeric.toBigInt(((RlpString) values.get(1)).getBytes());
BigInteger gasLimit = Numeric.toBigInt(((RlpString) values.get(2)).getBytes());
String to = Numeric.toHexString(((RlpString) values.get(3)).getBytes());
BigInteger value = Numeric.toBigInt(((RlpString) values.get(4)).getBytes());
String data = Numeric.toHexString(((RlpString) values.get(5)).getBytes());
RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
RlpString v = (RlpString) values.get(6);
RlpString r = (RlpString) values.get(7);
RlpString s = (RlpString) values.get(8);
Sign.SignatureData signatureData = new Sign.SignatureData(
v.getBytes()[0],
Numeric.toBytesPadded(Numeric.toBigInt(r.getBytes()), 32),
Numeric.toBytesPadded(Numeric.toBigInt(s.getBytes()), 32));
BigInteger pubKey = Sign.signedMessageToKey(TransactionEncoder.encode(rawTransaction), signatureData);
System.out.println("publicKey " + pubKey.toString(16));
String address = Numeric.prependHexPrefix(Keys.getAddress(pubKey));
System.out.println("address " + address);
System.out.println("解密 end " + System.currentTimeMillis());
} catch (Exception e) {
e.printStackTrace();
}
}
内容来源于网络,如有侵权,请联系作者删除!