Skip to content

Instantly share code, notes, and snippets.

@bluepnume
Last active May 17, 2021 04:28
Show Gist options
  • Save bluepnume/0d4386eff538d88098b92132db75ee85 to your computer and use it in GitHub Desktop.
Save bluepnume/0d4386eff538d88098b92132db75ee85 to your computer and use it in GitHub Desktop.
const addBlock = async (hashedBlock : string) => {
const verifiedBlock = await verifyHashAndUnpack(hashedBlock);
const verifiedTransactions = await asyncMap(verifiedBlock.transactions, verifySignatureAndUnpack);
const fullyVerifiedBlock = {
...verifiedBlock,
transactions: verifiedTransactions
};
const headNode = root.findValueByID(fullyVerifiedBlock.parentid);
const hash = unpackHash(hashedBlock);
if (headNode && divisibleBy(hash, headNode.getValue().difficulty)) {
headNode.addChildNodeValue(fullyVerifiedBlock);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment