/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Encodes the value into its minimal representation. * * @return the minimal encoded bytes of the value */ public byte[] encode() { byte[] bytes; switch (sizeOf(value)) { case 1: return new byte[]{(byte) value}; case 3: return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; case 5: bytes = new byte[5]; bytes[0] = (byte) 254; Utils.uint32ToByteArrayLE(value, bytes, 1); return bytes; default: bytes = new byte[9]; bytes[0] = (byte) 255; Utils.uint64ToByteArrayLE(value, bytes, 1); return bytes; } } }
/** * Encodes the value into its minimal representation. * * @return the minimal encoded bytes of the value */ public byte[] encode() { byte[] bytes; switch (sizeOf(value)) { case 1: return new byte[]{(byte) value}; case 3: return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; case 5: bytes = new byte[5]; bytes[0] = (byte) 254; Utils.uint32ToByteArrayLE(value, bytes, 1); return bytes; default: bytes = new byte[9]; bytes[0] = (byte) 255; Utils.uint64ToByteArrayLE(value, bytes, 1); return bytes; } } }
/** * Encodes the value into its minimal representation. * * @return the minimal encoded bytes of the value */ public byte[] encode() { byte[] bytes; switch (sizeOf(value)) { case 1: return new byte[]{(byte) value}; case 3: return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; case 5: bytes = new byte[5]; bytes[0] = (byte) 254; Utils.uint32ToByteArrayLE(value, bytes, 1); return bytes; default: bytes = new byte[9]; bytes[0] = (byte) 255; Utils.uint64ToByteArrayLE(value, bytes, 1); return bytes; } } }
/** * Encodes the value into its minimal representation. * * @return the minimal encoded bytes of the value */ public byte[] encode() { byte[] bytes; switch (sizeOf(value)) { case 1: return new byte[]{(byte) value}; case 3: return new byte[]{(byte) 253, (byte) (value), (byte) (value >> 8)}; case 5: bytes = new byte[5]; bytes[0] = (byte) 254; Utils.uint32ToByteArrayLE(value, bytes, 1); return bytes; default: bytes = new byte[9]; bytes[0] = (byte) 255; Utils.uint64ToByteArrayLE(value, bytes, 1); return bytes; } } }
public Sha256Hash getHash() { byte [] dataToHash = new byte[pubKeyCollateralAddress.getBytes().length+8]; Utils.uint32ToByteArrayLE(sigTime, dataToHash, 0); System.arraycopy(pubKeyCollateralAddress.getBytes(), 0, dataToHash, 8, pubKeyCollateralAddress.getBytes().length); try { UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(8 + vin.getMessageSize() + pubKeyCollateralAddress.calculateMessageSizeInBytes()); vin.bitcoinSerialize(bos); Utils.int64ToByteStreamLE(sigTime, bos); pubKeyCollateralAddress.bitcoinSerialize(bos); return Sha256Hash.wrapReversed(Sha256Hash.hashTwice((bos.toByteArray()))); } catch (IOException e) { throw new RuntimeException(e); // Cannot happen. } }
Utils.uint32ToByteArrayLE((long)b64Original.block.getTransactions().size(), varIntBytes, 1); Utils.uint32ToByteArrayLE(((long)b64Original.block.getTransactions().size()) >>> 32, varIntBytes, 5); stream.write(varIntBytes); checkState(new VarInt(varIntBytes, 0).value == b64Original.block.getTransactions().size()); Utils.uint32ToByteArrayLE(Script.MAX_SCRIPT_ELEMENT_SIZE + 1, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1); tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript)); addOnlyInputToTransaction(tx, b73); Utils.uint32ToByteArrayLE(Block.MAX_BLOCK_SIGOPS, outputScript, Block.MAX_BLOCK_SIGOPS - sigOps + 1); tx.addOutput(new TransactionOutput(params, tx, SATOSHI, outputScript)); addOnlyInputToTransaction(tx, b76);