Skip to content

Commit

Permalink
Merge pull request #40 from jplomas/master
Browse files Browse the repository at this point in the history
New node handling logic & updates to all non-tx based commands
  • Loading branch information
jplomas authored Dec 6, 2020
2 parents 8ab7d37 + db60b00 commit ae8528c
Show file tree
Hide file tree
Showing 37 changed files with 1,397 additions and 1,086 deletions.
21 changes: 14 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ version: 2
jobs:
node-latest: &test
docker:
- image: circleci/node:12.3.1
- image: circleci/python:3.7-node
working_directory: ~/cli
steps:
- checkout
- restore_cache: &restore_cache
keys:
- v1-npm-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}}
- v1-npm-{{checksum ".circleci/config.yml"}}
- run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
- run: |
node -v
- run: |
nvm install v12
nvm install v10.16.3
node -v
nvm alias default v10.16.3
- run:
name: Install dependencies
command: yarn
Expand All @@ -26,17 +37,13 @@ jobs:
name: Build binaries
command: yarn run make-binaries
- run: cd dist && find . -type f -print0 | xargs -0 shasum -a 256 > ../shasum.256.asc && cd .. && cp shasum.256.asc dist/
- run: sudo npm install -g semantic-release
- run: zip -r qrl-cli-macos.zip dist/macos
- run: zip -r qrl-cli-win.zip dist/win
- run: zip -r qrl-cli-linux.zip dist/linux
- run:
name: "Publish Release on GitHub"
command: semantic-release
node-12:
<<: *test
docker:
- image: node:12
command: nvm use v12 && npx semantic-release

cache:
<<: *test
steps:
Expand Down
11 changes: 9 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"extends": "oclif",
"extends": ["airbnb-base", "prettier"],
"env": {
"browser": true,
"node": true,
"mocha": true
},
"rules": {
"object-curly-spacing": "off",
"require-atomic-updates": "off",
"comma-dangle": "off"
"comma-dangle": "off",
"no-shadow": "off",
"no-extra-semi": "error"
}
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.3.1
10.16.3
6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

8 changes: 8 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// prettier.config.js or .prettierrc.js
module.exports = {
trailingComma: "es5",
tabWidth: 2,
semi: false,
singleQuote: true,
printWidth: 120,
}
Binary file added assets/linux/ecdh.node
Binary file not shown.
Binary file added assets/macos/ecdh.node
Binary file not shown.
Binary file added assets/win/ecdh.node
Binary file not shown.
27 changes: 19 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
"@theqrl/explorer-helpers": "^2.0.0",
"@theqrl/qrl-proto-sha256": "^2.0.3",
"@theqrl/qrl-proto-sha256": "^3.3.0",
"@theqrl/qrlbase.proto": "^1.1.0",
"@theqrl/validate-qrl-address": "^1.1.0",
"acorn": "^7.2.0",
"aes-js": "^3.1.2",
Expand All @@ -25,11 +26,12 @@
"cli-ux": "^5.3.1",
"crypto": "^1.0.1",
"crypto-js": "^3.1.9-1",
"eccrypto": "^1.1.3",
"eccrypto": "^1.1.5",
"google-proto-files": "^2.3.0",
"grpc-js-kit": "^0.1.0",
"kleur": "^3.0.3",
"moment": "^2.24.0",
"node": "12.3.1",
"node": "10.16.3",
"ora": "^3.4.0",
"qrcode-terminal": "^0.12.0",
"qrllib": "^1.1.7",
Expand All @@ -39,17 +41,22 @@
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/test": "^1",
"babel-eslint": "^10.1.0",
"chai": "^4",
"codecov": "^3.6.5",
"eslint": "^5.13",
"eslint-config-oclif": "^3.1",
"eslint": "^7.4.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-import": "^0.13.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-modules": "^1.1.1",
"globby": "^10",
"mocha": "^7.1.2",
"nyc": "^15.0.1",
"pkg": "^4.4.4"
"pkg": "^4.4.9"
},
"engines": {
"node": ">=12.0.0"
"node": ">=10.0.0"
},
"files": [
"/bin",
Expand Down Expand Up @@ -82,6 +89,10 @@
"test-status": "nyc mocha --forbid-only -t 50000 \"test/commands/status.test.js\"",
"version": "oclif-dev readme && git add README.md",
"cov": "nyc report --reporter=text-lcov > coverage.lcov && ./node_modules/.bin/codecov -t $CODECOV_TOKEN",
"make-binaries": "pkg . -t node12-macos-x64 -o dist/macos/qrl-cli && pkg . -t node12-win-x64 -o dist/win/qrl-cli && pkg . -t node12-linux-x64 -o dist/linux/qrl-cli"
"make-binaries": "pkg . -t node10-macos-x64 -o dist/macos/qrl-cli && pkg . -t node10-win-x64 -o dist/win/qrl-cli && pkg . -t node10-linux-x64 -o dist/linux/qrl-cli && cp ./assets/macos/ecdh.node dist/macos && cp ./assets/linux/ecdh.node dist/linux && cp ./assets/win/ecdh.node dist/win"
},
"pkg": {
"scripts": [ "src/**" ],
"assets": [ "node_modules/@theqrl/qrlbase.proto/**" ]
}
}
105 changes: 37 additions & 68 deletions src/commands/balance.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
/* eslint new-cap: 0, max-depth: 0 */
const {Command, flags} = require('@oclif/command')
const {red, white, black} = require('kleur')
let {qrlClient,
checkProtoHash,
loadGrpcBaseProto,
loadGrpcProto} = require('../functions/grpc')
const { Command, flags } = require('@oclif/command')
const { red, white, black } = require('kleur')
const ora = require('ora')
const validateQrlAddress = require('@theqrl/validate-qrl-address')
const BigNumber = require('bignumber.js')
const fs = require('fs')
const aes256 = require('aes256')
const {cli} = require('cli-ux')
const { cli } = require('cli-ux')

