From 276cecb99b1ddb67208a4ec45b18f7c55f7eb124 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 10 Mar 2025 16:29:44 -0700 Subject: [PATCH] Add support for multiple hashes. --- cli.js | 146 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 64 deletions(-) diff --git a/cli.js b/cli.js index 90aec93..930c57d 100755 --- a/cli.js +++ b/cli.js @@ -6,74 +6,92 @@ import * as puppeteer from 'puppeteer' import * as fs from 'node:fs/promises' const args = process.argv.slice(2) -const hash = args.pop() -if (!/^[0-9A-Fa-f]{64}$/.test(hash)) throw new Error('Invalid block hash') +const hashes = [] +let hash = args.pop() +while (/^[0-9A-Fa-f]{64}$/.test(hash)) { + hashes.unshift(hash) + hash = args.pop() +} +if (hashes.length === 0) { + console.error('Invalid block hash input') + process.exit(1) +} const options = {} for (let i = 0; i < args.length; i++) { - switch (args[i]) { - case ('--threshold'): - case ('-t'): { - if (args[i + 1] == null) throw new Error('Missing argument for threshold') - if (/^[0-9A-Fa-f]{,8}$/.test(args[i + 1])) throw new Error('Invalid threshold') - options['threshold'] = parseInt(args[i + 1], 16) - break - } - case ('--effort'): - case ('-e'): { - if (args[i + 1] == null) throw new Error('Missing argument for effort') - if (/^[0-9]{,2}$/.test(args[i + 1])) throw new Error('Invalid effort') - options['effort'] = parseInt(args[i + 1], 10) - break - } - case ('--debug'): - case ('-d'): { - options['debug'] = true - break - } - } + switch (args[i]) { + case ('--threshold'): + case ('-t'): { + if (args[i + 1] == null) throw new Error('Missing argument for threshold') + if (/^[0-9A-Fa-f]{,8}$/.test(args[i + 1])) throw new Error('Invalid threshold') + options['threshold'] = parseInt(args[i + 1], 16) + break + } + case ('--effort'): + case ('-e'): { + if (args[i + 1] == null) throw new Error('Missing argument for effort') + if (/^[0-9]{,2}$/.test(args[i + 1])) throw new Error('Invalid effort') + options['effort'] = parseInt(args[i + 1], 10) + break + } + case ('--debug'): + case ('-d'): { + options['debug'] = true + break + } + } } (async () => { - const NanoPow = await fs.readFile(`${import.meta.dirname}/main.min.js`, 'utf-8') - const browser = await puppeteer.launch({ - headless: true, - args: [ - '--no-sandbox', - '--headless=new', - '--use-angle=vulkan', - '--enable-features=Vulkan', - '--disable-vulkan-surface', - '--enable-unsafe-webgpu', - '--enable-vulkan' - ] - }) - const page = await browser.newPage() - console.log('Starting search...') - page.on('console', async (msg) => { - if (msg.type() === 'info' && /^[A-Fa-f0-9]{16}$/.test(msg.text())) { - console.log(msg.text()) - process.exit() - } - }) - await page.setContent(` - - - - - - - - `) - await new Promise(r => setTimeout(r, 90000)) - console.log('Not found') - await browser.close() + const NanoPow = await fs.readFile(`${import.meta.dirname}/main.min.js`, 'utf-8') + const browser = await puppeteer.launch({ + headless: true, + args: [ + '--no-sandbox', + '--headless=new', + '--use-angle=vulkan', + '--enable-features=Vulkan', + '--disable-vulkan-surface', + '--enable-unsafe-webgpu', + '--enable-vulkan' + ] + }) + const page = await browser.newPage() + page.on('console', async (msg) => { + const output = msg.text().split(' ') + if (output[0] === 'cli') { + if (output[1] === 'exit') { + process.exit() + } else { + console.log(output[1]) + } + } else if (options['debug']) { + console.log(msg.text()) + } + }) + await page.setContent(` + + + + + + + + `) + await new Promise(r => setTimeout(r, 90000)) + console.log('Not found') + await browser.close() })() -- 2.34.1