Java Code Examples for net.bither.bitherj.utils.Utils#bytesToHexString()
The following examples show how to use
net.bither.bitherj.utils.Utils#bytesToHexString() .
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: BitcoinSerializer.java From bitherj with Apache License 2.0 | 6 votes |
/** * Deserialize payload only. You must provide a header, typically obtained by calling * {@link BitcoinSerializer#deserializeHeader}. */ public Message deserializePayload(BitcoinPacketHeader header, ByteBuffer in) throws ProtocolException, BufferUnderflowException { byte[] payloadBytes = new byte[header.size]; in.get(payloadBytes, 0, header.size); // Verify the checksum. byte[] hash; hash = doubleDigest(payloadBytes); if (header.checksum[0] != hash[0] || header.checksum[1] != hash[1] || header.checksum[2] != hash[2] || header.checksum[3] != hash[3]) { throw new ProtocolException("Checksum failed to verify, actual " + bytesToHexString(hash) + " vs " + bytesToHexString(header.checksum)); } if (log.isDebugEnabled()) { log.debug("Received {} byte '{}' message: {}", header.size, header.command, Utils.bytesToHexString(payloadBytes)); } try { return makeMessage(header.command, header.size, payloadBytes, hash, header.checksum); } catch (Exception e) { throw new ProtocolException("Error deserializing message " + Utils.bytesToHexString(payloadBytes) + "\n", e); } }
Example 2
Source File: QRCodeEnodeUtil.java From bitherj with Apache License 2.0 | 6 votes |
public static String getPublicKeyStrOfPrivateKey() { String content = ""; List<Address> addresses = AddressManager.getInstance().getPrivKeyAddresses(); for (int i = 0; i < addresses.size(); i++) { Address address = addresses.get(i); String pubStr = ""; if (address.isFromXRandom()) { pubStr = QRCodeUtil.XRANDOM_FLAG; } pubStr = pubStr + Utils.bytesToHexString(address.getPubKey()); content += pubStr; if (i < addresses.size() - 1) { content += QRCodeUtil.QR_CODE_SPLIT; } } content.toUpperCase(Locale.US); return content; }
Example 3
Source File: QRCodeTxTransport.java From bitherj with Apache License 2.0 | 5 votes |
private static QRCodeTxTransport fromDeskpHDMSendRequestWithUnsignedTransaction(TxTransportType txTransportType, Tx tx, List<DesktopHDMAddress> desktopHDMAddresses, String addressCannotParsed) { if (!AddressManager.getInstance().hasDesktopHDMKeychain()) { return null; } QRCodeTxTransport qrCodeTransport = new QRCodeTxTransport(); qrCodeTransport.setMyAddress(tx.getFromAddress()); String toAddress = tx.getFirstOutAddress(); if (Utils.isEmpty(toAddress)) { toAddress = addressCannotParsed; } qrCodeTransport.setToAddress(toAddress); qrCodeTransport.setTo(tx.amountSentToAddress(toAddress)); qrCodeTransport.setFee(tx.getFee()); List<String> hashList = new ArrayList<String>(); if (txTransportType == TxTransportType.DesktopHDM) { for (int i = 0; i < desktopHDMAddresses.size(); i++) { DesktopHDMAddress desktopHDMAddress = desktopHDMAddresses.get(i); for (byte[] h : tx.getUnsignedInHashesForDesktpHDM(desktopHDMAddress.getPubKey(), i)) { String[] strings = new String[]{Integer.toString(desktopHDMAddress.getPathType().getValue()), Integer.toString(desktopHDMAddress.getIndex()), Utils.bytesToHexString(h)}; hashList.add(Utils.joinString(strings, QRCodeUtil.QR_CODE_SECONDARY_SPLIT)); } } } qrCodeTransport.setHashList(hashList); return qrCodeTransport; }
Example 4
Source File: PushTxThirdParty.java From bitherj with Apache License 2.0 | 5 votes |
public void pushTx(Tx tx) { String raw = Utils.bytesToHexString(tx.bitcoinSerialize()); pushToBlockChainInfo(raw); pushToBtcCom(raw); pushToChainQuery(raw); pushToBlockr(raw); pushToBlockExplorer(raw); }
Example 5
Source File: HDMBId.java From bitherj with Apache License 2.0 | 5 votes |
public String getPreSignString() throws Exception { SecureRandom random = new SecureRandom(); decryptedPassword = new byte[32]; random.nextBytes(decryptedPassword); GetHDMBIdRandomApi getHDMBIdRandomApi = new GetHDMBIdRandomApi(address); getHDMBIdRandomApi.handleHttpGet(); serviceRandom = getHDMBIdRandomApi.getResult(); String message = getBitidString(); byte[] hash = Utils.getPreSignMessage(message); return Utils.bytesToHexString(hash); }
Example 6
Source File: Block.java From bitherj with Apache License 2.0 | 5 votes |
private void checkMerkleRoot() throws VerificationException { byte[] calculatedRoot = calculateMerkleRoot(); if (!Arrays.equals(calculatedRoot, blockRoot)) { log.error("Merkle tree did not verify"); throw new VerificationException("Merkle hashes do not match: " + Utils.bytesToHexString(calculatedRoot) + " vs " + Utils.bytesToHexString(blockRoot)); } }
Example 7
Source File: BlockTest.java From bitherj with Apache License 2.0 | 5 votes |
@Test public void testText() { assertEquals("", ""); Block block = new Block(2, "00000000000000003711b624fbde8c77d4c7e25334cfa8bc176b7248ca67b24b", "d1ce608b0e83f5b0c134d27ea6952fc55bc68b5ccf0490bbb47ea1906a7075d0", 1407474112 , 406305378, 2798738616L, 314496); String str = Utils.bytesToHexString(Utils.reverseBytes(block.getBlockHash())); assertEquals("000000000000000030e597a72386c512d830b08ecc70b254f46033fd06f2bf93", str); AbstractDb.blockProvider.addBlock(block); Block testBlock = AbstractDb.blockProvider. getBlock(Utils.reverseBytes(Utils.hexStringToByteArray( "000000000000000030e597a72386c512d830b08ecc70b254f46033fd06f2bf93"))); assertEquals(Utils.bytesToHexString(testBlock.getBlockHash()), Utils.bytesToHexString(block.getBlockHash())); }
Example 8
Source File: UnknownMessage.java From bitherj with Apache License 2.0 | 4 votes |
public String toString() { return "Unknown message [" + name + "]: " + (bytes == null ? "" : Utils.bytesToHexString(bytes)); }
Example 9
Source File: EnterpriseHDMTxSignaturePool.java From bitherj with Apache License 2.0 | 4 votes |
@Override public String toString() { return getClass().getSimpleName() + " :\n tx0: " + Utils.bytesToHexString(unsignedHashes ().get(0)) + "\n threshold: " + threshold() + "\n program: " + Utils .bytesToHexString(multisigProgram); }