Guest User

Untitled

a guest
Oct 22nd, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. class Block{
  2. constructor(timestamp,lastHash,hash,data){
  3. this.timestamp = timestamp;
  4. this.lastHash = lastHash;
  5. this.hash = hash;
  6. this.data = data;
  7. }
  8.  
  9. toString(){
  10. return `Block -
  11. Timestamp : ${this.timestamp}
  12. Last Hash : ${this.lastHash.substring(0,10)}
  13. Hash : ${this.hash.substring(0,10)}
  14. Data : ${this.data}`;
  15. }
  16.  
  17. static genesis(){
  18. return new this('Genesis time','----','genesis-hash',[]);
  19. }
  20.  
  21. static hash(timestamp,lastHash,data){
  22. return SHA256(`${timestamp}${lastHash}${data}`).toString();
  23. }
  24.  
  25. static mineBlock(lastBlock,data){
  26.  
  27. let hash;
  28. let timestamp;
  29. const lastHash = lastBlock.hash;
  30.  
  31. return new this(timestamp,lastHash,hash,data);
  32. }
  33. }
  34.  
  35. module.exports = Block;
Add Comment
Please, Sign In to add comment