Skip to content

Instantly share code, notes, and snippets.

@spenserhuang
Last active December 28, 2017 06:35
Show Gist options
  • Save spenserhuang/4715ce9a82dfe100ecc469d980d8fc14 to your computer and use it in GitHub Desktop.
Save spenserhuang/4715ce9a82dfe100ecc469d980d8fc14 to your computer and use it in GitHub Desktop.
Block Object with calculateHash Function
const SHA256 = require('crypto-js/sha256')
class Block {
constructor(timestamp, data) {
this.index = 0;
this.timestamp = timestamp;
this.data = data;
this.previousHash = "0";
this.hash = this.calculateHash();
this.nonce = 0;
}
calculateHash() {
return SHA256(this.index + this.previousHash + this.timestamp + this.data + this.nonce).toString();
}
mineBlock(difficulty) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment