persistence for the blockchain + everything through the chain instead of broadcasting

This commit is contained in:
Josip Milovac 2022-12-05 16:00:26 +11:00
parent 1cb1070d45
commit ea81105df6
5 changed files with 127 additions and 61 deletions

View file

@ -28,17 +28,19 @@ class Blockchain {
return true;
}
//return false on failure, true on success
replaceChain(newChain) {
if (newChain.length <= this.chain.length) {
console.log('Received chain is not longer than the current chain.');
return;
return false;
} else if (!this.isValidChain(newChain)) {
console.log('The received chain is not valid.');
return;
return false;
}
console.log('Replacing blockchain with the new chain.');
this.chain = newChain;
return true;
}
}