本文整理了Java中org.spongycastle.util.encoders.Hex.decode()
方法的一些代码示例,展示了Hex.decode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex.decode()
方法的具体详情如下:
包路径:org.spongycastle.util.encoders.Hex
类名称:Hex
方法名:decode
[英]decode the Hex encoded String data - whitespace will be ignored.
[中]解码十六进制编码的字符串数据-空白将被忽略。
代码示例来源:origin: ethereum/ethereumj
@Override
public byte[] next() {
return Hex.decode(scanner.nextLine());
}
};
代码示例来源:origin: ethereum/ethereumj
@ValidateMe
public byte[] getMineExtraData() {
byte[] bytes;
if (config.hasPath("mine.extraDataHex")) {
bytes = Hex.decode(config.getString("mine.extraDataHex"));
} else {
bytes = config.getString("mine.extraData").getBytes();
}
if (bytes.length > 32) throw new RuntimeException("mine.extraData exceed 32 bytes length: " + bytes.length);
return bytes;
}
代码示例来源:origin: ethereum/ethereumj
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException {
URL url = ClassLoader.getSystemResource(path);
File file = new File(url.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
List<Block> blocks = new ArrayList<>(strData.size());
for (String rlp : strData) {
blocks.add(new Block(decode(rlp)));
}
return blocks;
}
代码示例来源:origin: ethereum/ethereumj
private static void checkKeys(Map<byte[], byte[]> map, String ... keys) {
Assert.assertEquals(keys.length, map.size());
for (String key : keys) {
assertTrue(map.containsKey(Hex.decode(key)));
}
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void test_1() {
byte[] payload = Hex.decode("f90144f9013Bf90136a0d8faffbc4c4213d35db9007de41cece45d95db7fd6c0f129e158baa888c48eefa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794baedba0480e1b882b606cd302d8c4f5701cabac7a0c7d4565fb7b3d98e54a0dec8b76f8c001a784a5689954ce0aedcc1bbe8d13095a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b8400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083063477825fc88609184e72a0008301e8488084543ffee680a00de0b9d4a0f0c23546d31f1f70db00d25cf6a7af79365b4e058e4a6a3b69527bc0c0850177ddbebe");
NewBlockMessage newBlockMessage = new NewBlockMessage(payload);
logger.trace("{}", newBlockMessage);
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void blockTest1() {
String rlp = "f90214a0a9c93d6bcd5dbcc94e0f467c88c59851b0951990c1c340c7b20aa967758ecd87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ee0250c19ad59305b2bdb61f34b45b72fe37154fa0ed230be6c9531d27a387fa5ca2cb2e70848d5de33636ae2a28d5e9e623a3089da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831116b881d9850ec4a4290b8084567406d39ad983010302844765746887676f312e352e318777696e646f7773a09a518a25af220fb8afe23bcafd71e4a0dba0da38972e962b07ed89dab34ac2748872311081e40c488a | f90214a01e479ea9dc53e675780469952ea87d531eb3d47808e2b57339055bdc6e61ae57a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794ee0250c19ad59305b2bdb61f34b45b72fe37154fa0ea92e8c9e36ffe81be59f06af1a3b4b18b778838d4fac19f4dfeb08a5a1046dfa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831118da81da850ec0f300028084567406dd9ad983010302844765746887676f312e352e318777696e646f7773a056bacad6b399e5e39f5168080941d54807f25984544f6bc885bbf1a0ffd0a0298856ceeb676b74d420 | " +
"f90214a0b7992b18db1b3514b90376fe96235bc73db9eba3cb21ecb190d34e9c680c914fa06ab8465069b6d6a758c73894d6fbd2ad98f9c551a7a99672aedba3b12d1e76f594ee0250c19ad59305b2bdb61f34b45b72fe37154fa0499179489d7c04a781c3fd8b8b0f0a04030fd2057a11e86e6a12e4baa07dfdd6a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083111afd81db850ebd42c3438084567406e19ad983010302844765746887676f312e352e318777696e646f7773a04d78ab8e21ea8630f52a60ed60d945c7bbb8267777d28a98612b77a673663430886b676858a8d6b99a | f90204a08680005ea64540a769286d281cb931a97e7abed2611f00f2c6f47a7aaad5faa8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479450b8f981ce93fd5b81b844409169148428400bf3a0bf55a6e82564fb532316e694838dae38d21fa80bc8af1867e418cb26bcdf0e61a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831118da81dc850ebd42c3438084567406f58acccccccccccccccccccca04c2135ea0bb1f148303b201141df207898fa0897e3fb48fe661cda3ba2880da388b4ce6cb5535077af | f90204a05897e0e01ed54cf189751c6dd7b0107b2b3b1c841cb7d9bdb6f2aca6ff770c17a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479450b8f981ce93fd5b81b844409169148428400bf3a01ad754d90de6789c4fa5708992d9f089165e5047d52e09abc22cf49428af23cda056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000831116b781dd850ebd42c3438084567407048acccccccccccccccccccca0b314fab93d91a0adea632fd58027cb39857a0ad188c473f41a640052a6a0141d88d64656f7bb5f1066";
for (String s : rlp.split("\\|")) {
BlockHeader blockHeader = new BlockHeader(Hex.decode(s));
System.out.println(Hex.toHexString(blockHeader.getHash()).substring(0, 6));
System.out.println(blockHeader);
}
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void identityTest1() {
DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000004");
PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config);
byte[] data = Hex.decode("112233445566");
byte[] expected = Hex.decode("112233445566");
byte[] result = contract.execute(data).getRight();
assertArrayEquals(expected, result);
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void testMulModOverflow() {
DataWord wr = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
DataWord w1 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
DataWord w2 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
DataWord actual = wr.mulmod(w1, w2);
assertEquals(32, wr.getData().length);
assertTrue(actual.isZero());
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void testGetAddress() {
ECKey key = ECKey.fromPublicOnly(pubKey);
assertArrayEquals(Hex.decode(address), key.getAddress());
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void testSignExtend2() {
DataWord x = DataWord.of(Hex.decode("f2"));
byte k = 1;
String expected = "00000000000000000000000000000000000000000000000000000000000000f2";
x = x.signExtend(k);
System.out.println(x.toString());
assertEquals(expected, x.toString());
}
代码示例来源:origin: ethereum/ethereumj
@Test // invalid block
public void test_2() {
byte[] rlp = Hex.decode("f90219f90214a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000857147839e5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");
Block b = new Block(rlp);
assertFalse(rule.validate(b.getHeader()).success);
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void test2() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
repository.addBalance(cow, BigInteger.TEN);
repository.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, repository.getBalance(cow));
assertEquals(BigInteger.ONE, repository.getBalance(horse));
repository.close();
}
代码示例来源:origin: ethereum/ethereumj
@Test // COINBASE OP
public void testCOINBASE_1() {
VM vm = new VM();
program =
new Program(Hex.decode("41"), invoke);
String s_expected_1 = "000000000000000000000000E559DE5527492BCB42EC68D07DF0742A98EC3F1E";
vm.step(program);
DataWord item1 = program.stackPop();
assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
代码示例来源:origin: ethereum/ethereumj
@Test // GASLIMIT OP
public void testGASLIMIT_1() {
VM vm = new VM();
program =
new Program(Hex.decode("45"), invoke);
String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000F4240";
vm.step(program);
DataWord item1 = program.stackPop();
assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void realBlockValidateTest2() {
byte[] rlp = Hex.decode("f9021af90215a06b42cf11dbb8a448a118939d1a68773f3deca05f8063d26113dac5f9f8ce6713a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479452bc44d5378309ee2abf1539bf71de1b7d7be3b5a037b5b65861017992bd33375bb71e0752d57eb94972a9496177f056aa340a2843a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008606b6e75611ca830a2ace832fefd880845668803198d783010203844765746887676f312e342e32856c696e7578a08eddfce4ba14ac38363b0534d12ed7ad4c224897dd443730256f04c6f835449f88108919adc0f2952bc0c0");
Block b = new Block(rlp);
System.out.println(b);
boolean valid = Ethash.getForBlock(SystemProperties.getDefault(), b.getNumber()).validate(b.getHeader());
Assert.assertTrue(valid);
}
代码示例来源:origin: ethereum/ethereumj
@Test // CALLDATALOAD OP
public void testCALLDATALOAD_5() {
VM vm = new VM();
program =
new Program(Hex.decode("603F35"), invoke);
String s_expected_1 = "B100000000000000000000000000000000000000000000000000000000000000";
vm.step(program);
vm.step(program);
DataWord item1 = program.stackPop();
assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase());
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void testGenesisFromRLP() {
// from RLP encoding
byte[] genesisBytes = Hex.decode(GENESIS_RLP);
Block genesisFromRLP = new Block(genesisBytes);
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
assertEquals(Hex.toHexString(genesis.getHash()), Hex.toHexString(genesisFromRLP.getHash()));
assertEquals(Hex.toHexString(genesis.getParentHash()), Hex.toHexString(genesisFromRLP.getParentHash()));
assertEquals(Hex.toHexString(genesis.getStateRoot()), Hex.toHexString(genesisFromRLP.getStateRoot()));
}
代码示例来源:origin: ethereum/ethereumj
@Test // SSTORE EIP1283
public void testSSTORE_NET_5() {
VM vm = new VM();
program = new Program(Hex.decode("60016000556001600055"), invoke, constantinopleConfig);
while (!program.isStopped())
vm.step(program);
assertEquals(20212, program.getResult().getGasUsed());
assertEquals(0, program.getResult().getFutureRefund());
}
代码示例来源:origin: ethereum/ethereumj
@Test
public void testStorage2() throws Exception {
RepositoryRoot repo = new RepositoryRoot(new HashMapDB<byte[]>());
Repository repo1 = repo.startTracking();
byte[] addr2 = decode("bbbb");
repo1.addStorageRow(addr2, DataWord.ONE, DataWord.of(111));
repo1.commit();
Assert.assertEquals(DataWord.of(111), repo.getStorageValue(addr2, DataWord.ONE));
}
}
代码示例来源:origin: ethereum/ethereumj
@Test // SSTORE EIP1283
public void testSSTORE_NET_11() {
VM vm = new VM();
setStorageToOne(vm);
program = new Program(Hex.decode("60026000556001600055"), invoke, constantinopleConfig);
while (!program.isStopped())
vm.step(program);
assertEquals(5212, program.getResult().getGasUsed());
assertEquals(4800, program.getResult().getFutureRefund());
}
内容来源于网络,如有侵权,请联系作者删除!