const Qrlnode = require('../functions/grpc')

const shorPerQuanta = 10 ** 9

const openWalletFile = function (path) {
const openWalletFile = (path) => {
const contents = fs.readFileSync(path)
return JSON.parse(contents)[0]
}

const addressForAPI = address => {
const addressForAPI = (address) => {
return Buffer.from(address.substring(1), 'hex')
}

class Balance extends Command {
async run() {
const {args, flags} = this.parse(Balance)
let address = args.address
let exitCode = null // eslint-disable-line no-unused-vars
const { args, flags } = this.parse(Balance)
let {address} = args
if (!validateQrlAddress.hexString(address).result) {
// not a valid address - is it a file?
let isFile = false
Expand Down Expand Up @@ -56,7 +53,7 @@ class Balance extends Command {
if (flags.password) {
password = flags.password
} else {
password = await cli.prompt('Enter password for wallet file', {type: 'hide'})
password = await cli.prompt('Enter password for wallet file', { type: 'hide' })
}
address = aes256.decrypt(password, walletJson.address)
if (validateQrlAddress.hexString(address).result) {
Expand Down Expand Up @@ -95,53 +92,21 @@ class Balance extends Command {
network = 'Mainnet'
}
this.log(white().bgBlue(network))
const spinner = ora({text: 'Fetching balance from node...'}).start()
const proto = await loadGrpcBaseProto(grpcEndpoint)
checkProtoHash(proto).then(async protoHash => {
if (!protoHash) {
this.log(`${red('⨉')} Unable to validate .proto file from node`)
this.exit(1)
}
// next load GRPC object and check hash of that too
qrlClient = await loadGrpcProto(proto, grpcEndpoint)
const request = {
address: addressForAPI(address),
}
if (network === 'Testnet') {
qrlClient.GetOptimizedAddressState(request, (error, response) => {
if (error) {
this.log(`${red('⨉')} Unable to read status`)
this.exit(1)
}
let balance = new BigNumber(parseInt(response.state.balance, 10))
if (flags.shor) {
spinner.succeed(`Balance: ${balance} Shor`)
}
if (flags.quanta || !flags.shor) {
// default to showing balance in Quanta if no flags
spinner.succeed(`Balance: ${balance / shorPerQuanta} Quanta`)
}
})
} else {
await qrlClient.GetAddressState(request, (error, response) => {
if (error) {
this.log(`${red('⨉')} Unable to read status`)
exitCode = 1
return
}
let balance = new BigNumber(parseInt(response.state.balance, 10))
if (flags.shor) {
spinner.succeed(`Balance: ${balance} Shor`)
exitCode = 0
}
if (flags.quanta || !flags.shor) {
// default to showing balance in Quanta if no flags
spinner.succeed(`Balance: ${balance / shorPerQuanta} Quanta`)
exitCode = 0
}
})
}
})
const spinner = ora({ text: 'Fetching balance from node...' }).start()
const Qrlnetwork = await new Qrlnode(grpcEndpoint)
await Qrlnetwork.connect()
const request = {
address: addressForAPI(address),
}
const response = await Qrlnetwork.api('GetOptimizedAddressState', request)
const balance = new BigNumber(parseInt(response.state.balance, 10))
if (flags.shor) {
spinner.succeed(`Balance: ${balance} Shor`)
}
if (flags.quanta || !flags.shor) {
// default to showing balance in Quanta if no flags
spinner.succeed(`Balance: ${balance / shorPerQuanta} Quanta`)
}
}
}

Expand All @@ -162,13 +127,17 @@ Balance.args = [
]

Balance.flags = {
testnet: flags.boolean({char: 't', default: false, description: 'queries testnet for the balance'}),
mainnet: flags.boolean({char: 'm', default: false, description: 'queries mainnet for the balance'}),
devnet: flags.boolean({char: 'd', default: false, description: 'queries devnet for the balance'}),
shor: flags.boolean({char: 's', default: false, description: 'reports the balance in Shor'}),
quanta: flags.boolean({char: 'q', default: false, description: 'reports the balance in Quanta'}),
grpc: flags.string({char: 'g', required: false, description: 'advanced: grcp endpoint (for devnet/custom QRL network deployments)'}),
password: flags.string({char: 'p', required: false, description: 'wallet file password'}),
testnet: flags.boolean({ char: 't', default: false, description: 'queries testnet for the balance' }),
mainnet: flags.boolean({ char: 'm', default: false, description: 'queries mainnet for the balance' }),
devnet: flags.boolean({ char: 'd', default: false, description: 'queries devnet for the balance' }),
shor: flags.boolean({ char: 's', default: false, description: 'reports the balance in Shor' }),
quanta: flags.boolean({ char: 'q', default: false, description: 'reports the balance in Quanta' }),
grpc: flags.string({
char: 'g',
required: false,
description: 'advanced: grcp endpoint (for devnet/custom QRL network deployments)',
}),
password: flags.string({ char: 'p', required: false, description: 'wallet file password' }),
}

module.exports = {Balance}
module.exports = { Balance }
1 change: 1 addition & 0 deletions src/commands/create-lattice.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/* global QRLLIB */
/* global DILLIB */
/* global KYBLIB */
Expand Down
7 changes: 5 additions & 2 deletions src/commands/create-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const bech32 = require('bech32')
const ora = require('ora')
const fs = require('fs')
const aes256 = require('aes256')

let QRLLIBLoaded = false

class CreateWallet extends Command {
Expand Down Expand Up @@ -37,6 +38,7 @@ class CreateWallet extends Command {

const concatenateTypedArrays = (resultConstructor, ...arrays) => {
let totalLength = 0
/* eslint-disable */
for (let arr of arrays) {
totalLength += arr.length
}
Expand All @@ -46,6 +48,7 @@ class CreateWallet extends Command {
result.set(arr, offset)
offset += arr.length
}
/* eslint-enable */
return result
}

Expand All @@ -70,14 +73,14 @@ class CreateWallet extends Command {
}, 50)
}

waitForQRLLIB(async _ => {
waitForQRLLIB(async () => {
// default to a tree height of 10 unless passed via CLI
let xmssHeight = 10
if (flags.height) {
let valid = true
let reason = ''
const h = parseInt(flags.height, 10)
if ((h & 1) === 1) {
if ((h & 1) === 1) { // eslint-disable-line no-bitwise
valid = false
reason = 'Height must be an even number'
}
Expand Down
1 change: 1 addition & 0 deletions src/commands/decrypt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/* eslint new-cap: 0, max-depth: 0 */
const {Command, flags} = require('@oclif/command')
const {red, white} = require('kleur')
Expand Down
1 change: 1 addition & 0 deletions src/commands/encrypt.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint new-cap: 0, max-depth: 0 */
/* eslint-disable */
const {Command, flags} = require('@oclif/command')
const {red, white} = require('kleur')
const ora = require('ora')
Expand Down
1 change: 1 addition & 0 deletions src/commands/get-keys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/* eslint new-cap: 0, max-depth: 0 */
const {Command, flags} = require('@oclif/command')
const {red, white} = require('kleur')
Expand Down
Loading

0 comments on commit ae8528c

Please sign in to comment.