public LNCloseAMessage (Sha256Hash channelHash, Collection<TransactionSignature> signatureList, float feePerByte) { this.channelHash = channelHash.getBytes(); this.signatureList = signatureList.stream().map(TransactionSignature::encodeToBitcoin).collect(Collectors.toList()); this.feePerByte = feePerByte; }
/** * Creates a new instance containing the hash of the calculated hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (two-time) hash */ public static Sha256Hash twiceOf(byte[] contents) { return wrap(hashTwice(contents)); }
public PrunedException(Sha256Hash hash) { super(hash.toString()); this.hash = hash; } public Sha256Hash getHash() {
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Returns the transaction hash as you see them in the block explorer. */ @Override public Sha256Hash getHash() { if (hash == null) { hash = Sha256Hash.wrapReversed(Sha256Hash.hashTwice(unsafeBitcoinSerialize())); } return hash; }
/** * Creates a new instance that wraps the given hash value (represented as a hex string). * * @param hexString a hash value represented as a hex string * @return a new instance * @throws IllegalArgumentException if the given string is not a valid * hex string, or if it does not represent exactly 32 bytes */ public static Sha256Hash wrap(String hexString) { return wrap(Utils.HEX.decode(hexString)); }
/** Use {@link #of(byte[])} instead: this old name is ambiguous. */ @Deprecated public static Sha256Hash create(byte[] contents) { return of(contents); }
/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }
/** * Creates a new instance that wraps the given hash value. * * @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 wrap(byte[] rawHashBytes) { return new Sha256Hash(rawHashBytes); }
/** * Returns true if the block height is either not a checkpoint, or is a checkpoint and the hash matches. */ public boolean passesCheckpoint(int height, Sha256Hash hash) { Sha256Hash checkpointHash = checkpoints.get(height); return checkpointHash == null || checkpointHash.equals(hash); }
/** * Calculates the SHA-256 hash of the given byte range. * * @param input the array containing the bytes to hash * @param offset the offset within the array of the bytes to hash * @param length the number of bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input, int offset, int length) { MessageDigest digest = newDigest(); digest.update(input, offset, length); return digest.digest(); }
/** * Calculates the SHA-256 hash of the given bytes, * and then hashes the resulting hash again. * * @param input the bytes to hash * @return the double-hash (in big-endian order) */ public static byte[] hashTwice(byte[] input) { return hashTwice(input, 0, input.length); }
@Override public int compare(OutPointOutput a, OutPointOutput b) { int depth1 = a.getDepthInBlocks(); int depth2 = b.getDepthInBlocks(); long aValue = a.getValueLong(); long bValue = b.getValueLong(); BigInteger aCoinDepth = BigInteger.valueOf(aValue).multiply(BigInteger.valueOf(depth1)); BigInteger bCoinDepth = BigInteger.valueOf(bValue).multiply(BigInteger.valueOf(depth2)); int c1 = bCoinDepth.compareTo(aCoinDepth); if (c1 != 0) return c1; // The "coin*days" destroyed are equal, sort by value alone to get the lowest transaction size. if (aValue != bValue) return aValue > bValue ? 1 : -1; // They are entirely equivalent (possibly pending) so sort by hash to ensure a total ordering. BigInteger aHash = a.getTxHash().toBigInteger(); BigInteger bHash = b.getTxHash().toBigInteger(); return aHash.compareTo(bHash); } });
/** * Creates a new instance containing the calculated (one-time) hash of the given bytes. * * @param contents the bytes on which the hash value is calculated * @return a new instance containing the calculated (one-time) hash */ public static Sha256Hash of(byte[] contents) { return wrap(hash(contents)); }
/** * Creates a new instance that wraps the given hash value (represented as a hex string). * * @param hexString a hash value represented as a hex string * @return a new instance * @throws IllegalArgumentException if the given string is not a valid * hex string, or if it does not represent exactly 32 bytes */ public static Sha256Hash wrap(String hexString) { return wrap(Utils.HEX.decode(hexString)); }
/** Use {@link #of(byte[])} instead: this old name is ambiguous. */ @Deprecated public static Sha256Hash create(byte[] contents) { return of(contents); }
private static Sha256Hash combineLeftRight(byte[] left, byte[] right) { return Sha256Hash.wrapReversed(Sha256Hash.hashTwice( reverseBytes(left), 0, 32, reverseBytes(right), 0, 32)); }
/** * Calculates the SHA-256 hash of the given bytes. * * @param input the bytes to hash * @return the hash (in big-endian order) */ public static byte[] hash(byte[] input) { return hash(input, 0, input.length); }