diff --git a/README.md b/README.md index 6164abe..0b3de51 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ $ npm install -g @theqrl/cli $ qrl-cli COMMAND running command... $ qrl-cli (-v|--version|version) -@theqrl/cli/1.9.0 linux-x64 node-v16.13.1 +@theqrl/cli/1.9.0 linux-x64 node-v16.13.2 $ qrl-cli --help [COMMAND] USAGE $ qrl-cli COMMAND @@ -311,6 +311,7 @@ OPTIONS -g, --grpc=grpc advanced: grpc endpoint (for devnet/custom QRL network deployments) -h, --hexseed=hexseed Secret (h)exseed/mnemonic of address notarization should be sent from -i, --otsindex=otsindex Unused OTS key (i)ndex for message transaction + -j, --json Return JSON response -m, --mainnet uses mainnet for the notarization -p, --password=password Encrypted QRL wallet file (p)assword -t, --testnet uses testnet for the notarization @@ -346,6 +347,7 @@ ARGUMENTS OPTIONS -g, --grpc=grpc Custom grcp endpoint to connect a hosted QRL node (-g 127.0.0.1:19009) + -j, --json Output in JSON -m, --mainnet (default) Queries mainnet for the OTS state -p, --password=password wallet file password if encrypted -t, --testnet Queries testnet for the OTS state diff --git a/src/commands/notarize.js b/src/commands/notarize.js index abcd883..e484ad0 100644 --- a/src/commands/notarize.js +++ b/src/commands/notarize.js @@ -142,7 +142,9 @@ class Notarise extends Command { grpcEndpoint = 'mainnet-1.automated.theqrl.org:19009' network = 'Mainnet' } - this.log(white().bgBlue(network)) + if (!flags.json){ + this.log(white().bgBlue(network)) + } // the data to notarise here, can be a file submitted (path) or a string passed on cli const spinner = ora({ text: 'Notarising Data...\n', }).start() if (args.dataHash) { @@ -347,14 +349,20 @@ class Notarise extends Command { const pushTransactionRes = JSON.stringify(response.tx_hash) const txhash = JSON.parse(pushTransactionRes) if (txnHash === bytesToHex(txhash.data)) { - spinner4.succeed(`Transaction submitted to node: transaction ID: ${bytesToHex(txhash.data)}`) - // return link to explorer if (network === 'Mainnet') { + spinner4.succeed(`Transaction submitted to Mainnet node: transaction ID: ${bytesToHex(txhash.data)}`) spinner3.succeed(`https://explorer.theqrl.org/tx/${bytesToHex(txhash.data)}`) + if (flags.json){ + this.log(`[{"tx_id":"${bytesToHex(txhash.data)}"}]`) + } } else if (network === 'Testnet') { + spinner4.succeed(`Transaction submitted to Testnet node: transaction ID: ${bytesToHex(txhash.data)}`) spinner3.succeed(`https://testnet-explorer.theqrl.org/tx/${bytesToHex(txhash.data)}`) + if (flags.json){ + this.log(`[{"tx_id":"${bytesToHex(txhash.data)}"}]`) + } } // this.exit(0) } @@ -396,6 +404,13 @@ Notarise.flags = { description: 'uses mainnet for the notarization' }), + json: flags.boolean({ + char: 'j', + default: false, + description: 'Return JSON response' + }), + + grpc: flags.string({ char: 'g', required: false, diff --git a/src/commands/ots.js b/src/commands/ots.js index a447d1b..079833d 100644 --- a/src/commands/ots.js +++ b/src/commands/ots.js @@ -80,8 +80,11 @@ class OTSKey extends Command { grpcEndpoint = 'mainnet-1.automated.theqrl.org:19009' network = 'Mainnet' } - this.log(white().bgBlue(network)) - const spinner = ora({text: 'Fetching OTS from API...'}).start() + let spinner = "" + if (!flags.json) { + this.log(white().bgBlue(network)) + spinner = ora({text: 'Fetching OTS from API...'}).start() + } const Qrlnetwork = await new Qrlnode(grpcEndpoint) try { await Qrlnetwork.connect() @@ -89,22 +92,27 @@ class OTSKey extends Command { let i = 0 const count = 5 while (Qrlnetwork.connection === false && i < count) { - spinner.succeed(`retry connection attempt: ${i}...`) + if (!flags.json) { + spinner.succeed(`retry connection attempt: ${i}...`) + } // eslint-disable-next-line no-await-in-loop await Qrlnetwork.connect() // eslint-disable-next-line no-plusplus i++ } } catch (e) { - spinner.fail(`Failed to connect to node. Check network connection & parameters.\n${e}`) + this.log(`Failed to connect to node. Check network connection & parameters.\n${e}`) this.exit(1) } const request = { address: Buffer.from(address.substring(1), 'hex') } const response = await Qrlnetwork.api('GetOTS', request) - if (response.unused_ots_index_found) { - spinner.succeed(`Next unused OTS key: ${response.next_unused_ots_index}`) + if (response.unused_ots_index_found && flags.json) { + this.log(`[{"next_key": ${response.next_unused_ots_index}}]`) this.exit(0) + } else if (response.unused_ots_index_found && !flags.json) { + spinner.succeed(`Next unused OTS key: ${response.next_unused_ots_index}`) + this.exit(0) } else { this.log(`${red('⨉')} Unable to fetch an OTS key`) this.exit(1) @@ -149,6 +157,12 @@ OTSKey.flags = { required: false, description: 'wallet file password if encrypted' }), + json: flags.boolean({ + char: 'j', + required: false, + description: 'Output in JSON' +}), + } -module.exports = {OTSKey} +module.exports = {OTSKey} \ No newline at end of file