Created
May 14, 2019 15:35
-
-
Save cyberpirate92/cf05f659187d23fb515de417cbfc20c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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