3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Clarify some parameter names in Sha256Hash and add a utility method.

This commit is contained in:
Mike Hearn 2013-01-06 21:57:09 +01:00
parent 7e8ed913ec
commit 7fc325900c

View File

@ -41,18 +41,18 @@ public class Sha256Hash implements Serializable {
/**
* Creates a Sha256Hash by wrapping the given byte array. It must be 32 bytes long.
*/
public Sha256Hash(byte[] bytes) {
checkArgument(bytes.length == 32);
this.bytes = bytes;
public Sha256Hash(byte[] rawHashBytes) {
checkArgument(rawHashBytes.length == 32);
this.bytes = rawHashBytes;
}
/**
* Creates a Sha256Hash by decoding the given hex string. It must be 64 characters long.
*/
public Sha256Hash(String string) {
checkArgument(string.length() == 64);
this.bytes = Hex.decode(string);
public Sha256Hash(String hexString) {
checkArgument(hexString.length() == 64);
this.bytes = Hex.decode(hexString);
}
/**
@ -67,6 +67,13 @@ public class Sha256Hash implements Serializable {
}
}
/**
* Calculates the hash of the hash of the contents. This is a standard operation in Bitcoin.
*/
public static Sha256Hash createDouble(byte[] contents) {
return new Sha256Hash(Utils.doubleDigest(contents));
}
/**
* Returns a hash of the given files contents. Reads the file fully into memory before hashing so only use with
* small files.