Let's start building the consensus algorithm by creating a new method called chainIsValid. This method will validate whether or not a chain is legitimate. Let's get started with building this method:
- In the blockchain.js file, after the proofOfWork method, let's define the method as follows:
Blockchain.prototype.chainIsValid = function() {
}
- Now, this method will take in a blockchain as an argument, and will return to us whether the blockchain is valid or not:
Blockchain.prototype.chainIsValid = function(blockchain) {
}
We're going to use this chainIsValid method to validate the other chains inside of the network when we are comparing them to the chain that is hosted on the current node. In order to validate that the blockchain is legitimate, we're simply going to iterate through every block inside of the blockchain...