3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-15 11:45:51 +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. * Creates a Sha256Hash by wrapping the given byte array. It must be 32 bytes long.
*/ */
public Sha256Hash(byte[] bytes) { public Sha256Hash(byte[] rawHashBytes) {
checkArgument(bytes.length == 32); checkArgument(rawHashBytes.length == 32);
this.bytes = bytes; this.bytes = rawHashBytes;
} }
/** /**
* Creates a Sha256Hash by decoding the given hex string. It must be 64 characters long. * Creates a Sha256Hash by decoding the given hex string. It must be 64 characters long.
*/ */
public Sha256Hash(String string) { public Sha256Hash(String hexString) {
checkArgument(string.length() == 64); checkArgument(hexString.length() == 64);
this.bytes = Hex.decode(string); 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 * Returns a hash of the given files contents. Reads the file fully into memory before hashing so only use with
* small files. * small files.