From 0bc6d278e12f918815e0af3756615a1e6ed8e36b Mon Sep 17 00:00:00 2001 From: Victor Graf Date: Mon, 2 Dec 2019 14:43:59 -0800 Subject: [PATCH 1/4] add node flag and adjust celotool verify flag description --- packages/celotool/src/cmds/account/verify.ts | 2 +- packages/cli/src/base.ts | 32 ++++++++++++------- packages/cli/src/commands/account/new.ts | 4 +++ packages/cli/src/commands/account/unlock.ts | 5 ++- packages/cli/src/commands/config/get.ts | 8 ++--- packages/cli/src/commands/config/set.ts | 12 ++++--- .../contractkit/src/wrappers/Attestations.ts | 1 - .../docs/command-line-interface/config.md | 5 ++- 8 files changed, 44 insertions(+), 25 deletions(-) diff --git a/packages/celotool/src/cmds/account/verify.ts b/packages/celotool/src/cmds/account/verify.ts index ad16a2015d0..37967025110 100644 --- a/packages/celotool/src/cmds/account/verify.ts +++ b/packages/celotool/src/cmds/account/verify.ts @@ -29,7 +29,7 @@ export const builder = (argv: yargs.Argv) => { return argv .option('phone', { type: 'string', - description: 'Phone number to attest to,', + description: `Phone number to attest to. Should be an E.164 number matching formatted like +451234567890.`, demand: 'Please specify phone number to attest to', }) .option('num', { diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index bebfa8c90dc..9e8aa1241a5 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -7,11 +7,28 @@ import { getNodeUrl } from './utils/config' import { injectDebugProvider } from './utils/eth-debug-provider' import { requireNodeIsSynced } from './utils/helpers' -export abstract class BaseCommand extends Command { +// Base for commands that do not need web3. +export abstract class LocalCommand extends Command { static flags = { logLevel: flags.string({ char: 'l', hidden: true }), help: flags.help({ char: 'h', hidden: true }), + } + + // TODO(yorke): implement log(msg) switch on logLevel with chalk colored output + log(msg: string, logLevel: string = 'info') { + if (logLevel === 'info') { + console.debug(msg) + } else if (logLevel === 'error') { + console.error(msg) + } + } +} + +export abstract class BaseCommand extends LocalCommand { + static flags = { + ...LocalCommand.flags, privateKey: flags.string({ hidden: true }), + node: flags.string({ char: 'n', hidden: true }), } // This specifies whether the node needs to be synced before the command @@ -31,7 +48,9 @@ export abstract class BaseCommand extends Command { get web3() { if (!this._web3) { - this._web3 = new Web3(getNodeUrl(this.config.configDir)) + const res: ParserOutput = this.parse() + const nodeUrl = (res.flags && res.flags.node) || getNodeUrl(this.config.configDir) + this._web3 = new Web3(nodeUrl) this._originalProvider = this._web3.currentProvider injectDebugProvider(this._web3) } @@ -56,15 +75,6 @@ export abstract class BaseCommand extends Command { } } - // TODO(yorke): implement log(msg) switch on logLevel with chalk colored output - log(msg: string, logLevel: string = 'info') { - if (logLevel === 'info') { - console.debug(msg) - } else if (logLevel === 'error') { - console.error(msg) - } - } - finally(arg: Error | undefined): Promise { try { // If local-signing accounts are added, the debug wrapper is itself wrapped diff --git a/packages/cli/src/commands/account/new.ts b/packages/cli/src/commands/account/new.ts index 6835f53b7db..cfc1660dc05 100644 --- a/packages/cli/src/commands/account/new.ts +++ b/packages/cli/src/commands/account/new.ts @@ -7,6 +7,10 @@ import { ReactNativeBip39MnemonicGenerator } from '../../utils/key_generator' export default class NewAccount extends BaseCommand { static description = 'Creates a new account' + static flags = { + ...BaseCommand.flags, + } + static examples = ['new'] static getRandomMnemonic(): string { diff --git a/packages/cli/src/commands/account/unlock.ts b/packages/cli/src/commands/account/unlock.ts index 5036b501811..50dcae56613 100644 --- a/packages/cli/src/commands/account/unlock.ts +++ b/packages/cli/src/commands/account/unlock.ts @@ -14,12 +14,15 @@ export default class Unlock extends BaseCommand { static examples = ['unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631'] + requireSynced = false + async run() { const res = this.parse(Unlock) // Unlock till geth exits // Source: https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_unlockaccount const unlockDurationInMs = 0 - const password = res.flags.password || (await cli.prompt('Password', { type: 'hide' })) + const password = + res.flags.password || (await cli.prompt('Password', { type: 'hide', required: false })) this.web3.eth.personal.unlockAccount(res.flags.account, password, unlockDurationInMs) } diff --git a/packages/cli/src/commands/config/get.ts b/packages/cli/src/commands/config/get.ts index 18a4c7ba3d4..fce2ba0c7cc 100644 --- a/packages/cli/src/commands/config/get.ts +++ b/packages/cli/src/commands/config/get.ts @@ -1,16 +1,14 @@ -import { BaseCommand } from '../../base' +import { LocalCommand } from '../../base' import { printValueMap } from '../../utils/cli' import { readConfig } from '../../utils/config' -export default class Get extends BaseCommand { +export default class Get extends LocalCommand { static description = 'Output network node configuration' static flags = { - ...BaseCommand.flags, + ...LocalCommand.flags, } - requireSynced = false - async run() { printValueMap(readConfig(this.config.configDir)) } diff --git a/packages/cli/src/commands/config/set.ts b/packages/cli/src/commands/config/set.ts index 1a4283d9247..3aa3ae4a48e 100644 --- a/packages/cli/src/commands/config/set.ts +++ b/packages/cli/src/commands/config/set.ts @@ -1,20 +1,22 @@ import { flags } from '@oclif/command' -import { BaseCommand } from '../../base' +import { LocalCommand } from '../../base' import { CeloConfig, writeConfig } from '../../utils/config' -export default class Set extends BaseCommand { +export default class Set extends LocalCommand { static description = 'Configure running node information for propogating transactions to network' static flags = { - ...BaseCommand.flags, + ...LocalCommand.flags, + // Overrides base command node flag. node: flags.string({ + char: 'n', required: true, - description: 'Node URL', + description: 'URL of the node to run commands against', default: 'http://localhost:8545', }), } - requireSynced = false + static examples = ['set --node ws://localhost:2500'] async run() { const res = this.parse(Set) diff --git a/packages/contractkit/src/wrappers/Attestations.ts b/packages/contractkit/src/wrappers/Attestations.ts index 398faa3f8fc..625a839f110 100644 --- a/packages/contractkit/src/wrappers/Attestations.ts +++ b/packages/contractkit/src/wrappers/Attestations.ts @@ -396,7 +396,6 @@ export class AttestationsWrapper extends BaseWrapper { /** * Selects the issuers for previously requested attestations for a phone number * @param phoneNumber The phone number for which to request attestations for - * @param token The token with which to pay for the attestation fee */ async selectIssuers(phoneNumber: string) { const phoneHash = PhoneNumberUtils.getPhoneHash(phoneNumber) diff --git a/packages/docs/command-line-interface/config.md b/packages/docs/command-line-interface/config.md index 6b2cc926d64..a76965fb674 100644 --- a/packages/docs/command-line-interface/config.md +++ b/packages/docs/command-line-interface/config.md @@ -24,7 +24,10 @@ USAGE $ celocli config:set OPTIONS - --node=node (required) [default: http://localhost:8545] Node URL + -n, --node=node (required) [default: http://localhost:8545] URL of the node to run celocli commands against + +EXAMPLE + set --node ws://localhost:2500 ``` _See code: [packages/cli/src/commands/config/set.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/config/set.ts)_ From 09607936455be9846b3d58cdd6c62c5ca03dcdeb Mon Sep 17 00:00:00 2001 From: Victor Graf Date: Tue, 3 Dec 2019 22:00:40 -0800 Subject: [PATCH 2/4] clarify account new as local --- packages/cli/src/commands/account/new.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/account/new.ts b/packages/cli/src/commands/account/new.ts index cfc1660dc05..4c3ffdedfa4 100644 --- a/packages/cli/src/commands/account/new.ts +++ b/packages/cli/src/commands/account/new.ts @@ -1,11 +1,12 @@ import { ec as EC } from 'elliptic' import Web3 from 'web3' -import { BaseCommand } from '../../base' +import { LocalCommand } from '../../base' import { printValueMap } from '../../utils/cli' import { ReactNativeBip39MnemonicGenerator } from '../../utils/key_generator' -export default class NewAccount extends BaseCommand { - static description = 'Creates a new account' +export default class NewAccount extends LocalCommand { + static description = + 'Creates a new account locally and print out the key information. Save this information for local transaction signing or import into a Celo node.' static flags = { ...BaseCommand.flags, @@ -37,8 +38,6 @@ export default class NewAccount extends BaseCommand { return new Web3().eth.accounts.privateKeyToAccount(privateKey).address } - requireSynced = false - async run() { // Generate a random mnemonic (uses crypto.randomBytes under the hood), defaults to 128-bits of entropy const mnemonic: string = NewAccount.getRandomMnemonic() From d88467a9eafb95973d1505a1b133d73589754574 Mon Sep 17 00:00:00 2001 From: Victor Graf Date: Tue, 3 Dec 2019 22:03:04 -0800 Subject: [PATCH 3/4] update docs --- packages/cli/src/commands/account/new.ts | 4 ++-- packages/docs/command-line-interface/account.md | 2 +- packages/docs/command-line-interface/config.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/commands/account/new.ts b/packages/cli/src/commands/account/new.ts index 4c3ffdedfa4..9ab95ed6f38 100644 --- a/packages/cli/src/commands/account/new.ts +++ b/packages/cli/src/commands/account/new.ts @@ -9,7 +9,7 @@ export default class NewAccount extends LocalCommand { 'Creates a new account locally and print out the key information. Save this information for local transaction signing or import into a Celo node.' static flags = { - ...BaseCommand.flags, + ...LocalCommand.flags, } static examples = ['new'] @@ -45,7 +45,7 @@ export default class NewAccount extends LocalCommand { const publicKey = NewAccount.getPublicKey(privateKey) const accountAddress = NewAccount.generateAccountAddressFromPrivateKey(privateKey) this.log( - 'This is not being stored anywhere, so, save the mnemonic somewhere to use this account at a later point\n' + 'This is not being stored anywhere. Save the mnemonic somewhere to use this account at a later point.\n' ) printValueMap({ mnemonic: mnemonic, privateKey, publicKey, accountAddress }) } diff --git a/packages/docs/command-line-interface/account.md b/packages/docs/command-line-interface/account.md index 09eaedcaf0c..fdb32f89f31 100644 --- a/packages/docs/command-line-interface/account.md +++ b/packages/docs/command-line-interface/account.md @@ -205,7 +205,7 @@ _See code: [packages/cli/src/commands/account/isvalidator.ts](https://github.com ### New -Creates a new account +Creates a new account locally and print out the key information. Save this information for local transaction signing or import into a Celo node. ``` USAGE diff --git a/packages/docs/command-line-interface/config.md b/packages/docs/command-line-interface/config.md index a76965fb674..3bb7f6394b1 100644 --- a/packages/docs/command-line-interface/config.md +++ b/packages/docs/command-line-interface/config.md @@ -24,7 +24,7 @@ USAGE $ celocli config:set OPTIONS - -n, --node=node (required) [default: http://localhost:8545] URL of the node to run celocli commands against + -n, --node=node (required) [default: http://localhost:8545] URL of the node to run commands against EXAMPLE set --node ws://localhost:2500 From d2025e3d68dc641cf5d4e5270a68b4116e38e809 Mon Sep 17 00:00:00 2001 From: Victor Graf Date: Wed, 4 Dec 2019 06:38:10 -0800 Subject: [PATCH 4/4] create exception for tslint --- packages/cli/src/base.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cli/src/base.ts b/packages/cli/src/base.ts index 9e8aa1241a5..0c1eb29ce53 100644 --- a/packages/cli/src/base.ts +++ b/packages/cli/src/base.ts @@ -24,6 +24,7 @@ export abstract class LocalCommand extends Command { } } +// tslint:disable-next-line:max-classes-per-file export abstract class BaseCommand extends LocalCommand { static flags = { ...LocalCommand.flags,