#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const block_1 = require("../../src/models/block");
const modules_1 = require("../../src/modules");
const config_1 = require("../../src/services/config");
const storage_1 = require("../../src/services/storage");
const verification_1 = require("../../src/services/verification");
if (require.main === module) {
    (async () => {
        const { CHAIN = '', NETWORK = '', HEIGHT, VERIFYSPENDS } = process.env;
        const resumeHeight = Number(HEIGHT) || 1;
        const chain = CHAIN || '';
        const network = NETWORK || '';
        modules_1.Modules.loadConfigured();
        const chainConfig = config_1.Config.chainConfig({ chain, network });
        let worker;
        if (verification_1.Verification.get(CHAIN, NETWORK)) {
            const workerClass = verification_1.Verification.get(CHAIN, NETWORK);
            worker = new workerClass({ chain, network, chainConfig });
            worker.connect();
            if (VERIFYSPENDS) {
                worker.enableDeepScan();
            }
            await storage_1.Storage.start();
            if (!chain || !network) {
                console.log('Please provide a CHAIN and NETWORK environment variable');
                process.exit(1);
            }
            const tip = await block_1.BitcoinBlockStorage.getLocalTip({ chain, network });
            if (tip) {
                for (let i = resumeHeight; i <= tip.height; i++) {
                    const { success } = await worker.validateDataForBlock(i, tip.height, true);
                    console.log({ block: i, success });
                }
            }
        }
        process.exit(0);
    })();
}
//# sourceMappingURL=db-verify.js.map