Skip to content

Instantly share code, notes, and snippets.

@cyberpirate92
Created May 14, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyberpirate92/cf05f659187d23fb515de417cbfc20c2 to your computer and use it in GitHub Desktop.
Save cyberpirate92/cf05f659187d23fb515de417cbfc20c2 to your computer and use it in GitHub Desktop.
public class Block {
public long nonce;
private long timestamp;
public String transactionData;
public String previousBlockHash;
public Block(String transactionData) {
nonce = 0;
timestamp = System.currentTimeMillis();
this.transactionData = transactionData;
}
public String getHash() throws NoSuchAlgorithmException {
return CryptoHelper.sha256(transactionData + String.valueOf(timestamp)
+ String.valueOf(previousBlockHash)
+ String.valueOf(nonce));
}
@Override
public String toString() {
return String.format("%s\t%d\t%d\t%s", previousBlockHash, timestamp, nonce, transactionData);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment