(newBlocks)
| 167 | }; |
| 168 | |
| 169 | var replaceChain = (newBlocks) => { |
| 170 | if (isValidChain(newBlocks) && newBlocks.length > blockchain.length) { |
| 171 | console.log('Received blockchain is valid. Replacing current blockchain with received blockchain'); |
| 172 | blockchain = newBlocks; |
| 173 | broadcast(responseLatestMsg()); |
| 174 | } else { |
| 175 | console.log('Received blockchain invalid'); |
| 176 | } |
| 177 | }; |
| 178 | |
| 179 | var isValidChain = (blockchainToValidate) => { |
| 180 | if (JSON.stringify(blockchainToValidate[0]) !== JSON.stringify(getGenesisBlock())) { |
no test coverage detected