persistence for the blockchain + everything through the chain instead of broadcasting
This commit is contained in:
parent
1cb1070d45
commit
ea81105df6
5 changed files with 127 additions and 61 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue