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 <value> increase demand on GPU processing
+ -t, --threshold <value> override the minimum threshold value
+ -v, --validate <value> 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: <bug-nano-pow@zoso.dev>
+Full documentation: <https://www.npmjs.com/package/nano-pow>
+`)
+ process.exit()
+}
+
const hashes = []
while (/^[0-9A-Fa-f]{64}$/.test(args[args.length - 1] ?? '')) {
hashes.unshift(args.pop())
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')
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({