Java Code Examples for org.spongycastle.util.encoders.Hex#toHexString()
The following examples show how to use
org.spongycastle.util.encoders.Hex#toHexString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrieImpl.java From nuls with MIT License | 5 votes |
private static String val2str(byte[] val, boolean shortHash) { String ret = Hex.toHexString(val); if (val.length > 16) { ret = ret.substring(0, 10) + "... len " + val.length; } return "\"" + ret + "\""; }
Example 2
Source File: DecodeResult.java From asf-sdk with GNU General Public License v3.0 | 5 votes |
private String asString(Object decoded) { if (decoded instanceof String) { return (String) decoded; } else if (decoded instanceof byte[]) { return Hex.toHexString((byte[]) decoded); } else if (decoded instanceof Object[]) { String result = ""; for (Object item : (Object[]) decoded) { result += asString(item); } return result; } throw new RuntimeException("Not a valid type. Should not occur"); }
Example 3
Source File: WalletClient.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get a Wallet from storage. */ public static WalletClient getWalletByStorage(String password) { String priKeyEnced = loadPriKey(); if (priKeyEnced == null) { return null; } //dec priKey byte[] priKeyAscEnced = priKeyEnced.getBytes(); byte[] priKeyHexEnced = Hex.decode(priKeyAscEnced); byte[] aesKey = getEncKey(password); byte[] priKeyHexPlain = SymmEncoder.AES128EcbDec(priKeyHexEnced, aesKey); String priKeyPlain = Hex.toHexString(priKeyHexPlain); return new WalletClient(priKeyPlain); }
Example 4
Source File: ByteArrayWrapper.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public String toString() { return Hex.toHexString(data); }
Example 5
Source File: ShiftCommand004.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftLeft,value is " + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test7ShiftLeft() { String filePath = "src/test/resources/soliditycode_v0.5.4/ShiftCommand001.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getByCodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abi").toString(); contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) .getData(); byte[] valueNumber = new DataWord( ByteArray.fromHexString("0x01")).getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "shlTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 6
Source File: ShiftCommand006.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0xff") public void test4ShiftRightSigned() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) .getData(); byte[] valueNumber = new DataWord( ByteArray .fromHexString("0xff")) .getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "sarTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Long returnnumber14 = ByteArray.toLong(ByteArray .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 7
Source File: Bloom.java From asf-sdk with GNU General Public License v3.0 | 4 votes |
@Override public String toString() { return Hex.toHexString(data); }
Example 8
Source File: ShiftCommand006.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + "0x8000000000000000000000000000000000000000000000000000000000000000 and Displacement number" + "is 0x01") public void test3ShiftRightSigned() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")) .getData(); byte[] valueNumber = new DataWord( ByteArray.fromHexString("0x01")).getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "sarTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0xc000000000000000000000000000000000000000000000000000000000000000")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 9
Source File: DataWord.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
public String toHexString() { return Hex.toHexString(data); }
Example 10
Source File: ShiftCommand006.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftRightSigned,value is " + "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0xf8") public void testShiftRightSigned13() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) .getData(); byte[] valueNumber = new DataWord( ByteArray .fromHexString("0xf8")) .getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "sarTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Long returnnumber14 = ByteArray.toLong(ByteArray .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0x000000000000000000000000000000000000000000000000000000000000007f")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 11
Source File: WalletManager.java From tron-wallet-android with Apache License 2.0 | 4 votes |
public static Protocol.TransactionInfo getTransactionInfo(Transaction transaction) { String txID = Hex.toHexString(Hash.sha256(transaction.getRawData().toByteArray())); return rpcCli.getTransactionInfo(txID); }
Example 12
Source File: Keccak.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
private BigInteger[][] padding(String message, Parameters parameters) { int size; message = message + parameters.getD(); while (((message.length() / 2) * 8 % parameters.getR()) != ((parameters.getR() - 8))) { message = message + "00"; } message = message + "80"; size = (((message.length() / 2) * 8) / parameters.getR()); BigInteger[][] arrayM = new BigInteger[size][]; arrayM[0] = new BigInteger[1600 / w]; initArray(arrayM[0]); int count = 0; int j = 0; int i = 0; for (int _n = 0; _n < message.length(); _n++) { if (j > (parameters.getR() / w - 1)) { j = 0; i++; arrayM[i] = new BigInteger[1600 / w]; initArray(arrayM[i]); } count++; if ((count * 4 % w) == 0) { String subString = message.substring((count - w / 4), (w / 4) + (count - w / 4)); arrayM[i][j] = new BigInteger(subString, 16); String revertString = Hex.toHexString(reverse((arrayM[i][j].toByteArray()))); revertString = addZero(revertString, subString.length()); arrayM[i][j] = new BigInteger(revertString, 16); j++; } } return arrayM; }
Example 13
Source File: ShiftCommand004.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftLeft,value is " + "0x0000000000000000000000000000000000000000000000000000000000000001 and Displacement number" + "is 0xff") public void test3ShiftLeft() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000001")) .getData(); byte[] valueNumber = new DataWord( ByteArray .fromHexString("0xff")) .getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "shlTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0x8000000000000000000000000000000000000000000000000000000000000000")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 14
Source File: ShiftCommand005.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftRight,value is " + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0101") public void testShiftRight12() { String filePath = "src/test/resources/soliditycode_v0.5.4/GvmNewCommand043.sol"; String contractName = "TestBitwiseShift"; HashMap retMap = PublicMethed.getByCodeAbi(filePath, contractName); String code = retMap.get("byteCode").toString(); String abi = retMap.get("abi").toString(); contractAddress = PublicMethed.deployContract(contractName, abi, code, "", maxFeeLimit, 0L, 100, null, contractExcKey, contractExcAddress, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) .getData(); byte[] valueNumber = new DataWord( ByteArray.fromHexString("0x0101")).getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "shrTest(int256,int256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 15
Source File: ShiftCommand005.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftRight,value is " + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x01") public void test8ShiftRight() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) .getData(); byte[] valueNumber = new DataWord( ByteArray.fromHexString("0x01")).getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "shrTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); Long returnnumber14 = ByteArray.toLong(ByteArray .fromHexString(ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray()))); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 16
Source File: StateTest.java From ethereumj with MIT License | 4 votes |
@Test // right way to calc tx trie hash public void testCalculatePostTxState() { /* txTrieHash */ String expected = "a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f"; Transaction tx = new Transaction( new byte[]{}, Hex.decode("09184E72A000"), Hex.decode("03E8"), Hex.decode("0000000000000000000000000000000000000000"), Hex.decode("03e8"), Hex.decode("60016000546006601160003960066000f261778e600054") ); byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4"); tx.sign(cowPrivKey); byte[] postTxState = Hex.decode("7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527"); byte[] cumGas = Hex.decode("0272"); TransactionReceipt tr = new TransactionReceipt(tx, postTxState, cumGas); Trie trie = new TrieImpl(new MockDB()); trie.update(RLP.encodeInt(0), tr.getEncoded()); String txTrieRoot = Hex.toHexString(trie.getRootHash()); assertEquals(expected, txTrieRoot); /* *** GROSS DATA *** BlockData [ hash=22cf863ab836a6f5c29389d2e77f4792a3b3b52908c98ed14b1cbe91491a3e36 parentHash=77ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6cd9225d285c89 unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 coinbase=4c5f4d519dff3c16f0d54b6866e256fbbbc1a600 stateHash=69c21ff84a5af0b53b11c61110a16d6ad43dad37b3eb29ae8e88c936eb06456a txTrieHash=a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f difficulty=3ff000 number=1 minGasPrice=10000000000000 gasLimit=999023 gasUsed=626 timestamp=1401979976 (2014.06.05 15:52:56) extraData=null nonce=0000000000000000000000000000000000000000000000005d439960040e4505 TransactionReceipt[ TransactionData [ hash=1ee6fa3149a5e9c09b54009eb6e108aaa7ecd79483d57eedcf2dff93a1505588 nonce=null, gasPrice=09184e72a000, gas=03e8, receiveAddress=0000000000000000000000000000000000000000, value=03e8, data=60016000546006601160003960066000f261778e600054, signatureV=27, signatureR=2b379f22050e3554c3fa5423d9040bb28dcc7f905300db4e67c03bcf9b27003c, signatureS=59f47793e050974e6b5fca2848b19925637b883a012693b54d712f1c4f74def5 ] , postTxState=7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527 , cumulativeGas=0272] ] +++ 4c5f4d519dff3c16f0d54b6866e256fbbbc1a600: +++ 77045e71a7a2c50903d88e564cd72fab11e82051: $[61,77,8e,60,0,54] ([]) * cd2a3d9f938e13cd947ec05abc7fe734df8dd826: #1 1606938044258990275541962092341162602522202987522792835300376 (-6260000000001000) */ }
Example 17
Source File: ShiftCommand004.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Test(enabled = true, description = "Trigger new ShiftLeft,value is " + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff and Displacement number" + "is 0x0100") public void test9ShiftLeft() { Account info; AccountResourceMessage resourceInfo = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); info = PublicMethed.queryAccount(contractExcKey, blockingStubFull); Long beforeBalance = info.getBalance(); Long beforeCpuUsed = resourceInfo.getCpuUsed(); Long beforeNetUsed = resourceInfo.getNetUsed(); Long beforeFreeNetUsed = resourceInfo.getFreeNetUsed(); logger.info("beforeBalance:" + beforeBalance); logger.info("beforeCpuUsed:" + beforeCpuUsed); logger.info("beforeNetUsed:" + beforeNetUsed); logger.info("beforeFreeNetUsed:" + beforeFreeNetUsed); String txid = ""; byte[] originNumber = new DataWord( ByteArray .fromHexString("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) .getData(); byte[] valueNumber = new DataWord( ByteArray.fromHexString("0x0100")).getData(); byte[] paramBytes = new byte[originNumber.length + valueNumber.length]; System.arraycopy(valueNumber, 0, paramBytes, 0, valueNumber.length); System.arraycopy(originNumber, 0, paramBytes, valueNumber.length, originNumber.length); String param = Hex.toHexString(paramBytes); txid = PublicMethed.triggerContract(contractAddress, "shlTest(uint256,uint256)", param, true, 0, maxFeeLimit, contractExcAddress, contractExcKey, blockingStubFull); PublicMethed.waitProduceNextBlock(blockingStubFull); Optional<TransactionInfo> infoById = null; infoById = PublicMethed.getTransactionInfoById(txid, blockingStubFull); Long fee = infoById.get().getFee(); Long netUsed = infoById.get().getReceipt().getNetUsage(); Long cpuUsed = infoById.get().getReceipt().getCpuUsage(); Long netFee = infoById.get().getReceipt().getNetFee(); long cpuUsageTotal = infoById.get().getReceipt().getCpuUsageTotal(); logger.info("fee:" + fee); logger.info("netUsed:" + netUsed); logger.info("cpuUsed:" + cpuUsed); logger.info("netFee:" + netFee); logger.info("cpuUsageTotal:" + cpuUsageTotal); Account infoafter = PublicMethed.queryAccount(contractExcKey, blockingStubFull); AccountResourceMessage resourceInfoafter = PublicMethed.getAccountResource(contractExcAddress, blockingStubFull); Long afterBalance = infoafter.getBalance(); Long afterCpuUsed = resourceInfoafter.getCpuUsed(); Long afterNetUsed = resourceInfoafter.getNetUsed(); Long afterFreeNetUsed = resourceInfoafter.getFreeNetUsed(); logger.info("afterBalance:" + afterBalance); logger.info("afterCpuUsed:" + afterCpuUsed); logger.info("afterNetUsed:" + afterNetUsed); logger.info("afterFreeNetUsed:" + afterFreeNetUsed); Assert.assertTrue(infoById.get().getResultValue() == 0); Assert.assertTrue(afterBalance + fee == beforeBalance); Assert.assertTrue(beforeCpuUsed + cpuUsed >= afterCpuUsed); Assert.assertTrue(beforeFreeNetUsed + netUsed >= afterFreeNetUsed); Assert.assertTrue(beforeNetUsed + netUsed >= afterNetUsed); String returnString = (ByteArray .toHexString(infoById.get().getContractResult(0).toByteArray())); logger.info("returnString:" + returnString); Assert.assertEquals(ByteArray.toLong(ByteArray .fromHexString("0x0000000000000000000000000000000000000000000000000000000000000000")), ByteArray.toLong(ByteArray .fromHexString( ByteArray.toHexString(infoById.get().getContractResult(0).toByteArray())))); }
Example 18
Source File: Wallet.java From ethereumj with MIT License | 4 votes |
public void importKey(byte[] privKey) { Account account = new Account(ECKey.fromPrivate(privKey)); String address = Hex.toHexString(account.getEcKey().getAddress()); rows.put(address, account); notifyListeners(); }
Example 19
Source File: ByteUtil.java From BlockchainWallet-Crypto with GNU General Public License v3.0 | 2 votes |
/** * Convert a byte-array into a hex String.<br> * Works similar to {@link Hex#toHexString} * but allows for <code>null</code> * * @param data - byte-array to convert to a hex-string * @return hex representation of the data.<br> * Returns an empty String if the input is <code>null</code> * * @see Hex#toHexString */ public static String toHexString(byte[] data) { return data == null ? "" : Hex.toHexString(data); }
Example 20
Source File: CommonWallet.java From wkcwallet-java with Apache License 2.0 | 2 votes |
/** * Get HEX Format PublicKey Key * * @return PublicKey Key with HEX Format */ public String getPublicKeyString() { return Hex.toHexString(this._eckey.getPubKey()); }