-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtobefilled.js
104 lines (67 loc) · 2.09 KB
/
tobefilled.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const SHA256 = require('crypto-js/sha256');
class Block{
/**
* timestamp and index to uniquely identify blocks
* data will store the transaction details
* previuosHash will store the output of the hash value of previous block
*/
constructor(index, timestamp, data, previousHash='') {
}
/**
* method to calculate hash value using SHA256 algorithm
*/
calculateHash(){
}
}
class BlockChain{
constructor() {
}
/**
* Creating the first block
* this will have previous hash as 0
*/
createGenesisBlock(){
}
/**
* will return the latest block
*/
getLatestBlock(){
}
/**
* adding a new block to the chain
* would take arguement an object of class Block
* initialize the previousHash of this block
* calculateHash of this block
* push it into the chain
*/
addNewBlock(newBlock){
}
/**
* Exclude Genesis block
* for all the blocks check whether its hash value match with calculateHash
* also check previousHash of this block matches with the previous block's current hash
* if no malicious activity found,return true
*/
isChainValid(){
}
}
/**
* instanciating BlockChain class i.e. creating an object of the class Blockchian
*/
let ACMCoin = new BlockChain();
/**
* adding newBlocks to the blockchain recently created
*/
ACMCoin.addNewBlock(new Block(1, Date.now(), { amount: 1000 }));
ACMCoin.addNewBlock(new Block(2, Date.now(), { amount: 2000 }));
console.log('Is blockchain Valid? ' + ACMCoin.isChainValid());
/**
* trying to modify the previously stored data
*/
ACMCoin.chain[1].data = { amount: 10000 };
ACMCoin.chain[1].hash = ACMCoin.chain[1].calculateHash();
/**
* checking whether blockchain is valid?
*/
console.log('Is blockchain Valid? ' + ACMCoin.isChainValid());
console.log(JSON.stringify(ACMCoin, null, 4));