Skip to content

Instantly share code, notes, and snippets.

@riccjohn
Created September 22, 2018 22:52
Show Gist options
  • Select an option

  • Save riccjohn/72471ed18a93b7e03ab710255123f7f9 to your computer and use it in GitHub Desktop.

Select an option

Save riccjohn/72471ed18a93b7e03ab710255123f7f9 to your computer and use it in GitHub Desktop.
const sha256 = require('sha256');
class Block {
constructor(index, timestamp, data, prevHash) {
this.index = index;
this.timestamp = timestamp;
this.data = data;
this.prevHash = prevHash;
this.thisHash = sha256(
this.index + this.timestamp + this.data + this.prevHash
);
}
}
const createGenesisBlock = () => new Block(0, Date.now(), 'Genesis Block', '0');
const nextBlock = (lastBlock, data) =>
new Block(lastBlock.index + 1, Date.now(), data, lastBlock.thisHash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment