From: Chris Duncan Date: Wed, 12 Mar 2025 23:31:47 +0000 (-0700) Subject: Move validate parsing. Add CLI help text. Whitespace. X-Git-Tag: v3.1.0~9^2~3 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=b110e531df6aeb04a5a1cbe8a300cf02645923f7;p=nano-pow.git Move validate parsing. Add CLI help text. Whitespace. --- diff --git a/cli.js b/cli.js index d969774..b7b8431 100755 --- a/cli.js +++ b/cli.js @@ -6,6 +6,29 @@ import * as puppeteer from 'puppeteer' import * as fs from 'node:fs/promises' const args = process.argv.slice(2) +if (args.length === 0 || args.some(v => v === '--help' || v === '-h')) { + console.log(`Usage: nano-pow [OPTION]... BLOCKHASH... +Generate work for BLOCKHASH, or multiple work values for BLOCKHASH(es) +Multiple blockhash values must be separated by spaces. +All command options are optional. + + -h, --help show this dialog + -d, --debug enable additional logging output + -e, --effort increase demand on GPU processing + -t, --threshold override the minimum threshold value + -v, --validate check an existing work value instead of searching for one + +Blockhash(es) must be 64-character hexadecimal values. +If validating a nonce, it must be a 16-character hexadecimal value. +Effort must be a decimal number between 1 - 32. +Threshold must be a hexadecimal number between 0x0 - 0xFFFFFFFF. + +Report bugs: +Full documentation: +`) + process.exit() +} + const hashes = [] while (/^[0-9A-Fa-f]{64}$/.test(args[args.length - 1] ?? '')) { hashes.unshift(args.pop()) @@ -20,6 +43,14 @@ let work = '' const options = {} for (let i = 0; i < args.length; i++) { switch (args[i]) { + case ('--validate'): + case ('-v'): { + if (args[i + 1] == null) throw new Error('Missing argument for work validation') + if (!/^[0-9A-Fa-f]{16}$/.test(args[i + 1])) throw new Error('Invalid work to validate') + fn = 'validate' + work = `'${args[i + 1]}', ` + break + } case ('--threshold'): case ('-t'): { if (args[i + 1] == null) throw new Error('Missing argument for threshold') @@ -39,19 +70,16 @@ for (let i = 0; i < args.length; i++) { options['debug'] = true break } - case ('--validate'): - case ('-v'): { - if (args[i + 1] == null) throw new Error('Missing argument for work validation') - if (!/^[0-9A-Fa-f]{16}$/.test(args[i + 1])) throw new Error('Invalid work to validate') - fn = 'validate' - work = `'${args[i + 1]}', ` - break - } } } + if (options['debug']) console.log(`NanoPowCli.${fn}()`) -if (options['debug']) console.log(`${fn} options`, JSON.stringify(options)); +if (options['debug']) console.log(`${fn} options`, JSON.stringify(options)) + ; +/** +* Main +*/ (async () => { const NanoPow = await fs.readFile(`${import.meta.dirname}/main.min.js`, 'utf-8') const browser = await puppeteer.launch({