MCPcopy
hub / github.com/lhartikk/naivechain / replaceChain

Function replaceChain

main.js:169–177  ·  view source on GitHub ↗
(newBlocks)

Source from the content-addressed store, hash-verified

167};
168
169var 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
179var isValidChain = (blockchainToValidate) => {
180 if (JSON.stringify(blockchainToValidate[0]) !== JSON.stringify(getGenesisBlock())) {

Callers 1

handleBlockchainResponseFunction · 0.85

Calls 3

isValidChainFunction · 0.85
broadcastFunction · 0.85
responseLatestMsgFunction · 0.85

Tested by

no test coverage detected