process.exit(1)
}
+let fn = 'search'
+let work = ''
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')
+ if (!/^[0-9A-Fa-f]{0,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')
+ if (!/^[0-9]{0,2}$/.test(args[i + 1])) throw new Error('Invalid effort')
options['effort'] = parseInt(args[i + 1], 10)
break
}
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));
(async () => {
const NanoPow = await fs.readFile(`${import.meta.dirname}/main.min.js`, 'utf-8')
const hashes = ["${hashes.join('","')}"]
for (const hash of hashes) {
try {
- console.log(\`cli \${hash}\`)
- const work = await NanoPow.search(hash)
+ const work = await NanoPow.${fn}(${work}hash, ${JSON.stringify(options)})
console.log(\`cli \${work}\`)
} catch (err) {
console.error(\`cli \${err}\`)