/** * Returns a reversed copy of the internal byte array. */ public byte[] getReversedBytes() { return Utils.reverseBytes(bytes); }
/** * Returns a reversed copy of the internal byte array. */ public byte[] getReversedBytes() { return Utils.reverseBytes(bytes); }
/** * Returns a reversed copy of the internal byte array. */ public byte[] getReversedBytes() { return Utils.reverseBytes(bytes); }
public static void uint64ToByteStreamLE(BigInteger val, OutputStream stream) throws IOException { byte[] bytes = val.toByteArray(); if (bytes.length > 8) { throw new RuntimeException("Input too large to encode into a uint64"); } bytes = reverseBytes(bytes); stream.write(bytes); if (bytes.length < 8) { for (int i = 0; i < 8 - bytes.length; i++) stream.write(0); } }
public static void uint64ToByteStreamLE(BigInteger val, OutputStream stream) throws IOException { byte[] bytes = val.toByteArray(); if (bytes.length > 8) { throw new RuntimeException("Input too large to encode into a uint64"); } bytes = reverseBytes(bytes); stream.write(bytes); if (bytes.length < 8) { for (int i = 0; i < 8 - bytes.length; i++) stream.write(0); } }
private static Sha256Hash combineLeftRight(byte[] left, byte[] right) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice( reverseBytes(left), 0, 32, reverseBytes(right), 0, 32)); }
private static Sha256Hash combineLeftRight(byte[] left, byte[] right) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice( reverseBytes(left), 0, 32, reverseBytes(right), 0, 32)); }
/** * Creates a new instance that wraps the given hash value, but with byte order reversed. * * @param rawHashBytes the raw hash bytes to wrap * @return a new instance * @throws IllegalArgumentException if the given array length is not exactly 32 */ @SuppressWarnings("deprecation") // the constructor will be made private in the future public static Sha256Hash wrapReversed(byte[] rawHashBytes) { return wrap(Utils.reverseBytes(rawHashBytes)); }
private static Sha256Hash combineLeftRight(byte[] left, byte[] right) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice( reverseBytes(left), 0, 32, reverseBytes(right), 0, 32)); }
/** * Creates a new instance that wraps the given hash value, but with byte order reversed. * * @param rawHashBytes the raw hash bytes to wrap * @return a new instance * @throws IllegalArgumentException if the given array length is not exactly 32 */ @SuppressWarnings("deprecation") // the constructor will be made private in the future public static Sha256Hash wrapReversed(byte[] rawHashBytes) { return wrap(Utils.reverseBytes(rawHashBytes)); }
private static Sha256Hash combineLeftRight(byte[] left, byte[] right) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice( reverseBytes(left), 0, 32, reverseBytes(right), 0, 32)); }
protected BigInteger readUint64() throws ProtocolException { // Java does not have an unsigned 64 bit type. So scrape it off the wire then flip. return new BigInteger(Utils.reverseBytes(readBytes(8))); }
/** * Creates a new instance that wraps the given hash value, but with byte order reversed. * * @param rawHashBytes the raw hash bytes to wrap * @return a new instance * @throws IllegalArgumentException if the given array length is not exactly 32 */ @SuppressWarnings("deprecation") // the constructor will be made private in the future public static Sha256Hash wrapReversed(byte[] rawHashBytes) { return wrap(Utils.reverseBytes(rawHashBytes)); }
/** * Cast a script chunk to a BigInteger. * * @see #castToBigInteger(byte[], int, boolean) for values with different maximum * sizes. * @throws ScriptException if the chunk is longer than 4 bytes. */ private static BigInteger castToBigInteger(byte[] chunk) throws ScriptException { if (chunk.length > 4) throw new ScriptException("Script attempted to use an integer larger than 4 bytes"); return Utils.decodeMPI(Utils.reverseBytes(chunk), false); }
private ScryptHash calculateScryptHash() { try { ByteArrayOutputStream bos = new UnsafeByteArrayOutputStream(HEADER_SIZE); writeHeader(bos); return new ScryptHash(reverseBytes(scryptDigest(bos.toByteArray()))); } catch (IOException e) { throw new RuntimeException(e); // Cannot happen. } catch (GeneralSecurityException e) { throw new RuntimeException(e); // Cannot happen. } }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { stream.write(new VarInt(hashes.size()).encode()); for (Sha256Hash hash: hashes) { stream.write(Utils.reverseBytes(hash.getBytes())); } Utils.uint32ToByteStreamLE(index, stream); }
@Override protected void bitcoinSerializeToStream(OutputStream stream) throws IOException { transaction.bitcoinSerialize(stream); stream.write(Utils.reverseBytes(hashBlock.getBytes())); coinbaseBranch.bitcoinSerialize(stream); chainMerkleBranch.bitcoinSerialize(stream); parentBlockHeader.bitcoinSerializeToStream(stream); }
@Test public void testReverseBytes() { assertArrayEquals(new byte[]{1, 2, 3, 4, 5}, Utils.reverseBytes(new byte[]{5, 4, 3, 2, 1})); }
public static Script createCLTVPaymentChannelOutput(BigInteger time, ECKey from, ECKey to) { byte[] timeBytes = Utils.reverseBytes(Utils.encodeMPI(time, false)); if (timeBytes.length > 5) { throw new RuntimeException("Time too large to encode as 5-byte int"); } return new ScriptBuilder().op(OP_IF) .data(to.getPubKey()).op(OP_CHECKSIGVERIFY) .op(OP_ELSE) .data(timeBytes).op(OP_CHECKLOCKTIMEVERIFY).op(OP_DROP) .op(OP_ENDIF) .data(from.getPubKey()).op(OP_CHECKSIG).build(); }
public static Script createCLTVPaymentChannelOutput(BigInteger time, ECKey from, ECKey to) { byte[] timeBytes = Utils.reverseBytes(Utils.encodeMPI(time, false)); if (timeBytes.length > 5) { throw new RuntimeException("Time too large to encode as 5-byte int"); } return new ScriptBuilder().op(OP_IF) .data(to.getPubKey()).op(OP_CHECKSIGVERIFY) .op(OP_ELSE) .data(timeBytes).op(OP_CHECKLOCKTIMEVERIFY).op(OP_DROP) .op(OP_ENDIF) .data(from.getPubKey()).op(OP_CHECKSIG).build(); }