Last active
March 29, 2018 14:45
-
-
Save towc/5e4072e8f6474823160e77f1027c8620 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { promisify } = require('util'); | |
const hash = require('./hash'); | |
const { dbs: dbsPath } = require('./paths'); | |
const readFilePromise = promisify(fs.readFile); | |
const getDBFileContentsFromName = async name => readFilePromise(`${dbsPath}/${name}`, 'utf-8'); | |
const getNodeContentsFromName = async name => getDBFileContentsFromName(`${name}.json`); | |
const getOriginHashFromFile = async () => getDBFileContentsFromName('origin-hash.txt'); | |
const getLastHashFromFile = async () => getDBFileContentsFromName('last-hash.txt'); | |
let originHash; | |
const setOriginHashFromFile = async () => { | |
originHash = await getOriginHashFromFile(); | |
}; | |
setOriginHashFromFile(); | |
const checkBlockHash = async (blockHash) => { | |
const blockContent = await getNodeContentsFromName(blockHash); | |
return hash.checkMatchesContent(blockHash, blockContent); | |
}; | |
const checkBlockIntegrity = async (blockHash) => { | |
if (!await checkBlockHash(blockHash)) { | |
return false; | |
} | |
// more code to appear here | |
}; | |
const checkChainIntegrity = async () => { | |
const lastBlockHash = await getLastHashFromFile(); | |
return checkBlockIntegrity(lastBlockHash); | |
}; | |
// and still need to declare the exports |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment