From fb4f3564e94b91815651928a307a854df8105070 Mon Sep 17 00:00:00 2001 From: bakasura980 Date: Wed, 29 Jan 2020 14:58:41 +0200 Subject: [PATCH 01/17] Add missing provider for default account --- src/defaults/local-account-default.js | 2 +- src/network-providers/local-provider.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/defaults/local-account-default.js b/src/defaults/local-account-default.js index a17e375..083541c 100644 --- a/src/defaults/local-account-default.js +++ b/src/defaults/local-account-default.js @@ -1,2 +1,2 @@ const Account = require('./../account/normal-account/account') -module.exports = new Account('eosio', '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', 'active'); +module.exports = new Account('eosio', '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3', '', 'active'); diff --git a/src/network-providers/local-provider.js b/src/network-providers/local-provider.js index 3d6d026..6a18333 100644 --- a/src/network-providers/local-provider.js +++ b/src/network-providers/local-provider.js @@ -9,8 +9,8 @@ const LocalNetworkConfig = { class LocalProvider extends BaseProvider { constructor(networkConfig) { - super(Object.assign({}, LocalNetworkConfig, networkConfig)) - this.defaultAccount = LOCAL_DEFATULT_ACCOUNT + super(Object.assign({}, LocalNetworkConfig, networkConfig)); + this.defaultAccount = LOCAL_DEFATULT_ACCOUNT; this.defaultAccount.provider = this; } } From a757dc76e85dff2d8ca5cf65370b9facb581b988 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Fri, 24 Apr 2020 12:57:13 +0300 Subject: [PATCH 02/17] Initial structure nodeos command with subcommands --- cli-commands/command.js | 13 +++++++ cli-commands/nodeos/definition.js | 5 +++ cli-commands/nodeos/index.js | 13 +++++++ cli-commands/nodeos/messages.js | 10 ++++++ cli-commands/nodeos/settings.json | 0 .../nodeos/subcommands/show/accounts.json | 17 ++++++++++ .../nodeos/subcommands/show/definition.js | 8 +++++ cli-commands/nodeos/subcommands/show/index.js | 18 ++++++++++ .../nodeos/subcommands/show/messages.js | 10 ++++++ .../accounts-option/accounts-option.js | 28 +++++++++++++++ .../options/accounts-option/accounts-table.js | 34 +++++++++++++++++++ .../subcommands/show/options/logs-option.js | 19 +++++++++++ .../nodeos/subcommands/start/definition.js | 7 ++++ .../nodeos/subcommands/start/index.js | 18 ++++++++++ .../nodeos/subcommands/start/messages.js | 10 ++++++ .../subcommands/start/options/path-option.js | 19 +++++++++++ .../nodeos/subcommands/stop/definition.js | 7 ++++ cli-commands/nodeos/subcommands/stop/index.js | 18 ++++++++++ .../nodeos/subcommands/stop/messages.js | 10 ++++++ .../subcommands/stop/options/path-option.js | 19 +++++++++++ cli.js | 12 +++++++ 21 files changed, 295 insertions(+) create mode 100644 cli-commands/nodeos/definition.js create mode 100644 cli-commands/nodeos/index.js create mode 100644 cli-commands/nodeos/messages.js create mode 100644 cli-commands/nodeos/settings.json create mode 100644 cli-commands/nodeos/subcommands/show/accounts.json create mode 100644 cli-commands/nodeos/subcommands/show/definition.js create mode 100644 cli-commands/nodeos/subcommands/show/index.js create mode 100644 cli-commands/nodeos/subcommands/show/messages.js create mode 100644 cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js create mode 100644 cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js create mode 100644 cli-commands/nodeos/subcommands/show/options/logs-option.js create mode 100644 cli-commands/nodeos/subcommands/start/definition.js create mode 100644 cli-commands/nodeos/subcommands/start/index.js create mode 100644 cli-commands/nodeos/subcommands/start/messages.js create mode 100644 cli-commands/nodeos/subcommands/start/options/path-option.js create mode 100644 cli-commands/nodeos/subcommands/stop/definition.js create mode 100644 cli-commands/nodeos/subcommands/stop/index.js create mode 100644 cli-commands/nodeos/subcommands/stop/messages.js create mode 100644 cli-commands/nodeos/subcommands/stop/options/path-option.js diff --git a/cli-commands/command.js b/cli-commands/command.js index daf9ca3..f308ce9 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -23,6 +23,19 @@ class Command { execute(args) { } + static defineSubcommands(subcommands) { + return (yargs) => { + for (const subcommand of subcommands) { + yargs.command(subcommand.template, + subcommand.description, + this.defineCommandOptions(subcommand), + this.executeWithContext(subcommand)); + } + + return yargs; + } + } + static defineCommandOptions(command) { return (yargs) => { for (const option of command.options) { diff --git a/cli-commands/nodeos/definition.js b/cli-commands/nodeos/definition.js new file mode 100644 index 0000000..f28a683 --- /dev/null +++ b/cli-commands/nodeos/definition.js @@ -0,0 +1,5 @@ +module.exports = { + "template": "nodeos", + "description": "Enable user to start/stop a local node", + "options": [] +} diff --git a/cli-commands/nodeos/index.js b/cli-commands/nodeos/index.js new file mode 100644 index 0000000..7c7e795 --- /dev/null +++ b/cli-commands/nodeos/index.js @@ -0,0 +1,13 @@ +const Command = require('./../command'); + +const nodeosCommandDefinition = require('./definition'); + +// eoslime nodeos + +class NodeosCommand extends Command { + constructor() { + super(nodeosCommandDefinition); + } +} + +module.exports = NodeosCommand; diff --git a/cli-commands/nodeos/messages.js b/cli-commands/nodeos/messages.js new file mode 100644 index 0000000..e59974a --- /dev/null +++ b/cli-commands/nodeos/messages.js @@ -0,0 +1,10 @@ +const chalk = require('chalk'); + +module.exports = { + 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, + 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, + 'UnsuccessfulProcessing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + console.log(error); + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/settings.json b/cli-commands/nodeos/settings.json new file mode 100644 index 0000000..e69de29 diff --git a/cli-commands/nodeos/subcommands/show/accounts.json b/cli-commands/nodeos/subcommands/show/accounts.json new file mode 100644 index 0000000..df12827 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/accounts.json @@ -0,0 +1,17 @@ +[ + { + "name": "eoslimedavid", + "publicKey":"EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey":"5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + }, + { + "name": "eoslimekevid", + "publicKey":"EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey":"5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + }, + { + "name": "eoslimemarty", + "publicKey":"EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey":"5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + } +] \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/definition.js b/cli-commands/nodeos/subcommands/show/definition.js new file mode 100644 index 0000000..9bccdd3 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/definition.js @@ -0,0 +1,8 @@ +const accountsOption = require('./options/accounts-option/accounts-option'); +const logsOption = require('./options/logs-option'); + +module.exports = { + "template": "show [accounts] [logs]", + "description": "Show local node details", + "options": [accountsOption, logsOption] +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js new file mode 100644 index 0000000..68d80f8 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -0,0 +1,18 @@ +const Command = require('../../../command'); + +const commandMessages = require('./messages'); +const showCommandDefinition = require('./definition'); + +// eoslime nodeos show --accounts --logs + +class ShowCommand extends Command { + constructor() { + super(showCommandDefinition); + } + + async execute(args) { + + } +} + +module.exports = ShowCommand; diff --git a/cli-commands/nodeos/subcommands/show/messages.js b/cli-commands/nodeos/subcommands/show/messages.js new file mode 100644 index 0000000..e59974a --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/messages.js @@ -0,0 +1,10 @@ +const chalk = require('chalk'); + +module.exports = { + 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, + 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, + 'UnsuccessfulProcessing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + console.log(error); + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js new file mode 100644 index 0000000..27ad734 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js @@ -0,0 +1,28 @@ +const AccountsTable = require('./accounts-table'); +const Option = require('../../../../../option'); + +const accounts = require('../../accounts.json'); + +class AccountsOption extends Option { + constructor() { + super( + 'accounts', + { + "describe": "Lists all predefined accounts", + "type": "string", + } + ); + + this.accountsTable = new AccountsTable(); + } + + process(optionValue) { + accounts.forEach(account => { + this.accountsTable.addRow([account.name, account.publicKey, account.privateKey]); + }); + + this.accountsTable.draw(); + } +} + +module.exports = new AccountsOption(); diff --git a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js new file mode 100644 index 0000000..3679d66 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js @@ -0,0 +1,34 @@ +const chalk = require('chalk').default; +const CLITable = require('cli-table'); + +const TABLE_HEAD = { + head: ['Account', 'Public Key', 'Private Key'] +} + +class ReportTable { + constructor() { + this.table = new CLITable(TABLE_HEAD); + } + + addRow(rowData) { + this.table.push(rowData); + } + + addSection(sectionName, sectionRows) { + this.table.push({ [chalk.cyanBright(sectionName)]: ['', '', ''] }); + + if (sectionRows) { + for (let i = 0; i < sectionRows.length; i++) { + const sectionRow = sectionRows[i]; + sectionRow.unshift(''); + this.addRow(sectionRow); + } + } + } + + draw() { + console.log(this.table.toString()); + } +} + +module.exports = ReportTable; diff --git a/cli-commands/nodeos/subcommands/show/options/logs-option.js b/cli-commands/nodeos/subcommands/show/options/logs-option.js new file mode 100644 index 0000000..70bfc01 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/options/logs-option.js @@ -0,0 +1,19 @@ +const Option = require('../../../../option'); + +class LogsOption extends Option { + constructor() { + super( + 'logs', + { + "describe": "Lists last N lines from node logs", + "type": "string", + } + ); + } + + process() { + + } +} + +module.exports = new LogsOption(); diff --git a/cli-commands/nodeos/subcommands/start/definition.js b/cli-commands/nodeos/subcommands/start/definition.js new file mode 100644 index 0000000..dfbe0ef --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/definition.js @@ -0,0 +1,7 @@ +const pathOption = require('./options/path-option'); + +module.exports = { + "template": "start [path]", + "description": "Start a local node", + "options": [pathOption] +} diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js new file mode 100644 index 0000000..1d05143 --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -0,0 +1,18 @@ +const Command = require('../../../command'); + +const commandMessages = require('./messages'); +const startCommandDefinition = require('./definition'); + +// eoslime nodeos start --path + +class StartCommand extends Command { + constructor() { + super(startCommandDefinition); + } + + async execute(args) { + + } +} + +module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/messages.js b/cli-commands/nodeos/subcommands/start/messages.js new file mode 100644 index 0000000..e59974a --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/messages.js @@ -0,0 +1,10 @@ +const chalk = require('chalk'); + +module.exports = { + 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, + 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, + 'UnsuccessfulProcessing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + console.log(error); + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/nodeos/subcommands/start/options/path-option.js new file mode 100644 index 0000000..3229afa --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/options/path-option.js @@ -0,0 +1,19 @@ +const Option = require('../../../../option'); + +class PathOption extends Option { + constructor() { + super( + 'path', + { + "describe": "Path to node folder", + "type": "string", + } + ); + } + + process() { + + } +} + +module.exports = new PathOption(); diff --git a/cli-commands/nodeos/subcommands/stop/definition.js b/cli-commands/nodeos/subcommands/stop/definition.js new file mode 100644 index 0000000..6f3205b --- /dev/null +++ b/cli-commands/nodeos/subcommands/stop/definition.js @@ -0,0 +1,7 @@ +const pathOption = require('./options/path-option'); + +module.exports = { + "template": "stop [path]", + "description": "Stop a local node", + "options": [pathOption] +} diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js new file mode 100644 index 0000000..39565be --- /dev/null +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -0,0 +1,18 @@ +const Command = require('../../../command'); + +const commandMessages = require('./messages'); +const stopCommandDefinition = require('./definition'); + +// eoslime nodeos stop --path + +class StopCommand extends Command { + constructor() { + super(stopCommandDefinition); + } + + async execute(args) { + + } +} + +module.exports = StopCommand; diff --git a/cli-commands/nodeos/subcommands/stop/messages.js b/cli-commands/nodeos/subcommands/stop/messages.js new file mode 100644 index 0000000..e59974a --- /dev/null +++ b/cli-commands/nodeos/subcommands/stop/messages.js @@ -0,0 +1,10 @@ +const chalk = require('chalk'); + +module.exports = { + 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, + 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, + 'UnsuccessfulProcessing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + console.log(error); + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/options/path-option.js b/cli-commands/nodeos/subcommands/stop/options/path-option.js new file mode 100644 index 0000000..3229afa --- /dev/null +++ b/cli-commands/nodeos/subcommands/stop/options/path-option.js @@ -0,0 +1,19 @@ +const Option = require('../../../../option'); + +class PathOption extends Option { + constructor() { + super( + 'path', + { + "describe": "Path to node folder", + "type": "string", + } + ); + } + + process() { + + } +} + +module.exports = new PathOption(); diff --git a/cli.js b/cli.js index 64bcf8a..a46c1db 100755 --- a/cli.js +++ b/cli.js @@ -4,9 +4,14 @@ const exec = require('child_process').exec; const InitCommand = require('./cli-commands/init'); const TestCommand = require('./cli-commands/test'); const ShapeCommand = require('./cli-commands/shape'); +const NodeosCommand = require('./cli-commands/nodeos'); const DeployCommand = require('./cli-commands/deploy'); const CompileCommand = require('./cli-commands/compile'); +const StartCommand = require('./cli-commands/nodeos/subcommands/start'); +const StopCommand = require('./cli-commands/nodeos/subcommands/stop'); +const ShowCommand = require('./cli-commands/nodeos/subcommands/show'); + const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); (() => { @@ -16,12 +21,19 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const initCommand = new InitCommand(); const testCommand = new TestCommand(); const shapeCommand = new ShapeCommand(); + const nodeosCommand = new NodeosCommand(); const deployCommand = new DeployCommand(); const compileCommand = new CompileCommand(); + // nodeos subcommands + const startCommand = new StartCommand(); + const stopCommand = new StopCommand(); + const showCommand = new ShowCommand(); + menu.command(initCommand.template, initCommand.description, InitCommand.defineCommandOptions(initCommand), InitCommand.executeWithContext(initCommand)); menu.command(testCommand.template, testCommand.description, TestCommand.defineCommandOptions(testCommand), TestCommand.executeWithContext(testCommand, MochaFramework)); menu.command(shapeCommand.template, shapeCommand.description, ShapeCommand.defineCommandOptions(shapeCommand), ShapeCommand.executeWithContext(shapeCommand)); + menu.command(nodeosCommand.template, nodeosCommand.description, NodeosCommand.defineSubcommands([startCommand, stopCommand, showCommand])); menu.command(deployCommand.template, deployCommand.description, DeployCommand.defineCommandOptions(deployCommand), DeployCommand.executeWithContext(deployCommand)); menu.command(compileCommand.template, compileCommand.description, CompileCommand.defineCommandOptions(compileCommand), CompileCommand.executeWithContext(compileCommand)); From 1811f7688fcf2bbe6f532b8adeefcaa5053f984c Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sat, 25 Apr 2020 01:45:50 +0300 Subject: [PATCH 03/17] Added usage messages to cli commands --- cli-commands/command.js | 4 ++++ cli.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cli-commands/command.js b/cli-commands/command.js index f308ce9..e7710ef 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -25,6 +25,8 @@ class Command { static defineSubcommands(subcommands) { return (yargs) => { + yargs.usage('Usage: $0 nodeos [command]'); + for (const subcommand of subcommands) { yargs.command(subcommand.template, subcommand.description, @@ -32,6 +34,8 @@ class Command { this.executeWithContext(subcommand)); } + yargs.demandCommand(1, ''); + return yargs; } } diff --git a/cli.js b/cli.js index a46c1db..386143b 100755 --- a/cli.js +++ b/cli.js @@ -30,6 +30,7 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const stopCommand = new StopCommand(); const showCommand = new ShowCommand(); + menu.usage('Usage: $0 [command]'); menu.command(initCommand.template, initCommand.description, InitCommand.defineCommandOptions(initCommand), InitCommand.executeWithContext(initCommand)); menu.command(testCommand.template, testCommand.description, TestCommand.defineCommandOptions(testCommand), TestCommand.executeWithContext(testCommand, MochaFramework)); menu.command(shapeCommand.template, shapeCommand.description, ShapeCommand.defineCommandOptions(shapeCommand), ShapeCommand.executeWithContext(shapeCommand)); @@ -51,7 +52,7 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); } }); - menu.help('help'); + menu.help(); menu.version(); menu.demandCommand(); menu.recommendCommands(); From 4d0c6f7e830baecdfde91384a35d82d117ca8a5f Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sat, 25 Apr 2020 09:49:20 +0300 Subject: [PATCH 04/17] Updated usage messages to cli commands --- cli-commands/command.js | 4 ++-- cli.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli-commands/command.js b/cli-commands/command.js index e7710ef..39391cf 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -23,9 +23,9 @@ class Command { execute(args) { } - static defineSubcommands(subcommands) { + static defineSubcommands(command, subcommands) { return (yargs) => { - yargs.usage('Usage: $0 nodeos [command]'); + yargs.usage(`Usage: $0 ${command.template} [command]`); for (const subcommand of subcommands) { yargs.command(subcommand.template, diff --git a/cli.js b/cli.js index 386143b..8e04c05 100755 --- a/cli.js +++ b/cli.js @@ -34,7 +34,7 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); menu.command(initCommand.template, initCommand.description, InitCommand.defineCommandOptions(initCommand), InitCommand.executeWithContext(initCommand)); menu.command(testCommand.template, testCommand.description, TestCommand.defineCommandOptions(testCommand), TestCommand.executeWithContext(testCommand, MochaFramework)); menu.command(shapeCommand.template, shapeCommand.description, ShapeCommand.defineCommandOptions(shapeCommand), ShapeCommand.executeWithContext(shapeCommand)); - menu.command(nodeosCommand.template, nodeosCommand.description, NodeosCommand.defineSubcommands([startCommand, stopCommand, showCommand])); + menu.command(nodeosCommand.template, nodeosCommand.description, NodeosCommand.defineSubcommands(nodeosCommand, [startCommand, stopCommand, showCommand])); menu.command(deployCommand.template, deployCommand.description, DeployCommand.defineCommandOptions(deployCommand), DeployCommand.executeWithContext(deployCommand)); menu.command(compileCommand.template, compileCommand.description, CompileCommand.defineCommandOptions(compileCommand), CompileCommand.executeWithContext(compileCommand)); From 4c3e4b96c2cbbd4ff92648610476b6e0ded8ba7e Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sun, 26 Apr 2020 22:42:43 +0300 Subject: [PATCH 05/17] Updated command 'nodeos show' --- cli-commands/nodeos/subcommands/show/index.js | 3 +-- .../nodeos/subcommands/show/messages.js | 8 ++------ .../accounts-option/accounts-option.js | 3 +++ .../subcommands/show/options/logs-option.js | 19 ++++++++++++++++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js index 68d80f8..6b221e5 100644 --- a/cli-commands/nodeos/subcommands/show/index.js +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -1,6 +1,5 @@ const Command = require('../../../command'); -const commandMessages = require('./messages'); const showCommandDefinition = require('./definition'); // eoslime nodeos show --accounts --logs @@ -11,7 +10,7 @@ class ShowCommand extends Command { } async execute(args) { - + await super.processOptions(args); } } diff --git a/cli-commands/nodeos/subcommands/show/messages.js b/cli-commands/nodeos/subcommands/show/messages.js index e59974a..b11502d 100644 --- a/cli-commands/nodeos/subcommands/show/messages.js +++ b/cli-commands/nodeos/subcommands/show/messages.js @@ -1,10 +1,6 @@ const chalk = require('chalk'); module.exports = { - 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, - 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, - 'UnsuccessfulProcessing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful processing =====`)); - console.log(error); - } + 'PredefinedAccounts': () => { console.log(chalk.magentaBright('===== Predefined accounts =====')); }, + 'NodeosLogs': () => { console.log(chalk.magentaBright('===== Nodeos logs =====')); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js index 27ad734..2b78086 100644 --- a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js +++ b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js @@ -2,6 +2,7 @@ const AccountsTable = require('./accounts-table'); const Option = require('../../../../../option'); const accounts = require('../../accounts.json'); +const optionMessages = require('../../messages'); class AccountsOption extends Option { constructor() { @@ -17,6 +18,8 @@ class AccountsOption extends Option { } process(optionValue) { + optionMessages.PredefinedAccounts(); + accounts.forEach(account => { this.accountsTable.addRow([account.name, account.publicKey, account.privateKey]); }); diff --git a/cli-commands/nodeos/subcommands/show/options/logs-option.js b/cli-commands/nodeos/subcommands/show/options/logs-option.js index 70bfc01..fcafd4a 100644 --- a/cli-commands/nodeos/subcommands/show/options/logs-option.js +++ b/cli-commands/nodeos/subcommands/show/options/logs-option.js @@ -1,4 +1,6 @@ +const exec = require('child_process').exec; const Option = require('../../../../option'); +const optionMessages = require('../messages'); class LogsOption extends Option { constructor() { @@ -6,13 +8,24 @@ class LogsOption extends Option { 'logs', { "describe": "Lists last N lines from node logs", - "type": "string", + "type": "number", } ); } - process() { - + process(optionValue) { + optionMessages.NodeosLogs(); + + const numLines = optionValue > 0 ? optionValue : 10; + + exec(`tail -n ${numLines} nodeos.log`, (error, stdout, stderr) => { + if (error) { + throw new Error(`Could not show logs, due to '${error}'`); + } + + console.log(stdout); + console.error(stderr); + }); } } From f7e20a0a7c3ef28b52bf3f0503a66119690690a4 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Tue, 28 Apr 2020 04:46:39 +0300 Subject: [PATCH 06/17] Refactored subcommands structure logic --- cli-commands/command.js | 35 ++++++++----------- cli-commands/compile/index.js | 4 +++ cli-commands/deploy/index.js | 4 +++ cli-commands/init/index.js | 4 +++ cli-commands/nodeos/index.js | 26 ++++++++++++++ cli-commands/nodeos/settings.json | 0 cli-commands/nodeos/subcommands/show/index.js | 4 +++ .../nodeos/subcommands/start/index.js | 4 +++ .../nodeos/subcommands/start/settings.json | 3 ++ cli-commands/nodeos/subcommands/stop/index.js | 4 +++ cli-commands/shape/index.js | 4 +++ cli-commands/test/index.js | 4 +++ cli.js | 22 ++++-------- 13 files changed, 83 insertions(+), 35 deletions(-) delete mode 100644 cli-commands/nodeos/settings.json create mode 100644 cli-commands/nodeos/subcommands/start/settings.json diff --git a/cli-commands/command.js b/cli-commands/command.js index 39391cf..4d9d6fa 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -21,28 +21,20 @@ class Command { return optionResults; } - execute(args) { } - - static defineSubcommands(command, subcommands) { - return (yargs) => { - yargs.usage(`Usage: $0 ${command.template} [command]`); - - for (const subcommand of subcommands) { - yargs.command(subcommand.template, - subcommand.description, - this.defineCommandOptions(subcommand), - this.executeWithContext(subcommand)); - } - - yargs.demandCommand(1, ''); - - return yargs; + define(...params) { } + + defineCommand(...params) { + return { + command: this.template, + description: this.description, + builder: this.defineCommandOptions(), + handler: this.defineCommandExecution(...params) } } - static defineCommandOptions(command) { + defineCommandOptions() { return (yargs) => { - for (const option of command.options) { + for (const option of this.options) { yargs = yargs.options(option.name, option.definition); } @@ -50,11 +42,14 @@ class Command { } } - static executeWithContext(context, ...params) { + defineCommandExecution(...params) { return async (args) => { - await context.execute(args, ...params); + await this.execute(args, ...params); } } + + execute(args) { } + } module.exports = Command; diff --git a/cli-commands/compile/index.js b/cli-commands/compile/index.js index d091331..e65d1e9 100644 --- a/cli-commands/compile/index.js +++ b/cli-commands/compile/index.js @@ -15,6 +15,10 @@ class CompileCommand extends Command { super(compileCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { try { commandMessages.StartCompilation(); diff --git a/cli-commands/deploy/index.js b/cli-commands/deploy/index.js index 58b86d4..1979172 100644 --- a/cli-commands/deploy/index.js +++ b/cli-commands/deploy/index.js @@ -10,6 +10,10 @@ class DeployCommand extends Command { super(deployCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { try { commandMessages.StartDeployment(); diff --git a/cli-commands/init/index.js b/cli-commands/init/index.js index 1386b73..f0694ba 100644 --- a/cli-commands/init/index.js +++ b/cli-commands/init/index.js @@ -18,6 +18,10 @@ class InitCommand extends Command { super(initCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + defineOptions(yargs) { super.defineOptions(yargs, initCommandDefinition.options); } diff --git a/cli-commands/nodeos/index.js b/cli-commands/nodeos/index.js index 7c7e795..818ea0a 100644 --- a/cli-commands/nodeos/index.js +++ b/cli-commands/nodeos/index.js @@ -1,5 +1,9 @@ const Command = require('./../command'); +const StartCommand = require('./subcommands/start'); +const StopCommand = require('./subcommands/stop'); +const ShowCommand = require('./subcommands/show'); + const nodeosCommandDefinition = require('./definition'); // eoslime nodeos @@ -7,6 +11,28 @@ const nodeosCommandDefinition = require('./definition'); class NodeosCommand extends Command { constructor() { super(nodeosCommandDefinition); + + this.subcommands = [ + new StartCommand(), new StopCommand(), new ShowCommand() + ] + } + + define(...params) { + return { + command: this.template, + description: this.description, + builder: (yargs) => { + yargs.usage(`Usage: $0 ${this.template} [command]`); + + for (const subcommand of this.subcommands) { + yargs.command(subcommand.define(...params)); + } + + yargs.demandCommand(1, ''); + + return yargs; + } + } } } diff --git a/cli-commands/nodeos/settings.json b/cli-commands/nodeos/settings.json deleted file mode 100644 index e69de29..0000000 diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js index 6b221e5..a9855fd 100644 --- a/cli-commands/nodeos/subcommands/show/index.js +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -9,6 +9,10 @@ class ShowCommand extends Command { super(showCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { await super.processOptions(args); } diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 1d05143..77f653a 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -10,6 +10,10 @@ class StartCommand extends Command { super(startCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { } diff --git a/cli-commands/nodeos/subcommands/start/settings.json b/cli-commands/nodeos/subcommands/start/settings.json new file mode 100644 index 0000000..5e78b19 --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/settings.json @@ -0,0 +1,3 @@ +{ + "configuration": "" +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index 39565be..3f5705b 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -10,6 +10,10 @@ class StopCommand extends Command { super(stopCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { } diff --git a/cli-commands/shape/index.js b/cli-commands/shape/index.js index 5c79749..be430ea 100644 --- a/cli-commands/shape/index.js +++ b/cli-commands/shape/index.js @@ -12,6 +12,10 @@ class ShapeCommand extends Command { super(shapeCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args) { try { commandMessages.StartShaping(); diff --git a/cli-commands/test/index.js b/cli-commands/test/index.js index 031516f..ef03795 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/test/index.js @@ -13,6 +13,10 @@ class TestCommand extends Command { super(testCommandDefinition); } + define(...params) { + return this.defineCommand(...params); + } + async execute(args, TestFramework) { try { args.eoslime = eoslime.init(); diff --git a/cli.js b/cli.js index 8e04c05..908f775 100755 --- a/cli.js +++ b/cli.js @@ -8,10 +8,6 @@ const NodeosCommand = require('./cli-commands/nodeos'); const DeployCommand = require('./cli-commands/deploy'); const CompileCommand = require('./cli-commands/compile'); -const StartCommand = require('./cli-commands/nodeos/subcommands/start'); -const StopCommand = require('./cli-commands/nodeos/subcommands/stop'); -const ShowCommand = require('./cli-commands/nodeos/subcommands/show'); - const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); (() => { @@ -25,18 +21,14 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const deployCommand = new DeployCommand(); const compileCommand = new CompileCommand(); - // nodeos subcommands - const startCommand = new StartCommand(); - const stopCommand = new StopCommand(); - const showCommand = new ShowCommand(); - menu.usage('Usage: $0 [command]'); - menu.command(initCommand.template, initCommand.description, InitCommand.defineCommandOptions(initCommand), InitCommand.executeWithContext(initCommand)); - menu.command(testCommand.template, testCommand.description, TestCommand.defineCommandOptions(testCommand), TestCommand.executeWithContext(testCommand, MochaFramework)); - menu.command(shapeCommand.template, shapeCommand.description, ShapeCommand.defineCommandOptions(shapeCommand), ShapeCommand.executeWithContext(shapeCommand)); - menu.command(nodeosCommand.template, nodeosCommand.description, NodeosCommand.defineSubcommands(nodeosCommand, [startCommand, stopCommand, showCommand])); - menu.command(deployCommand.template, deployCommand.description, DeployCommand.defineCommandOptions(deployCommand), DeployCommand.executeWithContext(deployCommand)); - menu.command(compileCommand.template, compileCommand.description, CompileCommand.defineCommandOptions(compileCommand), CompileCommand.executeWithContext(compileCommand)); + + menu.command(initCommand.define()); + menu.command(testCommand.define(MochaFramework)); + menu.command(shapeCommand.define()); + menu.command(nodeosCommand.define()); + menu.command(deployCommand.define()); + menu.command(compileCommand.define()); menu.command({ command: '*', From 9f51a4a4391c1632739163000c9758c6476d53a3 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Tue, 28 Apr 2020 11:07:32 +0300 Subject: [PATCH 07/17] Removed redundant command definition --- cli-commands/command.js | 4 +--- cli-commands/compile/index.js | 4 ---- cli-commands/deploy/index.js | 4 ---- cli-commands/init/index.js | 4 ---- cli-commands/nodeos/subcommands/show/index.js | 4 ---- cli-commands/nodeos/subcommands/start/index.js | 4 ---- cli-commands/nodeos/subcommands/stop/index.js | 4 ---- cli-commands/shape/index.js | 4 ---- cli-commands/test/index.js | 4 ---- 9 files changed, 1 insertion(+), 35 deletions(-) diff --git a/cli-commands/command.js b/cli-commands/command.js index 4d9d6fa..0b60b81 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -21,9 +21,7 @@ class Command { return optionResults; } - define(...params) { } - - defineCommand(...params) { + define(...params) { return { command: this.template, description: this.description, diff --git a/cli-commands/compile/index.js b/cli-commands/compile/index.js index e65d1e9..d091331 100644 --- a/cli-commands/compile/index.js +++ b/cli-commands/compile/index.js @@ -15,10 +15,6 @@ class CompileCommand extends Command { super(compileCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { try { commandMessages.StartCompilation(); diff --git a/cli-commands/deploy/index.js b/cli-commands/deploy/index.js index 1979172..58b86d4 100644 --- a/cli-commands/deploy/index.js +++ b/cli-commands/deploy/index.js @@ -10,10 +10,6 @@ class DeployCommand extends Command { super(deployCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { try { commandMessages.StartDeployment(); diff --git a/cli-commands/init/index.js b/cli-commands/init/index.js index f0694ba..1386b73 100644 --- a/cli-commands/init/index.js +++ b/cli-commands/init/index.js @@ -18,10 +18,6 @@ class InitCommand extends Command { super(initCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - defineOptions(yargs) { super.defineOptions(yargs, initCommandDefinition.options); } diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js index a9855fd..6b221e5 100644 --- a/cli-commands/nodeos/subcommands/show/index.js +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -9,10 +9,6 @@ class ShowCommand extends Command { super(showCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { await super.processOptions(args); } diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 77f653a..1d05143 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -10,10 +10,6 @@ class StartCommand extends Command { super(startCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { } diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index 3f5705b..39565be 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -10,10 +10,6 @@ class StopCommand extends Command { super(stopCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { } diff --git a/cli-commands/shape/index.js b/cli-commands/shape/index.js index be430ea..5c79749 100644 --- a/cli-commands/shape/index.js +++ b/cli-commands/shape/index.js @@ -12,10 +12,6 @@ class ShapeCommand extends Command { super(shapeCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args) { try { commandMessages.StartShaping(); diff --git a/cli-commands/test/index.js b/cli-commands/test/index.js index ef03795..031516f 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/test/index.js @@ -13,10 +13,6 @@ class TestCommand extends Command { super(testCommandDefinition); } - define(...params) { - return this.defineCommand(...params); - } - async execute(args, TestFramework) { try { args.eoslime = eoslime.init(); From 19906436693142ef5c7f0c0d5a8a12ffe7f47cf5 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sun, 3 May 2020 17:54:21 +0300 Subject: [PATCH 08/17] Implemented subcommand nodeos start --- .../nodeos/subcommands/start/index.js | 45 ++++++++++++++++++- .../nodeos/subcommands/start/messages.js | 9 ++-- .../subcommands/start/options/path-option.js | 9 ++-- .../nodeos/subcommands/start/settings.js | 3 ++ .../nodeos/subcommands/start/settings.json | 3 -- package.json | 1 + 6 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 cli-commands/nodeos/subcommands/start/settings.js delete mode 100644 cli-commands/nodeos/subcommands/start/settings.json diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 1d05143..c32e85d 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -1,6 +1,10 @@ +const axios = require('axios'); + const Command = require('../../../command'); +const AsyncSoftExec = require('../../../helpers/async-soft-exec'); const commandMessages = require('./messages'); +const commandExpression = require('./settings').command; const startCommandDefinition = require('./definition'); // eoslime nodeos start --path @@ -11,8 +15,47 @@ class StartCommand extends Command { } async execute(args) { - + try { + commandMessages.NodeosStarting(); + const optionsResults = await super.processOptions(args); + await startNodeos(optionsResults.path); + } catch (error) { + commandMessages.UnsuccessfulStarting(error); + } + } +} + +const startNodeos = async function(folderPath) { + const nodeosRunning = await isNodeosRunning(); + + if (nodeosRunning) { + commandMessages.NodeosAlreadyRunning(); + } else { + await runNodeos(folderPath); } } +const isNodeosRunning = async function() { + try { + let result = await axios.get('http://localhost:8888/v1/chain/get_info'); + + if (result.status == 200) { + return true; + } + } catch (error) {} + + return false; +} + +const runNodeos = async function(folderPath) { + const expression = commandExpression.replace(new RegExp('{path}', 'g'), folderPath); + + const asyncSoftExec = new AsyncSoftExec(expression); + + asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); + asyncSoftExec.onSuccess(() => { commandMessages.SuccessfulStarting(); }); + + await asyncSoftExec.exec(); +} + module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/messages.js b/cli-commands/nodeos/subcommands/start/messages.js index e59974a..c2c9dd3 100644 --- a/cli-commands/nodeos/subcommands/start/messages.js +++ b/cli-commands/nodeos/subcommands/start/messages.js @@ -1,10 +1,11 @@ const chalk = require('chalk'); module.exports = { - 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, - 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, - 'UnsuccessfulProcessing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + 'NodeosStarting': () => { console.log(chalk.magentaBright('===== Starting nodeos ... =====')); }, + 'NodeosAlreadyRunning': () => { console.log(chalk.redBright(`===== Nodeos is already running =====`)); }, + 'SuccessfulStarting': () => { console.log(chalk.greenBright(`===== Successfully started =====`)); }, + 'UnsuccessfulStarting': (error) => { + console.log(chalk.redBright(`===== Unsuccessful starting =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/nodeos/subcommands/start/options/path-option.js index 3229afa..26c1f82 100644 --- a/cli-commands/nodeos/subcommands/start/options/path-option.js +++ b/cli-commands/nodeos/subcommands/start/options/path-option.js @@ -1,18 +1,21 @@ const Option = require('../../../../option'); +const fileSystemUtil = require('../../../../helpers/file-system-util'); class PathOption extends Option { constructor() { super( 'path', { - "describe": "Path to node folder", + "describe": "Path to nodeos folder", "type": "string", + "default": "." } ); } - process() { - + async process(optionValue) { + fileSystemUtil.isDir(optionValue); + return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/start/settings.js b/cli-commands/nodeos/subcommands/start/settings.js new file mode 100644 index 0000000..9cb7412 --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/settings.js @@ -0,0 +1,3 @@ +module.exports = { + "command": `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d {path}/data --config-dir {path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> {path}/nodeos.log 2>&1 &` +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/start/settings.json b/cli-commands/nodeos/subcommands/start/settings.json deleted file mode 100644 index 5e78b19..0000000 --- a/cli-commands/nodeos/subcommands/start/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "configuration": "" -} \ No newline at end of file diff --git a/package.json b/package.json index a925aa7..eb08d05 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "author": "Lyubomir Kiprov (Limechain)", "license": "MIT", "dependencies": { + "axios": "0.19.2", "chalk": "2.4.2", "cli-table": "0.3.1", "crypto-js": "3.1.9-1", From 4ce79e6d7b6f7535727506aaa80b79cb88c463cb Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sun, 3 May 2020 22:15:08 +0300 Subject: [PATCH 09/17] Implemented subcommand nodeos show --- cli-commands/nodeos/definition.js | 2 +- cli-commands/nodeos/messages.js | 10 ------ .../nodeos/subcommands/show/definition.js | 7 ++-- cli-commands/nodeos/subcommands/show/index.js | 27 +++++++++++++-- .../accounts-option/accounts-option.js | 31 ----------------- .../subcommands/show/options/logs-option.js | 32 ------------------ .../accounts}/accounts-table.js | 0 .../{ => subcommands/accounts}/accounts.json | 0 .../show/subcommands/accounts/definition.js | 5 +++ .../show/subcommands/accounts/index.js | 33 +++++++++++++++++++ .../{ => subcommands/accounts}/messages.js | 5 ++- .../show/subcommands/logs/definition.js | 8 +++++ .../show/subcommands/logs/index.js | 33 +++++++++++++++++++ .../show/subcommands/logs/messages.js | 12 +++++++ .../subcommands/logs/options/lines-option.js | 23 +++++++++++++ .../subcommands/logs/options/path-option.js | 22 +++++++++++++ .../nodeos/subcommands/start/index.js | 1 - package.json | 1 + 18 files changed, 168 insertions(+), 84 deletions(-) delete mode 100644 cli-commands/nodeos/messages.js delete mode 100644 cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js delete mode 100644 cli-commands/nodeos/subcommands/show/options/logs-option.js rename cli-commands/nodeos/subcommands/show/{options/accounts-option => subcommands/accounts}/accounts-table.js (100%) rename cli-commands/nodeos/subcommands/show/{ => subcommands/accounts}/accounts.json (100%) create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js rename cli-commands/nodeos/subcommands/show/{ => subcommands/accounts}/messages.js (50%) create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/index.js create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js create mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js diff --git a/cli-commands/nodeos/definition.js b/cli-commands/nodeos/definition.js index f28a683..e47c98f 100644 --- a/cli-commands/nodeos/definition.js +++ b/cli-commands/nodeos/definition.js @@ -1,5 +1,5 @@ module.exports = { "template": "nodeos", - "description": "Enable user to start/stop a local node", + "description": "Enable user to manage a local node", "options": [] } diff --git a/cli-commands/nodeos/messages.js b/cli-commands/nodeos/messages.js deleted file mode 100644 index e59974a..0000000 --- a/cli-commands/nodeos/messages.js +++ /dev/null @@ -1,10 +0,0 @@ -const chalk = require('chalk'); - -module.exports = { - 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, - 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, - 'UnsuccessfulProcessing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful processing =====`)); - console.log(error); - } -} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/definition.js b/cli-commands/nodeos/subcommands/show/definition.js index 9bccdd3..346c468 100644 --- a/cli-commands/nodeos/subcommands/show/definition.js +++ b/cli-commands/nodeos/subcommands/show/definition.js @@ -1,8 +1,5 @@ -const accountsOption = require('./options/accounts-option/accounts-option'); -const logsOption = require('./options/logs-option'); - module.exports = { - "template": "show [accounts] [logs]", + "template": "show", "description": "Show local node details", - "options": [accountsOption, logsOption] + "options": [] } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js index 6b221e5..640ec90 100644 --- a/cli-commands/nodeos/subcommands/show/index.js +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -1,16 +1,37 @@ const Command = require('../../../command'); +const LogsCommand = require('./subcommands/logs'); +const AccountsCommand = require('./subcommands/accounts'); + const showCommandDefinition = require('./definition'); -// eoslime nodeos show --accounts --logs +// eoslime nodeos show class ShowCommand extends Command { constructor() { super(showCommandDefinition); + + this.subcommands = [ + new AccountsCommand(), new LogsCommand() + ] } - async execute(args) { - await super.processOptions(args); + define(...params) { + return { + command: this.template, + description: this.description, + builder: (yargs) => { + yargs.usage(`Usage: $0 nodeos ${this.template} [command]`); + + for (const subcommand of this.subcommands) { + yargs.command(subcommand.define(...params)); + } + + yargs.demandCommand(1, ''); + + return yargs; + } + } } } diff --git a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js b/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js deleted file mode 100644 index 2b78086..0000000 --- a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-option.js +++ /dev/null @@ -1,31 +0,0 @@ -const AccountsTable = require('./accounts-table'); -const Option = require('../../../../../option'); - -const accounts = require('../../accounts.json'); -const optionMessages = require('../../messages'); - -class AccountsOption extends Option { - constructor() { - super( - 'accounts', - { - "describe": "Lists all predefined accounts", - "type": "string", - } - ); - - this.accountsTable = new AccountsTable(); - } - - process(optionValue) { - optionMessages.PredefinedAccounts(); - - accounts.forEach(account => { - this.accountsTable.addRow([account.name, account.publicKey, account.privateKey]); - }); - - this.accountsTable.draw(); - } -} - -module.exports = new AccountsOption(); diff --git a/cli-commands/nodeos/subcommands/show/options/logs-option.js b/cli-commands/nodeos/subcommands/show/options/logs-option.js deleted file mode 100644 index fcafd4a..0000000 --- a/cli-commands/nodeos/subcommands/show/options/logs-option.js +++ /dev/null @@ -1,32 +0,0 @@ -const exec = require('child_process').exec; -const Option = require('../../../../option'); -const optionMessages = require('../messages'); - -class LogsOption extends Option { - constructor() { - super( - 'logs', - { - "describe": "Lists last N lines from node logs", - "type": "number", - } - ); - } - - process(optionValue) { - optionMessages.NodeosLogs(); - - const numLines = optionValue > 0 ? optionValue : 10; - - exec(`tail -n ${numLines} nodeos.log`, (error, stdout, stderr) => { - if (error) { - throw new Error(`Could not show logs, due to '${error}'`); - } - - console.log(stdout); - console.error(stderr); - }); - } -} - -module.exports = new LogsOption(); diff --git a/cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js similarity index 100% rename from cli-commands/nodeos/subcommands/show/options/accounts-option/accounts-table.js rename to cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js diff --git a/cli-commands/nodeos/subcommands/show/accounts.json b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json similarity index 100% rename from cli-commands/nodeos/subcommands/show/accounts.json rename to cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js new file mode 100644 index 0000000..ecdfac9 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js @@ -0,0 +1,5 @@ +module.exports = { + "template": "accounts", + "description": "Lists all predefined accounts", + "options": [] +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js new file mode 100644 index 0000000..142d44a --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js @@ -0,0 +1,33 @@ +const Command = require('../../../../../command'); +const AccountsTable = require('./accounts-table'); + +const commandMessages = require('./messages'); +const accounts = require('./accounts.json'); +const accountsCommandDefinition = require('./definition'); + +// eoslime nodeos show accounts + +class AccountsCommand extends Command { + constructor() { + super(accountsCommandDefinition); + } + + async execute(args) { + try { + commandMessages.PredefinedAccounts(); + showAccounts(); + } catch (error) { + commandMessages.UnsuccessfulShowing(error); + } + } +} + +const showAccounts = function () { + let accountsTable = new AccountsTable(); + accounts.forEach(account => { + accountsTable.addRow([account.name, account.publicKey, account.privateKey]); + }); + accountsTable.draw(); +} + +module.exports = AccountsCommand; diff --git a/cli-commands/nodeos/subcommands/show/messages.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js similarity index 50% rename from cli-commands/nodeos/subcommands/show/messages.js rename to cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js index b11502d..1dbbf49 100644 --- a/cli-commands/nodeos/subcommands/show/messages.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js @@ -2,5 +2,8 @@ const chalk = require('chalk'); module.exports = { 'PredefinedAccounts': () => { console.log(chalk.magentaBright('===== Predefined accounts =====')); }, - 'NodeosLogs': () => { console.log(chalk.magentaBright('===== Nodeos logs =====')); } + 'UnsuccessfulShowing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful showing accounts =====`)); + console.log(error); + } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js new file mode 100644 index 0000000..1f552ae --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js @@ -0,0 +1,8 @@ +const pathOption = require('./options/path-option'); +const linesOption = require('./options/lines-option'); + +module.exports = { + "template": "logs [path] [lines]", + "description": "Lists last N lines from node logs", + "options": [pathOption, linesOption] +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js new file mode 100644 index 0000000..72621e3 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js @@ -0,0 +1,33 @@ +const Command = require('../../../../../command'); +const readLastLines = require('read-last-lines'); + +const commandMessages = require('./messages'); +const showCommandDefinition = require('./definition'); + +const fileSystemUtil = require('../../../..../../../../helpers/file-system-util'); + +// eoslime nodeos show logs --path --lines + +class LogsCommand extends Command { + constructor() { + super(showCommandDefinition); + } + + async execute(args) { + try { + const optionsResults = await super.processOptions(args); + await showLogs(optionsResults); + } catch (error) { + commandMessages.UnsuccessfulShowing(error); + } + } +} + +const showLogs = async function(result) { + const filePath = `${result.path}/nodeos.log`; + fileSystemUtil.isFile(filePath); + let logs = await readLastLines.read(filePath, result.lines); + commandMessages.NodeosLogs(logs); +} + +module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js new file mode 100644 index 0000000..67059ef --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js @@ -0,0 +1,12 @@ +const chalk = require('chalk'); + +module.exports = { + 'NodeosLogs': (logs) => { + console.log(chalk.magentaBright('===== Nodeos logs =====')); + console.log(logs); + }, + 'UnsuccessfulShowing': (error) => { + console.log(chalk.redBright(`===== Unsuccessful showing logs =====`)); + console.log(error); + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js new file mode 100644 index 0000000..b374198 --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js @@ -0,0 +1,23 @@ +const Option = require('../../../../../../option'); + +const commandMessages = require('../messages'); +const readLastLines = require('read-last-lines'); + +class LinesOption extends Option { + constructor() { + super( + 'lines', + { + "describe": "Number of lines to display", + "type": "number", + "default": 10 + } + ); + } + + async process(optionValue) { + return optionValue ? optionValue : 10; + } +} + +module.exports = new LinesOption(); diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js new file mode 100644 index 0000000..07dd1ce --- /dev/null +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js @@ -0,0 +1,22 @@ +const Option = require('../../../../../../option'); +const fileSystemUtil = require('../../../..../../../../../helpers/file-system-util'); + +class PathOption extends Option { + constructor() { + super( + 'path', + { + "describe": "Path to nodeos folder", + "type": "string", + "default": "." + } + ); + } + + async process(optionValue) { + fileSystemUtil.isDir(optionValue); + return optionValue; + } +} + +module.exports = new PathOption(); diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index c32e85d..64eb23e 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -51,7 +51,6 @@ const runNodeos = async function(folderPath) { const expression = commandExpression.replace(new RegExp('{path}', 'g'), folderPath); const asyncSoftExec = new AsyncSoftExec(expression); - asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); asyncSoftExec.onSuccess(() => { commandMessages.SuccessfulStarting(); }); diff --git a/package.json b/package.json index eb08d05..5307dbd 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "is-invalid-path": "1.0.2", "mocha": "5.2.0", "prompts": "2.2.1", + "read-last-lines": "1.7.2", "simple-git": "1.132.0", "yargs": "12.0.5" }, From 82a075940bd5ad67178a6fbb542a0e105d33bdab Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Sun, 3 May 2020 22:22:15 +0300 Subject: [PATCH 10/17] updated LinesOption --- .../subcommands/show/subcommands/logs/options/lines-option.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js index b374198..434bb9d 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js @@ -9,8 +9,7 @@ class LinesOption extends Option { 'lines', { "describe": "Number of lines to display", - "type": "number", - "default": 10 + "type": "number" } ); } From 3b76f3d29dd3fe85e2e24102733a650ff88fb266 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Mon, 4 May 2020 03:24:02 +0300 Subject: [PATCH 11/17] Implemented subcommand nodeos stop --- .../show/subcommands/logs/index.js | 17 ++++--- .../subcommands/logs/options/lines-option.js | 6 +-- .../subcommands/logs/options/path-option.js | 6 ++- .../nodeos/subcommands/start/index.js | 6 +-- .../nodeos/subcommands/start/messages.js | 2 +- .../nodeos/subcommands/stop/definition.js | 5 +- cli-commands/nodeos/subcommands/stop/index.js | 51 ++++++++++++++++++- .../nodeos/subcommands/stop/messages.js | 19 +++++-- .../subcommands/stop/options/path-option.js | 7 ++- .../subcommands/stop/options/pid-option.js | 19 +++++++ 10 files changed, 111 insertions(+), 27 deletions(-) create mode 100644 cli-commands/nodeos/subcommands/stop/options/pid-option.js diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js index 72621e3..1fc4ec5 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js @@ -1,11 +1,9 @@ +const exec = require('child_process').exec; const Command = require('../../../../../command'); -const readLastLines = require('read-last-lines'); const commandMessages = require('./messages'); const showCommandDefinition = require('./definition'); -const fileSystemUtil = require('../../../..../../../../helpers/file-system-util'); - // eoslime nodeos show logs --path --lines class LogsCommand extends Command { @@ -23,11 +21,14 @@ class LogsCommand extends Command { } } -const showLogs = async function(result) { - const filePath = `${result.path}/nodeos.log`; - fileSystemUtil.isFile(filePath); - let logs = await readLastLines.read(filePath, result.lines); - commandMessages.NodeosLogs(logs); +const showLogs = async function (result) { + exec(`tail -n ${result.lines} ${result.path}`, (error, stdout, stderr) => { + if (error) { + throw new Error(`Could not show logs, due to '${error}'`); + } + + commandMessages.NodeosLogs(stdout); + }); } module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js index 434bb9d..cdef565 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js @@ -1,15 +1,13 @@ const Option = require('../../../../../../option'); -const commandMessages = require('../messages'); -const readLastLines = require('read-last-lines'); - class LinesOption extends Option { constructor() { super( 'lines', { "describe": "Number of lines to display", - "type": "number" + "type": "number", + "default": 10 } ); } diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js index 07dd1ce..7b933b8 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js @@ -14,8 +14,12 @@ class PathOption extends Option { } async process(optionValue) { + const filePath = `${optionValue}/nodeos.log`; + fileSystemUtil.isDir(optionValue); - return optionValue; + fileSystemUtil.isFile(filePath); + + return filePath; } } diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 64eb23e..245b3cc 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -16,7 +16,7 @@ class StartCommand extends Command { async execute(args) { try { - commandMessages.NodeosStarting(); + commandMessages.StartingNodeos(); const optionsResults = await super.processOptions(args); await startNodeos(optionsResults.path); } catch (error) { @@ -35,7 +35,7 @@ const startNodeos = async function(folderPath) { } } -const isNodeosRunning = async function() { +const isNodeosRunning = async function () { try { let result = await axios.get('http://localhost:8888/v1/chain/get_info'); @@ -47,7 +47,7 @@ const isNodeosRunning = async function() { return false; } -const runNodeos = async function(folderPath) { +const runNodeos = async function (folderPath) { const expression = commandExpression.replace(new RegExp('{path}', 'g'), folderPath); const asyncSoftExec = new AsyncSoftExec(expression); diff --git a/cli-commands/nodeos/subcommands/start/messages.js b/cli-commands/nodeos/subcommands/start/messages.js index c2c9dd3..743587d 100644 --- a/cli-commands/nodeos/subcommands/start/messages.js +++ b/cli-commands/nodeos/subcommands/start/messages.js @@ -1,7 +1,7 @@ const chalk = require('chalk'); module.exports = { - 'NodeosStarting': () => { console.log(chalk.magentaBright('===== Starting nodeos ... =====')); }, + 'StartingNodeos': () => { console.log(chalk.magentaBright('===== Starting nodeos ... =====')); }, 'NodeosAlreadyRunning': () => { console.log(chalk.redBright(`===== Nodeos is already running =====`)); }, 'SuccessfulStarting': () => { console.log(chalk.greenBright(`===== Successfully started =====`)); }, 'UnsuccessfulStarting': (error) => { diff --git a/cli-commands/nodeos/subcommands/stop/definition.js b/cli-commands/nodeos/subcommands/stop/definition.js index 6f3205b..a5565b5 100644 --- a/cli-commands/nodeos/subcommands/stop/definition.js +++ b/cli-commands/nodeos/subcommands/stop/definition.js @@ -1,7 +1,8 @@ const pathOption = require('./options/path-option'); +const pidOption = require('./options/pid-option'); module.exports = { - "template": "stop [path]", + "template": "stop [path] [pid]", "description": "Stop a local node", - "options": [pathOption] + "options": [pathOption, pidOption] } diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index 39565be..e5fd0e2 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -1,9 +1,12 @@ +const axios = require('axios'); + const Command = require('../../../command'); +const AsyncSoftExec = require('../../../helpers/async-soft-exec'); const commandMessages = require('./messages'); const stopCommandDefinition = require('./definition'); -// eoslime nodeos stop --path +// eoslime nodeos stop --path --pid class StopCommand extends Command { constructor() { @@ -11,8 +14,52 @@ class StopCommand extends Command { } async execute(args) { - + try { + commandMessages.StoppingNodeos(); + const optionsResults = await super.processOptions(args); + await stopNodeos(optionsResults); + } catch (error) { + commandMessages.UnsuccessfulStopping(error); + } } } +const stopNodeos = async function (result) { + const nodeosRunning = await isNodeosRunning(); + + if (!nodeosRunning) { + commandMessages.NoRunningNodeos(); + } else { + await stopAndClean(result); + } +} + +const isNodeosRunning = async function () { + try { + let result = await axios.get('http://localhost:8888/v1/chain/get_info'); + + if (result.status == 200) { + return true; + } + } catch (error) {} + + return false; +} + +const stopAndClean = async function (result) { + const killCommand = result.pid ? `kill ${result.pid}` : `pkill nodeos`; + + const asyncKillExec = new AsyncSoftExec(killCommand); + asyncKillExec.onError((error) => commandMessages.UnsuccessfulProcessTermination(error)); + asyncKillExec.onSuccess(() => commandMessages.SuccessfulProcessTermination()); + await asyncKillExec.exec(); + + const asyncCleanExec = new AsyncSoftExec(`rm -rf ${result.path}/*`); + asyncCleanExec.onError((error) => commandMessages.UnsuccessfulCleanUp(error)); + asyncCleanExec.onSuccess(() => commandMessages.SuccessfulCleanUp()); + await asyncCleanExec.exec(); + + commandMessages.SuccessfulStopping(); +} + module.exports = StopCommand; diff --git a/cli-commands/nodeos/subcommands/stop/messages.js b/cli-commands/nodeos/subcommands/stop/messages.js index e59974a..d6c7538 100644 --- a/cli-commands/nodeos/subcommands/stop/messages.js +++ b/cli-commands/nodeos/subcommands/stop/messages.js @@ -1,10 +1,21 @@ const chalk = require('chalk'); module.exports = { - 'StartProcessing': () => { console.log(chalk.magentaBright('===== Processing ... =====')); }, - 'SuccessfulProcessing': () => { console.log(chalk.greenBright(`===== Successful processing =====`)); }, - 'UnsuccessfulProcessing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful processing =====`)); + 'StoppingNodeos': () => { console.log(chalk.magentaBright('===== Stopping nodeos ... =====')); }, + 'NoRunningNodeos': () => { console.log(chalk.redBright('===== There is no running nodeos ... =====')); }, + 'SuccessfulProcessTermination': () => { console.log(chalk.blueBright('===== Instance terminated =====')); }, + 'UnsuccessfulProcessTermination': (error) => { + console.log(chalk.redBright('===== Unsuccessful instance termination =====')); + console.log(error); + }, + 'SuccessfulCleanUp': () => { console.log(chalk.blueBright('===== Folder cleaned up =====')); }, + 'UnsuccessfulCleanUp': (error) => { + console.log(chalk.redBright('===== Unsuccessful folder clean up =====')); + console.log(error); + }, + 'SuccessfulStopping': () => { console.log(chalk.greenBright(`===== Successfully stopped =====`)); }, + 'UnsuccessfulStopping': (error) => { + console.log(chalk.redBright(`===== Unsuccessful stopping =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/options/path-option.js b/cli-commands/nodeos/subcommands/stop/options/path-option.js index 3229afa..e09848d 100644 --- a/cli-commands/nodeos/subcommands/stop/options/path-option.js +++ b/cli-commands/nodeos/subcommands/stop/options/path-option.js @@ -1,4 +1,5 @@ const Option = require('../../../../option'); +const fileSystemUtil = require('../../../../helpers/file-system-util'); class PathOption extends Option { constructor() { @@ -7,12 +8,14 @@ class PathOption extends Option { { "describe": "Path to node folder", "type": "string", + "default": "." } ); } - process() { - + process(optionValue) { + fileSystemUtil.isDir(optionValue); + return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/stop/options/pid-option.js b/cli-commands/nodeos/subcommands/stop/options/pid-option.js new file mode 100644 index 0000000..5cbda6a --- /dev/null +++ b/cli-commands/nodeos/subcommands/stop/options/pid-option.js @@ -0,0 +1,19 @@ +const Option = require('../../../../option'); + +class PIDOption extends Option { + constructor() { + super( + 'pid', + { + "describe": "Process ID of running nodeos", + "type": "number" + } + ); + } + + process(optionValue) { + return optionValue; + } +} + +module.exports = new PIDOption(); From a7e507bff91e864c8ba42dcc20ddbfd026e11a41 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Mon, 4 May 2020 14:09:05 +0300 Subject: [PATCH 12/17] Added subcommand optimization --- cli-commands/command-definer.js | 39 +++++++++++++++++++ cli-commands/command.js | 32 ++------------- cli-commands/compile/index.js | 2 + cli-commands/deploy/index.js | 2 + cli-commands/init/index.js | 2 + cli-commands/nodeos/index.js | 28 +++---------- cli-commands/nodeos/subcommands/show/index.js | 27 ++----------- .../show/subcommands/accounts/index.js | 2 + .../show/subcommands/logs/index.js | 2 + .../nodeos/subcommands/start/index.js | 2 + cli-commands/nodeos/subcommands/stop/index.js | 2 + cli-commands/parent-command.js | 29 ++++++++++++++ cli-commands/shape/index.js | 4 ++ cli-commands/test/index.js | 4 ++ cli.js | 17 ++++---- package.json | 1 - 16 files changed, 112 insertions(+), 83 deletions(-) create mode 100644 cli-commands/command-definer.js create mode 100644 cli-commands/parent-command.js diff --git a/cli-commands/command-definer.js b/cli-commands/command-definer.js new file mode 100644 index 0000000..11f874e --- /dev/null +++ b/cli-commands/command-definer.js @@ -0,0 +1,39 @@ +class CommandDefiner { + constructor(yargs) { + this.yargs = yargs; + } + + define (command, ...params) { + return { + command: command.template, + description: command.description, + builder: this.build(command), + handler: this.handle(command, ...params) + } + } + + build (command) { + return (yargs) => { + for (const subcommand of command.subcommands) { + yargs.command(this.define(subcommand)); + } + + for (const option of command.options) { + yargs = yargs.options(option.name, option.definition); + } + + return yargs; + } + } + + handle (command, ...params) { + return async (args) => { + const result = await command.execute(args, ...params); + if (!result) { + this.yargs.showHelp(); + } + } + } +} + +module.exports = CommandDefiner; diff --git a/cli-commands/command.js b/cli-commands/command.js index 0b60b81..fa1e38d 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -1,9 +1,10 @@ class Command { constructor(commandDefinition) { - this.template = commandDefinition.template; - this.description = commandDefinition.description; - this.options = commandDefinition.options; + this.template = commandDefinition.template || ''; + this.description = commandDefinition.description || ''; + this.options = commandDefinition.options || []; + this.subcommands = []; } async processOptions(args) { @@ -21,31 +22,6 @@ class Command { return optionResults; } - define(...params) { - return { - command: this.template, - description: this.description, - builder: this.defineCommandOptions(), - handler: this.defineCommandExecution(...params) - } - } - - defineCommandOptions() { - return (yargs) => { - for (const option of this.options) { - yargs = yargs.options(option.name, option.definition); - } - - return yargs; - } - } - - defineCommandExecution(...params) { - return async (args) => { - await this.execute(args, ...params); - } - } - execute(args) { } } diff --git a/cli-commands/compile/index.js b/cli-commands/compile/index.js index d091331..6b6e9a1 100644 --- a/cli-commands/compile/index.js +++ b/cli-commands/compile/index.js @@ -32,6 +32,7 @@ class CompileCommand extends Command { asyncSoftExec.onSuccess(() => commandMessages.SuccessfulCompilationOfContract(contractPath.fileName)); await asyncSoftExec.exec(); + return true; } } else { commandMessages.ContractNotExisting(); @@ -39,6 +40,7 @@ class CompileCommand extends Command { } catch (error) { commandMessages.UnsuccessfulCompilation(error); } + return false; } } diff --git a/cli-commands/deploy/index.js b/cli-commands/deploy/index.js index 58b86d4..05da5af 100644 --- a/cli-commands/deploy/index.js +++ b/cli-commands/deploy/index.js @@ -15,9 +15,11 @@ class DeployCommand extends Command { commandMessages.StartDeployment(); const optionsResults = await super.processOptions(args); await runDeploymentScripts(optionsResults.path, optionsResults.network, optionsResults.deployer); + return true; } catch (error) { commandMessages.UnsuccessfulDeployment(error); } + return false; } } diff --git a/cli-commands/init/index.js b/cli-commands/init/index.js index 1386b73..9f449c9 100644 --- a/cli-commands/init/index.js +++ b/cli-commands/init/index.js @@ -41,6 +41,8 @@ class InitCommand extends Command { asyncSoftExec.onSuccess(() => { commandMessages.SuccessfulInstallation(); }); await asyncSoftExec.exec(); + + return true; } } diff --git a/cli-commands/nodeos/index.js b/cli-commands/nodeos/index.js index 818ea0a..7101281 100644 --- a/cli-commands/nodeos/index.js +++ b/cli-commands/nodeos/index.js @@ -1,4 +1,4 @@ -const Command = require('./../command'); +const ParentCommand = require('../parent-command'); const StartCommand = require('./subcommands/start'); const StopCommand = require('./subcommands/stop'); @@ -8,31 +8,13 @@ const nodeosCommandDefinition = require('./definition'); // eoslime nodeos -class NodeosCommand extends Command { +class NodeosCommand extends ParentCommand { constructor() { super(nodeosCommandDefinition); - this.subcommands = [ - new StartCommand(), new StopCommand(), new ShowCommand() - ] - } - - define(...params) { - return { - command: this.template, - description: this.description, - builder: (yargs) => { - yargs.usage(`Usage: $0 ${this.template} [command]`); - - for (const subcommand of this.subcommands) { - yargs.command(subcommand.define(...params)); - } - - yargs.demandCommand(1, ''); - - return yargs; - } - } + this.subcommands.push(new StartCommand()); + this.subcommands.push(new StopCommand()); + this.subcommands.push(new ShowCommand()); } } diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js index 640ec90..134c600 100644 --- a/cli-commands/nodeos/subcommands/show/index.js +++ b/cli-commands/nodeos/subcommands/show/index.js @@ -1,4 +1,4 @@ -const Command = require('../../../command'); +const ParentCommand = require('../../../parent-command'); const LogsCommand = require('./subcommands/logs'); const AccountsCommand = require('./subcommands/accounts'); @@ -7,31 +7,12 @@ const showCommandDefinition = require('./definition'); // eoslime nodeos show -class ShowCommand extends Command { +class ShowCommand extends ParentCommand { constructor() { super(showCommandDefinition); - this.subcommands = [ - new AccountsCommand(), new LogsCommand() - ] - } - - define(...params) { - return { - command: this.template, - description: this.description, - builder: (yargs) => { - yargs.usage(`Usage: $0 nodeos ${this.template} [command]`); - - for (const subcommand of this.subcommands) { - yargs.command(subcommand.define(...params)); - } - - yargs.demandCommand(1, ''); - - return yargs; - } - } + this.subcommands.push(new AccountsCommand()); + this.subcommands.push(new LogsCommand()); } } diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js index 142d44a..5166510 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js @@ -16,9 +16,11 @@ class AccountsCommand extends Command { try { commandMessages.PredefinedAccounts(); showAccounts(); + return true; } catch (error) { commandMessages.UnsuccessfulShowing(error); } + return false; } } diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js index 1fc4ec5..c6e64cf 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js @@ -15,9 +15,11 @@ class LogsCommand extends Command { try { const optionsResults = await super.processOptions(args); await showLogs(optionsResults); + return true; } catch (error) { commandMessages.UnsuccessfulShowing(error); } + return false; } } diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 245b3cc..107d1e6 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -19,9 +19,11 @@ class StartCommand extends Command { commandMessages.StartingNodeos(); const optionsResults = await super.processOptions(args); await startNodeos(optionsResults.path); + return true; } catch (error) { commandMessages.UnsuccessfulStarting(error); } + return false; } } diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index e5fd0e2..8c3ebb2 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -18,9 +18,11 @@ class StopCommand extends Command { commandMessages.StoppingNodeos(); const optionsResults = await super.processOptions(args); await stopNodeos(optionsResults); + return true; } catch (error) { commandMessages.UnsuccessfulStopping(error); } + return false; } } diff --git a/cli-commands/parent-command.js b/cli-commands/parent-command.js new file mode 100644 index 0000000..a47bdac --- /dev/null +++ b/cli-commands/parent-command.js @@ -0,0 +1,29 @@ +const Command = require('./command'); + +class ParentCommand extends Command { + constructor(commandDefinition) { + super(commandDefinition); + } + + async execute (args) { + if (validate(args, this.options)) { + await super.processOptions(args); + return true; + } + + return false; + } +} + +const validate = function (args, commandOptions) { + for (let i = 0; i < commandOptions.length; i++) { + const option = commandOptions[i]; + if (args[option.name]) { + return true; + } + } + + return false; +} + +module.exports = ParentCommand; diff --git a/cli-commands/shape/index.js b/cli-commands/shape/index.js index 5c79749..f0e8f03 100644 --- a/cli-commands/shape/index.js +++ b/cli-commands/shape/index.js @@ -24,9 +24,13 @@ class ShapeCommand extends Command { await git.clone(optionsResults.framework); commandMessages.SuccessfulShaping(); + + return true; } catch (error) { commandMessages.UnsuccessfulShaping(error); } + + return false; } } diff --git a/cli-commands/test/index.js b/cli-commands/test/index.js index 031516f..3c01b44 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/test/index.js @@ -25,9 +25,13 @@ class TestCommand extends Command { args.testFramework.setDescribeArgs(args.eoslime); args.testFramework.runTests(); + + return true; } catch (error) { console.log(error); } + + return false; } } diff --git a/cli.js b/cli.js index 908f775..779aede 100755 --- a/cli.js +++ b/cli.js @@ -1,5 +1,6 @@ #!/usr/bin/env node const exec = require('child_process').exec; +const CommandDefiner = require('./cli-commands/command-definer'); const InitCommand = require('./cli-commands/init'); const TestCommand = require('./cli-commands/test'); @@ -14,6 +15,8 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); let menu = require('yargs'); + const commandDefiner = new CommandDefiner(menu); + const initCommand = new InitCommand(); const testCommand = new TestCommand(); const shapeCommand = new ShapeCommand(); @@ -21,14 +24,12 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const deployCommand = new DeployCommand(); const compileCommand = new CompileCommand(); - menu.usage('Usage: $0 [command]'); - - menu.command(initCommand.define()); - menu.command(testCommand.define(MochaFramework)); - menu.command(shapeCommand.define()); - menu.command(nodeosCommand.define()); - menu.command(deployCommand.define()); - menu.command(compileCommand.define()); + menu.command(commandDefiner.define(initCommand)); + menu.command(commandDefiner.define(testCommand, MochaFramework)); + menu.command(commandDefiner.define(shapeCommand)); + menu.command(commandDefiner.define(nodeosCommand)); + menu.command(commandDefiner.define(deployCommand)); + menu.command(commandDefiner.define(compileCommand)); menu.command({ command: '*', diff --git a/package.json b/package.json index 5307dbd..eb08d05 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,6 @@ "is-invalid-path": "1.0.2", "mocha": "5.2.0", "prompts": "2.2.1", - "read-last-lines": "1.7.2", "simple-git": "1.132.0", "yargs": "12.0.5" }, From 1de8013860be523e452a45153d8edb7a6c9d0d1c Mon Sep 17 00:00:00 2001 From: bakasura980 Date: Thu, 7 May 2020 15:50:54 +0300 Subject: [PATCH 13/17] Implement getRawWASM and getABI methods in Provider; Implement getRawWASM method in Contract; Refactor wrong inheritance code coupling; Add tests --- package.json | 2 +- src/contract/contract-deployer.js | 60 ----------------- src/contract/contract-factory.js | 91 ++++++++++++++++++++------ src/contract/contract-initializator.js | 43 ++++++++++++ src/contract/contract.js | 8 ++- src/network-providers/base-provider.js | 12 +++- tests/account-tests.js | 4 +- tests/contract-tests.js | 63 +++++++++++++++++- tests/providers-tests.js | 34 ++++++++++ 9 files changed, 229 insertions(+), 88 deletions(-) delete mode 100644 src/contract/contract-deployer.js create mode 100644 src/contract/contract-initializator.js diff --git a/package.json b/package.json index b332aca..02b4814 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "eoslime is an EOS development and deployment framework based on eosjs.js", "main": "index.js", "scripts": { - "test": "bash ./tests/testing-contracts/compile.sh && nyc --check-coverage mocha './tests/*.js'", + "test": "bash ./tests/testing-contracts/compile.sh && mocha './tests/*.js'", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" }, "author": "Lyubomir Kiprov (Limechain)", diff --git a/src/contract/contract-deployer.js b/src/contract/contract-deployer.js deleted file mode 100644 index c09fa73..0000000 --- a/src/contract/contract-deployer.js +++ /dev/null @@ -1,60 +0,0 @@ -const is = require('./../helpers/is'); -const contractFilesReader = require('./../helpers/contract-files-reader'); - -const EventClass = require('./../helpers/event-class'); - -const defaultDeployOptions = { - inline: false -} - -const deployOptionsActions = { - inline: async (contract, inline) => { - if (inline) { - return contract.makeInline(); - } - } -} - -const EVENTS = { - 'deploy': 'deploy' -} - -class ContractDeployer extends EventClass { - - constructor(provider) { - super(EVENTS); - this.provider = provider; - } - - async deployOnAccount(wasmPath, abiPath, contractAccount, options = defaultDeployOptions) { - is(contractAccount).instanceOf('BaseAccount'); - - const abi = contractFilesReader.readABIFromFile(abiPath); - const wasm = contractFilesReader.readWASMFromFile(wasmPath); - - const setCodeTxReceipt = await this.provider.eos.setcode(contractAccount.name, 0, 0, wasm, { keyProvider: contractAccount.privateKey }); - const setAbiTxReceipt = await this.provider.eos.setabi(contractAccount.name, abi, { keyProvider: contractAccount.privateKey }); - - const contract = this.fromFile(abi, contractAccount.name, contractAccount); - - options = Object.assign(defaultDeployOptions, options); - await executeOptions(contract, options); - - this.emit(EVENTS.deploy, [setCodeTxReceipt, setAbiTxReceipt], contract); - - return contract; - } -} - -const executeOptions = async function (contract, options) { - const optionsKeys = Object.keys(options); - for (let i = 0; i < optionsKeys.length; i++) { - const optionKey = optionsKeys[i]; - - if (deployOptionsActions[optionKey]) { - await deployOptionsActions[optionKey](contract, options[optionKey]); - } - } -} - -module.exports = ContractDeployer; diff --git a/src/contract/contract-factory.js b/src/contract/contract-factory.js index 1fc23f1..7d2b71a 100644 --- a/src/contract/contract-factory.js +++ b/src/contract/contract-factory.js @@ -1,47 +1,96 @@ -const Contract = require('./contract'); +const is = require('../helpers/is'); +const contractFilesReader = require('../helpers/contract-files-reader'); + +const ContractInitializator = require('./contract-initializator'); const AccountFactory = require('../account/normal-account/account-factory'); -const ContractDeployer = require('./contract-deployer'); +const defaultDeployOptions = { + inline: false +} -const is = require('./../helpers/is'); -const contractFilesReader = require('./..//helpers/contract-files-reader'); +const deployOptionsActions = { + inline: async (contract, inline) => { + if (inline) { + return contract.makeInline(); + } + } +} const EVENTS = { - 'init': 'init', + 'deploy': 'deploy' } -class ContractFactory extends ContractDeployer { +class ContractFactory extends ContractInitializator { constructor(provider) { super(provider); Object.assign(this.events, EVENTS); } - fromFile(abi, contractName, contractExecutorAccount = this.provider.defaultAccount) { - let abiInterface = abi; - if (contractFilesReader.doesAbiExists(abi)) { - abiInterface = contractFilesReader.readABIFromFile(abi); - } - - const contract = new Contract(this.provider, abiInterface, contractName, contractExecutorAccount); - this.emit(EVENTS.init, contract); + async deploy (wasmPath, abiPath, options) { + const accountFactory = new AccountFactory(this.provider); + const newContractAccount = await accountFactory.createRandom(); - return contract; + return this.deployOnAccount(wasmPath, abiPath, newContractAccount, options); } - async at(contractName, contractExecutorAccount = this.provider.defaultAccount) { - const abiInterface = (await this.provider.eos.getAbi(contractName)).abi; - const contract = new Contract(this.provider, abiInterface, contractName, contractExecutorAccount); + async deployOnAccount (wasmPath, abiPath, contractAccount, options = defaultDeployOptions) { + const abi = contractFilesReader.readABIFromFile(abiPath); + const wasm = contractFilesReader.readWASMFromFile(wasmPath); + + const contract = await this.__processDeployment( + wasm, + abi, + contractAccount, + options + ); - this.emit(EVENTS.init, contract); return contract; } - async deploy(wasmPath, abiPath, options) { + async deployRaw (wasm, abi, options) { const accountFactory = new AccountFactory(this.provider); const newContractAccount = await accountFactory.createRandom(); - return super.deployOnAccount(wasmPath, abiPath, newContractAccount, options); + return this.deployRawOnAccount(wasm, abi, newContractAccount, options); + } + + async deployRawOnAccount (wasm, abi, contractAccount, options = defaultDeployOptions) { + const contract = await this.__processDeployment( + Buffer.from(wasm, 'base64'), + abi, + contractAccount, + options + ); + + return contract; + } + + async __processDeployment (wasm, abi, contractAccount, options = defaultDeployOptions) { + is(contractAccount).instanceOf('BaseAccount'); + + const setCodeTxReceipt = await this.provider.eos.setcode(contractAccount.name, 0, 0, wasm, { keyProvider: contractAccount.privateKey }); + const setAbiTxReceipt = await this.provider.eos.setabi(contractAccount.name, abi, { keyProvider: contractAccount.privateKey }); + + const contract = this.fromFile(abi, contractAccount.name, contractAccount); + + options = Object.assign(defaultDeployOptions, options); + await executeOptions(contract, options); + + this.emit(EVENTS.deploy, [setCodeTxReceipt, setAbiTxReceipt], contract); + + return contract; + } +} + +const executeOptions = async function (contract, options) { + const optionsKeys = Object.keys(options); + for (let i = 0; i < optionsKeys.length; i++) { + const optionKey = optionsKeys[i]; + + if (deployOptionsActions[optionKey]) { + await deployOptionsActions[optionKey](contract, options[optionKey]); + } } } diff --git a/src/contract/contract-initializator.js b/src/contract/contract-initializator.js new file mode 100644 index 0000000..ab2eedb --- /dev/null +++ b/src/contract/contract-initializator.js @@ -0,0 +1,43 @@ +const Contract = require('./contract'); + +const is = require('../helpers/is'); +const contractFilesReader = require('../helpers/contract-files-reader'); + +const EventClass = require('../helpers/event-class'); +const EVENTS = { + 'init': 'init', +} + +class ContractInitializator extends EventClass { + + constructor(provider) { + super(EVENTS); + this.provider = provider; + } + + fromFile (abi, contractName, contractExecutorAccount = this.provider.defaultAccount) { + is(contractExecutorAccount).instanceOf('BaseAccount'); + + let abiInterface = abi; + if (contractFilesReader.doesAbiExists(abi)) { + abiInterface = contractFilesReader.readABIFromFile(abi); + } + + const contract = new Contract(this.provider, abiInterface, contractName, contractExecutorAccount); + this.emit(EVENTS.init, contract); + + return contract; + } + + async at (contractName, contractExecutorAccount = this.provider.defaultAccount) { + is(contractExecutorAccount).instanceOf('BaseAccount'); + + const abiInterface = (await this.provider.eos.getAbi(contractName)).abi; + const contract = new Contract(this.provider, abiInterface, contractName, contractExecutorAccount); + + this.emit(EVENTS.init, contract); + return contract; + } +} + +module.exports = ContractInitializator; diff --git a/src/contract/contract.js b/src/contract/contract.js index f7c6382..b3e5681 100644 --- a/src/contract/contract.js +++ b/src/contract/contract.js @@ -3,6 +3,7 @@ const FunctionsFactory = require('./contract-function/functions-factory'); class Contract { constructor(provider, abi, contractName, contractExecutorAccount) { + this.abi = abi; this.name = contractName; this.provider = provider; this.executor = contractExecutorAccount; @@ -11,7 +12,7 @@ class Contract { declareTableGetters.call(this, abi); } - async makeInline() { + async makeInline () { is(this.executor).instanceOf('BaseAccount', 'executor is missing'); if (this.name != this.executor.name) { @@ -20,6 +21,11 @@ class Contract { return this.executor.addPermission("eosio.code"); } + + async getRawWASM () { + const wasm = await this.provider.getRawWASM(this.name); + return wasm; + } } module.exports = Contract; diff --git a/src/network-providers/base-provider.js b/src/network-providers/base-provider.js index 0649392..effd383 100644 --- a/src/network-providers/base-provider.js +++ b/src/network-providers/base-provider.js @@ -22,10 +22,20 @@ class BaseProvider { }) } - select(table) { + select (table) { const tableReader = new TableReader(this.eos); return tableReader.select(table); } + + async getABI (contractName) { + const result = await this.eos.getAbi(contractName); + return result.abi; + } + + async getRawWASM (contractName) { + const result = await this.eos.getRawCodeAndAbi(contractName); + return result.wasm; + } } module.exports = BaseProvider diff --git a/tests/account-tests.js b/tests/account-tests.js index 7a52b5f..9c7a2c0 100644 --- a/tests/account-tests.js +++ b/tests/account-tests.js @@ -63,7 +63,7 @@ describe('Account', function () { /* Deploy eos token contract on local nodoes in order to send eos and buy ram / bandwidth */ - async function createEOSToken() { + async function createEOSToken () { const TOKEN_ABI_PATH = './tests/testing-contracts/compiled/eosio.token.abi'; const TOKEN_WASM_PATH = './tests/testing-contracts/compiled/eosio.token.wasm'; const TOTAL_SUPPLY = '1000000000.0000 SYS'; @@ -82,7 +82,7 @@ describe('Account', function () { await createEOSToken(); }); - function assertCorrectAccount(account) { + function assertCorrectAccount (account) { assert(account.name == ACCOUNT_NAME, 'Incorrect name'); assert(account.privateKey == ACCOUNT_PRIVATE_KEY, 'Incorrect private key'); assert(account.publicKey == ACCOUNT_PUBLIC_KEY, 'Incorrect public key'); diff --git a/tests/contract-tests.js b/tests/contract-tests.js index 1f71d93..15d9c37 100644 --- a/tests/contract-tests.js +++ b/tests/contract-tests.js @@ -24,7 +24,7 @@ describe("Contract", function () { /* Deploy eos token contract on local nodoes in order to send eos and buy ram / bandwidth */ - async function createToken() { + async function createToken () { // Deploy a token contract try { const tokenAccount = await eoslime.Account.createRandom(); @@ -35,7 +35,7 @@ describe("Contract", function () { } } - async function createFaucet() { + async function createFaucet () { // Deploy a faucet contract try { faucetAccount = await eoslime.Account.createRandom(); @@ -101,6 +101,56 @@ describe("Contract", function () { }); }); + describe("Deployment", function () { + it("Should deploy a contract from file on a random account", async () => { + const faucetContract = await eoslime.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH); + const deployedABI = await eoslime.Provider.getABI(faucetContract.name); + + assert(deployedABI); + }); + + it("Should deploy a contract from file on provided account", async () => { + const contractAccount = await eoslime.Account.createRandom(); + + const initialABI = await eoslime.Provider.getABI(contractAccount.name); + await eoslime.Contract.deployOnAccount(FAUCET_WASM_PATH, FAUCET_ABI_PATH, contractAccount); + const deployedABI = await eoslime.Provider.getABI(contractAccount.name); + + assert(initialABI == undefined); + assert(deployedABI); + }); + + it("Should deploy a contract from raw data on a random account", async () => { + const contractA = await eoslime.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH); + const contractA_ABI = await eoslime.Provider.getABI(contractA.name); + const contractA_WASM = await eoslime.Provider.getRawWASM(contractA.name); + + const contractB = await eoslime.Contract.deployRaw(contractA_WASM, contractA_ABI); + const contractB_ABI = await eoslime.Provider.getABI(contractB.name); + const contractB_WASM = await eoslime.Provider.getRawWASM(contractB.name); + + assert(contractA_WASM == contractB_WASM); + assert(JSON.stringify(contractA_ABI) == JSON.stringify(contractB_ABI)); + }); + + it("Should deploy a contract from raw data on provided account", async () => { + const contractA = await eoslime.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH); + const contractA_ABI = await eoslime.Provider.getABI(contractA.name); + const contractA_WASM = await eoslime.Provider.getRawWASM(contractA.name); + + const contractB_Account = await eoslime.Account.createRandom(); + const initialABI = await eoslime.Provider.getABI(contractB_Account.name); + + const contractB = await eoslime.Contract.deployRawOnAccount(contractA_WASM, contractA_ABI, contractB_Account); + const contractB_ABI = await eoslime.Provider.getABI(contractB.name); + const contractB_WASM = await eoslime.Provider.getRawWASM(contractB.name); + + assert(initialABI == undefined); + assert(contractA_WASM == contractB_WASM); + assert(JSON.stringify(contractA_ABI) == JSON.stringify(contractB_ABI)); + }); + }); + describe("Blockchain methods", function () { it("Should execute a blockchain method from the provided executor", async () => { const faucetContract = eoslime.Contract.fromFile(FAUCET_ABI_PATH, faucetAccount.name, faucetAccount); @@ -290,4 +340,13 @@ describe("Contract", function () { } }); }); + + describe("Retrieve raw WASM", function () { + it("Should retrieve contract raw WASM", async () => { + const faucetContract = eoslime.Contract.fromFile(FAUCET_ABI_PATH, faucetAccount.name, faucetAccount); + + const contractWASM = await faucetContract.getRawWASM(); + assert(contractWASM.endsWith('='), 'Not correctly encoded WASM'); + }); + }); }); diff --git a/tests/providers-tests.js b/tests/providers-tests.js index 3714098..dc6641e 100644 --- a/tests/providers-tests.js +++ b/tests/providers-tests.js @@ -327,4 +327,38 @@ describe('Providers', function () { } }); }); + + describe('Retrieve contract ABI', function () { + it('Should retrieve contract ABI', async () => { + const eoslimeInstance = eoslime.init(); + const Provider = eoslimeInstance.Provider; + + const faucetContract = await eoslimeInstance.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH); + + const contractABI = await Provider.getABI(faucetContract.name); + + assert(faucetContract.abi.version == contractABI.version); + assert(JSON.stringify(faucetContract.abi.types) == JSON.stringify(contractABI.types)); + assert(JSON.stringify(faucetContract.abi.structs) == JSON.stringify(contractABI.structs)); + assert(JSON.stringify(faucetContract.abi.actions) == JSON.stringify(contractABI.actions)); + + assert(faucetContract.abi.tables[0].name == contractABI.tables[0].name); + assert(faucetContract.abi.tables[0].type == contractABI.tables[0].type); + assert(faucetContract.abi.tables[0].index_type == contractABI.tables[0].index_type); + assert(JSON.stringify(faucetContract.abi.tables[0].key_names) == JSON.stringify(contractABI.tables[0].key_names)); + assert(JSON.stringify(faucetContract.abi.tables[0].key_types) == JSON.stringify(contractABI.tables[0].key_types)); + }); + }); + + describe('Retrieve contract raw WASM', function () { + it('Should retrieve contract raw WASM', async () => { + const eoslimeInstance = eoslime.init(); + const Provider = eoslimeInstance.Provider; + + const faucetContract = await eoslimeInstance.Contract.deploy(FAUCET_WASM_PATH, FAUCET_ABI_PATH); + + const contractWASM = await Provider.getRawWASM(faucetContract.name); + assert(contractWASM.endsWith('='), 'Not correctly encoded WASM'); + }); + }); }); From e1de6f5a797858a1276804fbff10489c773e750a Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Mon, 11 May 2020 10:22:02 +0300 Subject: [PATCH 14/17] Updated cli commands --- cli-commands/compile/index.js | 3 +- cli-commands/deploy/index.js | 3 +- cli-commands/helpers/async-soft-exec.js | 4 +- cli-commands/helpers/file-system-util.js | 41 +++++++++++ cli-commands/init/index.js | 5 -- .../nodeos/subcommands/show/definition.js | 2 +- .../show/subcommands/accounts/accounts.json | 2 +- .../show/subcommands/accounts/definition.js | 2 +- .../show/subcommands/accounts/index.js | 26 ++++--- .../show/subcommands/accounts/messages.js | 4 +- .../show/subcommands/logs/definition.js | 7 +- .../show/subcommands/logs/index.js | 41 ++++++----- .../show/subcommands/logs/messages.js | 2 +- .../subcommands/logs/options/lines-option.js | 4 +- .../subcommands/logs/options/path-option.js | 26 ------- .../nodeos/subcommands/start/definition.js | 2 +- .../nodeos/subcommands/start/index.js | 70 +++++++++--------- .../nodeos/subcommands/start/messages.js | 4 +- .../subcommands/start/options/path-option.js | 9 ++- .../nodeos/subcommands/start/settings.js | 3 - .../nodeos/subcommands/start/template.js | 3 + .../nodeos/subcommands/stop/definition.js | 9 +-- cli-commands/nodeos/subcommands/stop/index.js | 71 ++++++++----------- .../nodeos/subcommands/stop/messages.js | 14 +--- .../subcommands/stop/options/path-option.js | 22 ------ .../subcommands/stop/options/pid-option.js | 19 ----- cli-commands/shape/index.js | 4 +- cli-commands/test/index.js | 4 +- package.json | 1 - 29 files changed, 176 insertions(+), 231 deletions(-) delete mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js delete mode 100644 cli-commands/nodeos/subcommands/start/settings.js create mode 100644 cli-commands/nodeos/subcommands/start/template.js delete mode 100644 cli-commands/nodeos/subcommands/stop/options/path-option.js delete mode 100644 cli-commands/nodeos/subcommands/stop/options/pid-option.js diff --git a/cli-commands/compile/index.js b/cli-commands/compile/index.js index 6b6e9a1..ece8c91 100644 --- a/cli-commands/compile/index.js +++ b/cli-commands/compile/index.js @@ -32,7 +32,6 @@ class CompileCommand extends Command { asyncSoftExec.onSuccess(() => commandMessages.SuccessfulCompilationOfContract(contractPath.fileName)); await asyncSoftExec.exec(); - return true; } } else { commandMessages.ContractNotExisting(); @@ -40,7 +39,7 @@ class CompileCommand extends Command { } catch (error) { commandMessages.UnsuccessfulCompilation(error); } - return false; + return true; } } diff --git a/cli-commands/deploy/index.js b/cli-commands/deploy/index.js index 05da5af..0527da7 100644 --- a/cli-commands/deploy/index.js +++ b/cli-commands/deploy/index.js @@ -15,11 +15,10 @@ class DeployCommand extends Command { commandMessages.StartDeployment(); const optionsResults = await super.processOptions(args); await runDeploymentScripts(optionsResults.path, optionsResults.network, optionsResults.deployer); - return true; } catch (error) { commandMessages.UnsuccessfulDeployment(error); } - return false; + return true; } } diff --git a/cli-commands/helpers/async-soft-exec.js b/cli-commands/helpers/async-soft-exec.js index 229c28f..d2af0d3 100644 --- a/cli-commands/helpers/async-soft-exec.js +++ b/cli-commands/helpers/async-soft-exec.js @@ -15,13 +15,13 @@ class AsyncSoftExec { async exec() { return new Promise((resolve, reject) => { - exec(this.command, (error) => { + exec(this.command, (error, stdout) => { if (error) { this.errorCallback(error); return void resolve(true); } - this.successCallback(); + this.successCallback(stdout); return void resolve(true); }); }); diff --git a/cli-commands/helpers/file-system-util.js b/cli-commands/helpers/file-system-util.js index 3e2a8da..6bcc100 100644 --- a/cli-commands/helpers/file-system-util.js +++ b/cli-commands/helpers/file-system-util.js @@ -56,6 +56,31 @@ const fileSystemUtils = { }); }); }, + recursivelyDeleteDir: async function (dirPath, deleteSelf) { + return new Promise(async (resolve, reject) => { + fs.readdir(dirPath, async function (err, filenames) { + if (err) { + return void reject(err.message); + } + + for (let i = 0; i < filenames.length; i++) { + const filename = filenames[i]; + + if (fileSystemUtils.isDir(path.join(dirPath, filename))) { + await fileSystemUtils.recursivelyDeleteDir(path.join(dirPath, filename), true); + } else { + fileSystemUtils.rmFile(path.join(dirPath, filename)); + } + } + + if (deleteSelf) { + fileSystemUtils.rmDir(dirPath); + } + + resolve(); + }); + }); + }, forEachFileInDir: (dirPath, actionCallback) => { fs.readdir(dirPath, function (err, filenames) { if (err) { @@ -69,6 +94,22 @@ const fileSystemUtils = { }, exists: (path) => { return fs.existsSync(path); + }, + readFile: (filePath) => { + return fs.readFileSync(filePath); + }, + writeFile: (filePath, fileContent) => { + try { + fs.writeFileSync(filePath, fileContent); + } catch (err) { + throw new Error(`Storing content failed: ${err.message}`) + } + }, + rmFile: (filePath) => { + fs.unlinkSync(filePath); + }, + rmDir: (dirPath) => { + fs.rmdirSync(dirPath); } } diff --git a/cli-commands/init/index.js b/cli-commands/init/index.js index 9f449c9..0fccf0d 100644 --- a/cli-commands/init/index.js +++ b/cli-commands/init/index.js @@ -1,5 +1,4 @@ const AsyncSoftExec = require('./../helpers/async-soft-exec'); - const Command = require('./../command'); const initDirectories = require('./directories'); @@ -18,10 +17,6 @@ class InitCommand extends Command { super(initCommandDefinition); } - defineOptions(yargs) { - super.defineOptions(yargs, initCommandDefinition.options); - } - async execute(args) { try { commandMessages.Installation(); diff --git a/cli-commands/nodeos/subcommands/show/definition.js b/cli-commands/nodeos/subcommands/show/definition.js index 346c468..fb18a40 100644 --- a/cli-commands/nodeos/subcommands/show/definition.js +++ b/cli-commands/nodeos/subcommands/show/definition.js @@ -1,5 +1,5 @@ module.exports = { "template": "show", - "description": "Show local node details", + "description": "Show local nodeos logs", "options": [] } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json index df12827..a5df1eb 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json @@ -5,7 +5,7 @@ "privateKey":"5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" }, { - "name": "eoslimekevid", + "name": "eoslimekevin", "publicKey":"EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", "privateKey":"5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" }, diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js index ecdfac9..5f08630 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js @@ -1,5 +1,5 @@ module.exports = { "template": "accounts", - "description": "Lists all predefined accounts", + "description": "Lists all preloaded accounts", "options": [] } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js index 5166510..fda8cf8 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js @@ -1,8 +1,9 @@ -const Command = require('../../../../../command'); const AccountsTable = require('./accounts-table'); +const Command = require('../../../../../command'); -const commandMessages = require('./messages'); const accounts = require('./accounts.json'); + +const commandMessages = require('./messages'); const accountsCommandDefinition = require('./definition'); // eoslime nodeos show accounts @@ -14,22 +15,19 @@ class AccountsCommand extends Command { async execute(args) { try { - commandMessages.PredefinedAccounts(); - showAccounts(); - return true; + commandMessages.PreloadedAccounts(); + + let accountsTable = new AccountsTable(); + for (let i = 0; i < accounts.length; i++) { + accountsTable.addRow([accounts[i].name, accounts[i].publicKey, accounts[i].privateKey]); + } + accountsTable.draw(); } catch (error) { commandMessages.UnsuccessfulShowing(error); } - return false; + + return true; } } -const showAccounts = function () { - let accountsTable = new AccountsTable(); - accounts.forEach(account => { - accountsTable.addRow([account.name, account.publicKey, account.privateKey]); - }); - accountsTable.draw(); -} - module.exports = AccountsCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js index 1dbbf49..eb325c6 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js @@ -1,9 +1,9 @@ const chalk = require('chalk'); module.exports = { - 'PredefinedAccounts': () => { console.log(chalk.magentaBright('===== Predefined accounts =====')); }, + 'PreloadedAccounts': () => { console.log(chalk.magentaBright('===== Preloaded accounts =====')); }, 'UnsuccessfulShowing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful showing accounts =====`)); + console.log(chalk.redBright(`===== Accounts has not been shown =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js index 1f552ae..4a21b4d 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js @@ -1,8 +1,7 @@ -const pathOption = require('./options/path-option'); const linesOption = require('./options/lines-option'); module.exports = { - "template": "logs [path] [lines]", - "description": "Lists last N lines from node logs", - "options": [pathOption, linesOption] + "template": "logs [lines]", + "description": "Show last N lines from local nodeos logs", + "options": [linesOption] } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js index c6e64cf..2a3d80c 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js @@ -1,36 +1,43 @@ -const exec = require('child_process').exec; +const path = require('path'); + const Command = require('../../../../../command'); +const AsyncSoftExec = require('../../../../../helpers/async-soft-exec'); const commandMessages = require('./messages'); -const showCommandDefinition = require('./definition'); +const logsCommandDefinition = require('./definition'); +const fileSystemUtil = require('../../../../../helpers/file-system-util'); -// eoslime nodeos show logs --path --lines +// eoslime nodeos show logs --lines class LogsCommand extends Command { constructor() { - super(showCommandDefinition); + super(logsCommandDefinition); } async execute(args) { try { const optionsResults = await super.processOptions(args); - await showLogs(optionsResults); - return true; + + const configJsonFile = path.join(__dirname, '../../../../config.json'); + + if (fileSystemUtil.exists(configJsonFile)) { + const nodeosDir = require(configJsonFile).nodeos_dir; + const nodeosLogFile = path.join(nodeosDir, 'nodeos.log'); + + if (fileSystemUtil.exists(nodeosLogFile)) { + const asyncSoftExec = new AsyncSoftExec(`tail -n ${optionsResults.lines} ${nodeosLogFile}`); + asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulShowing(error); }); + asyncSoftExec.onSuccess((logs) => { commandMessages.NodeosLogs(logs); }); + + await asyncSoftExec.exec(); + } + } } catch (error) { commandMessages.UnsuccessfulShowing(error); } - return false; + + return true; } } -const showLogs = async function (result) { - exec(`tail -n ${result.lines} ${result.path}`, (error, stdout, stderr) => { - if (error) { - throw new Error(`Could not show logs, due to '${error}'`); - } - - commandMessages.NodeosLogs(stdout); - }); -} - module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js index 67059ef..0f5b8a9 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js @@ -6,7 +6,7 @@ module.exports = { console.log(logs); }, 'UnsuccessfulShowing': (error) => { - console.log(chalk.redBright(`===== Unsuccessful showing logs =====`)); + console.log(chalk.redBright(`===== Logs has not been shown =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js index cdef565..3596acb 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js @@ -12,8 +12,8 @@ class LinesOption extends Option { ); } - async process(optionValue) { - return optionValue ? optionValue : 10; + process(optionValue) { + return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js deleted file mode 100644 index 7b933b8..0000000 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/path-option.js +++ /dev/null @@ -1,26 +0,0 @@ -const Option = require('../../../../../../option'); -const fileSystemUtil = require('../../../..../../../../../helpers/file-system-util'); - -class PathOption extends Option { - constructor() { - super( - 'path', - { - "describe": "Path to nodeos folder", - "type": "string", - "default": "." - } - ); - } - - async process(optionValue) { - const filePath = `${optionValue}/nodeos.log`; - - fileSystemUtil.isDir(optionValue); - fileSystemUtil.isFile(filePath); - - return filePath; - } -} - -module.exports = new PathOption(); diff --git a/cli-commands/nodeos/subcommands/start/definition.js b/cli-commands/nodeos/subcommands/start/definition.js index dfbe0ef..dd7d192 100644 --- a/cli-commands/nodeos/subcommands/start/definition.js +++ b/cli-commands/nodeos/subcommands/start/definition.js @@ -2,6 +2,6 @@ const pathOption = require('./options/path-option'); module.exports = { "template": "start [path]", - "description": "Start a local node", + "description": "Start local nodeos", "options": [pathOption] } diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 107d1e6..4bc31c0 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -1,11 +1,15 @@ -const axios = require('axios'); +const path = require('path'); const Command = require('../../../command'); const AsyncSoftExec = require('../../../helpers/async-soft-exec'); +const template = require('./template'); + const commandMessages = require('./messages'); -const commandExpression = require('./settings').command; const startCommandDefinition = require('./definition'); +const fileSystemUtil = require('../../../helpers/file-system-util'); + +const DEFAULT_NODEOS_DIR = '/tmp/nodeos'; // eoslime nodeos start --path @@ -15,48 +19,50 @@ class StartCommand extends Command { } async execute(args) { + let nodeosDir; + try { commandMessages.StartingNodeos(); + const optionsResults = await super.processOptions(args); - await startNodeos(optionsResults.path); - return true; + + const configJsonFile = path.join(__dirname, '../../config.json'); + + if (fileSystemUtil.exists(configJsonFile)) { + nodeosDir = require(configJsonFile).nodeos_dir; + } + else { + nodeosDir = optionsResults.path ? optionsResults.path : DEFAULT_NODEOS_DIR; + + createNodeosDir(nodeosDir); + storeNodeosConfig({ nodeos_dir: nodeosDir }); + } + + if (fileSystemUtil.exists(path.join(nodeosDir, 'eosd.pid'))) { + commandMessages.NodeosAlreadyRunning(); + return true; + } + + const asyncSoftExec = new AsyncSoftExec(template(nodeosDir)); + asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); + asyncSoftExec.onSuccess(() => { commandMessages.SuccessfullyStarted(); }); + + await asyncSoftExec.exec(); } catch (error) { commandMessages.UnsuccessfulStarting(error); } - return false; - } -} -const startNodeos = async function(folderPath) { - const nodeosRunning = await isNodeosRunning(); - - if (nodeosRunning) { - commandMessages.NodeosAlreadyRunning(); - } else { - await runNodeos(folderPath); + return true; } } -const isNodeosRunning = async function () { - try { - let result = await axios.get('http://localhost:8888/v1/chain/get_info'); - - if (result.status == 200) { - return true; - } - } catch (error) {} - - return false; +const createNodeosDir = function (dirPath) { + fileSystemUtil.createDir(dirPath); } -const runNodeos = async function (folderPath) { - const expression = commandExpression.replace(new RegExp('{path}', 'g'), folderPath); - - const asyncSoftExec = new AsyncSoftExec(expression); - asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); - asyncSoftExec.onSuccess(() => { commandMessages.SuccessfulStarting(); }); - - await asyncSoftExec.exec(); +const storeNodeosConfig = function (config) { + const configContent = JSON.stringify(config); + fileSystemUtil.writeFile(CONFIG_FILE, configContent); } module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/messages.js b/cli-commands/nodeos/subcommands/start/messages.js index 743587d..edce524 100644 --- a/cli-commands/nodeos/subcommands/start/messages.js +++ b/cli-commands/nodeos/subcommands/start/messages.js @@ -3,9 +3,9 @@ const chalk = require('chalk'); module.exports = { 'StartingNodeos': () => { console.log(chalk.magentaBright('===== Starting nodeos ... =====')); }, 'NodeosAlreadyRunning': () => { console.log(chalk.redBright(`===== Nodeos is already running =====`)); }, - 'SuccessfulStarting': () => { console.log(chalk.greenBright(`===== Successfully started =====`)); }, + 'SuccessfullyStarted': () => { console.log(chalk.greenBright(`===== Successfully started =====`)); }, 'UnsuccessfulStarting': (error) => { - console.log(chalk.redBright(`===== Unsuccessful starting =====`)); + console.log(chalk.redBright(`===== Nodeos has not been started =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/nodeos/subcommands/start/options/path-option.js index 26c1f82..6eb0b5a 100644 --- a/cli-commands/nodeos/subcommands/start/options/path-option.js +++ b/cli-commands/nodeos/subcommands/start/options/path-option.js @@ -1,20 +1,19 @@ -const Option = require('../../../../option'); const fileSystemUtil = require('../../../../helpers/file-system-util'); +const Option = require('../../../../option'); + class PathOption extends Option { constructor() { super( 'path', { - "describe": "Path to nodeos folder", - "type": "string", - "default": "." + "describe": "The path nodeos data will be stored", + "type": "string" } ); } async process(optionValue) { - fileSystemUtil.isDir(optionValue); return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/start/settings.js b/cli-commands/nodeos/subcommands/start/settings.js deleted file mode 100644 index 9cb7412..0000000 --- a/cli-commands/nodeos/subcommands/start/settings.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - "command": `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d {path}/data --config-dir {path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> {path}/nodeos.log 2>&1 &` -} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/start/template.js b/cli-commands/nodeos/subcommands/start/template.js new file mode 100644 index 0000000..f3a9522 --- /dev/null +++ b/cli-commands/nodeos/subcommands/start/template.js @@ -0,0 +1,3 @@ +module.exports = (path) => { + return `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d ${path}/data --config-dir ${path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> ${path}/nodeos.log 2>&1 & echo $! > ${path}/eosd.pid` +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/definition.js b/cli-commands/nodeos/subcommands/stop/definition.js index a5565b5..190703a 100644 --- a/cli-commands/nodeos/subcommands/stop/definition.js +++ b/cli-commands/nodeos/subcommands/stop/definition.js @@ -1,8 +1,5 @@ -const pathOption = require('./options/path-option'); -const pidOption = require('./options/pid-option'); - module.exports = { - "template": "stop [path] [pid]", - "description": "Stop a local node", - "options": [pathOption, pidOption] + "template": "stop", + "description": "Stop local nodeos", + "options": [] } diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index 8c3ebb2..b003969 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -1,12 +1,13 @@ -const axios = require('axios'); +const path = require('path'); const Command = require('../../../command'); const AsyncSoftExec = require('../../../helpers/async-soft-exec'); const commandMessages = require('./messages'); const stopCommandDefinition = require('./definition'); +const fileSystemUtil = require('../../../helpers/file-system-util'); -// eoslime nodeos stop --path --pid +// eoslime nodeos stop class StopCommand extends Command { constructor() { @@ -14,54 +15,40 @@ class StopCommand extends Command { } async execute(args) { + let nodeosDir; + let nodeosPid; + try { commandMessages.StoppingNodeos(); - const optionsResults = await super.processOptions(args); - await stopNodeos(optionsResults); - return true; - } catch (error) { - commandMessages.UnsuccessfulStopping(error); - } - return false; - } -} - -const stopNodeos = async function (result) { - const nodeosRunning = await isNodeosRunning(); - - if (!nodeosRunning) { - commandMessages.NoRunningNodeos(); - } else { - await stopAndClean(result); - } -} -const isNodeosRunning = async function () { - try { - let result = await axios.get('http://localhost:8888/v1/chain/get_info'); + const configJsonFile = path.join(__dirname, '../../config.json'); + + if (fileSystemUtil.exists(configJsonFile)) { + nodeosDir = require(configJsonFile).nodeos_dir; + const nodeosPidFile = path.join(nodeosDir, 'eosd.pid'); - if (result.status == 200) { - return true; - } - } catch (error) {} - - return false; -} + if (fileSystemUtil.exists(nodeosPidFile)) { + nodeosPid = fileSystemUtil.readFile(nodeosPidFile); + } + } -const stopAndClean = async function (result) { - const killCommand = result.pid ? `kill ${result.pid}` : `pkill nodeos`; + if (nodeosPid) { + await fileSystemUtil.recursivelyDeleteDir(nodeosDir, false); - const asyncKillExec = new AsyncSoftExec(killCommand); - asyncKillExec.onError((error) => commandMessages.UnsuccessfulProcessTermination(error)); - asyncKillExec.onSuccess(() => commandMessages.SuccessfulProcessTermination()); - await asyncKillExec.exec(); + const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); + asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); + asyncKillExec.onSuccess(() => commandMessages.SuccessfullyStopped()); - const asyncCleanExec = new AsyncSoftExec(`rm -rf ${result.path}/*`); - asyncCleanExec.onError((error) => commandMessages.UnsuccessfulCleanUp(error)); - asyncCleanExec.onSuccess(() => commandMessages.SuccessfulCleanUp()); - await asyncCleanExec.exec(); + await asyncKillExec.exec(); + } else { + commandMessages.NoRunningNodeos(); + } + } catch (error) { + commandMessages.UnsuccessfulStopping(error); + } - commandMessages.SuccessfulStopping(); + return true; + } } module.exports = StopCommand; diff --git a/cli-commands/nodeos/subcommands/stop/messages.js b/cli-commands/nodeos/subcommands/stop/messages.js index d6c7538..718de12 100644 --- a/cli-commands/nodeos/subcommands/stop/messages.js +++ b/cli-commands/nodeos/subcommands/stop/messages.js @@ -3,19 +3,9 @@ const chalk = require('chalk'); module.exports = { 'StoppingNodeos': () => { console.log(chalk.magentaBright('===== Stopping nodeos ... =====')); }, 'NoRunningNodeos': () => { console.log(chalk.redBright('===== There is no running nodeos ... =====')); }, - 'SuccessfulProcessTermination': () => { console.log(chalk.blueBright('===== Instance terminated =====')); }, - 'UnsuccessfulProcessTermination': (error) => { - console.log(chalk.redBright('===== Unsuccessful instance termination =====')); - console.log(error); - }, - 'SuccessfulCleanUp': () => { console.log(chalk.blueBright('===== Folder cleaned up =====')); }, - 'UnsuccessfulCleanUp': (error) => { - console.log(chalk.redBright('===== Unsuccessful folder clean up =====')); - console.log(error); - }, - 'SuccessfulStopping': () => { console.log(chalk.greenBright(`===== Successfully stopped =====`)); }, + 'SuccessfullyStopped': () => { console.log(chalk.greenBright(`===== Successfully stopped =====`)); }, 'UnsuccessfulStopping': (error) => { - console.log(chalk.redBright(`===== Unsuccessful stopping =====`)); + console.log(chalk.redBright(`===== Nodeos has not been stopped =====`)); console.log(error); } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/options/path-option.js b/cli-commands/nodeos/subcommands/stop/options/path-option.js deleted file mode 100644 index e09848d..0000000 --- a/cli-commands/nodeos/subcommands/stop/options/path-option.js +++ /dev/null @@ -1,22 +0,0 @@ -const Option = require('../../../../option'); -const fileSystemUtil = require('../../../../helpers/file-system-util'); - -class PathOption extends Option { - constructor() { - super( - 'path', - { - "describe": "Path to node folder", - "type": "string", - "default": "." - } - ); - } - - process(optionValue) { - fileSystemUtil.isDir(optionValue); - return optionValue; - } -} - -module.exports = new PathOption(); diff --git a/cli-commands/nodeos/subcommands/stop/options/pid-option.js b/cli-commands/nodeos/subcommands/stop/options/pid-option.js deleted file mode 100644 index 5cbda6a..0000000 --- a/cli-commands/nodeos/subcommands/stop/options/pid-option.js +++ /dev/null @@ -1,19 +0,0 @@ -const Option = require('../../../../option'); - -class PIDOption extends Option { - constructor() { - super( - 'pid', - { - "describe": "Process ID of running nodeos", - "type": "number" - } - ); - } - - process(optionValue) { - return optionValue; - } -} - -module.exports = new PIDOption(); diff --git a/cli-commands/shape/index.js b/cli-commands/shape/index.js index f0e8f03..568d161 100644 --- a/cli-commands/shape/index.js +++ b/cli-commands/shape/index.js @@ -24,13 +24,11 @@ class ShapeCommand extends Command { await git.clone(optionsResults.framework); commandMessages.SuccessfulShaping(); - - return true; } catch (error) { commandMessages.UnsuccessfulShaping(error); } - return false; + return true; } } diff --git a/cli-commands/test/index.js b/cli-commands/test/index.js index 3c01b44..111cac6 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/test/index.js @@ -25,13 +25,11 @@ class TestCommand extends Command { args.testFramework.setDescribeArgs(args.eoslime); args.testFramework.runTests(); - - return true; } catch (error) { console.log(error); } - return false; + return true; } } diff --git a/package.json b/package.json index eb08d05..a925aa7 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "author": "Lyubomir Kiprov (Limechain)", "license": "MIT", "dependencies": { - "axios": "0.19.2", "chalk": "2.4.2", "cli-table": "0.3.1", "crypto-js": "3.1.9-1", From 7de1dd63a502c7a64ef343fe34e2ec9e07a245f7 Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Tue, 12 May 2020 09:34:32 +0300 Subject: [PATCH 15/17] Optimizations in nodeos command --- cli-commands/helpers/file-system-util.js | 10 ++--- .../subcommands/accounts/accounts-table.js | 29 ++----------- .../nodeos/subcommands/start/index.js | 22 ++++++---- .../subcommands/start/options/path-option.js | 4 +- cli-commands/nodeos/subcommands/stop/index.js | 27 ++++++------ cli-commands/table.js | 41 +++++++++++++++++++ .../resource-usage-option/report-table.js | 27 ++---------- 7 files changed, 81 insertions(+), 79 deletions(-) create mode 100644 cli-commands/table.js diff --git a/cli-commands/helpers/file-system-util.js b/cli-commands/helpers/file-system-util.js index 6bcc100..867aad3 100644 --- a/cli-commands/helpers/file-system-util.js +++ b/cli-commands/helpers/file-system-util.js @@ -1,5 +1,5 @@ const fs = require('fs'); - +const path = require('path'); const fileSystemUtils = { createDir: (dirName) => { @@ -56,7 +56,7 @@ const fileSystemUtils = { }); }); }, - recursivelyDeleteDir: async function (dirPath, deleteSelf) { + recursivelyDeleteDir: async function (dirPath) { return new Promise(async (resolve, reject) => { fs.readdir(dirPath, async function (err, filenames) { if (err) { @@ -67,15 +67,13 @@ const fileSystemUtils = { const filename = filenames[i]; if (fileSystemUtils.isDir(path.join(dirPath, filename))) { - await fileSystemUtils.recursivelyDeleteDir(path.join(dirPath, filename), true); + await fileSystemUtils.recursivelyDeleteDir(path.join(dirPath, filename)); } else { fileSystemUtils.rmFile(path.join(dirPath, filename)); } } - if (deleteSelf) { - fileSystemUtils.rmDir(dirPath); - } + fileSystemUtils.rmDir(dirPath); resolve(); }); diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js index 3679d66..e5fffde 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js +++ b/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js @@ -1,34 +1,13 @@ -const chalk = require('chalk').default; -const CLITable = require('cli-table'); +const Table = require('../../../../../table'); const TABLE_HEAD = { head: ['Account', 'Public Key', 'Private Key'] } -class ReportTable { +class AccountsTable extends Table { constructor() { - this.table = new CLITable(TABLE_HEAD); - } - - addRow(rowData) { - this.table.push(rowData); - } - - addSection(sectionName, sectionRows) { - this.table.push({ [chalk.cyanBright(sectionName)]: ['', '', ''] }); - - if (sectionRows) { - for (let i = 0; i < sectionRows.length; i++) { - const sectionRow = sectionRows[i]; - sectionRow.unshift(''); - this.addRow(sectionRow); - } - } - } - - draw() { - console.log(this.table.toString()); + super(TABLE_HEAD); } } -module.exports = ReportTable; +module.exports = AccountsTable; diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 4bc31c0..594b74e 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -9,7 +9,8 @@ const commandMessages = require('./messages'); const startCommandDefinition = require('./definition'); const fileSystemUtil = require('../../../helpers/file-system-util'); -const DEFAULT_NODEOS_DIR = '/tmp/nodeos'; +const defaultNodeosDir = '/tmp/nodeos'; +const configJsonFile = path.join(__dirname, '../../config.json'); // eoslime nodeos start --path @@ -28,16 +29,23 @@ class StartCommand extends Command { const configJsonFile = path.join(__dirname, '../../config.json'); - if (fileSystemUtil.exists(configJsonFile)) { - nodeosDir = require(configJsonFile).nodeos_dir; + if (!fileSystemUtil.exists(configJsonFile)) { + nodeosDir = optionsResults.path ? optionsResults.path : defaultNodeosDir; } else { - nodeosDir = optionsResults.path ? optionsResults.path : DEFAULT_NODEOS_DIR; + nodeosDir = require(configJsonFile).nodeos_dir; - createNodeosDir(nodeosDir); - storeNodeosConfig({ nodeos_dir: nodeosDir }); + if (fileSystemUtil.exists(path.join(nodeosDir, 'eosd.pid'))) { + commandMessages.NodeosAlreadyRunning(); + return true; + } + + nodeosDir = optionsResults.path ? optionsResults.path : nodeosDir; } + createNodeosDir(nodeosDir); + storeNodeosConfig({ nodeos_dir: nodeosDir }); + if (fileSystemUtil.exists(path.join(nodeosDir, 'eosd.pid'))) { commandMessages.NodeosAlreadyRunning(); return true; @@ -62,7 +70,7 @@ const createNodeosDir = function (dirPath) { const storeNodeosConfig = function (config) { const configContent = JSON.stringify(config); - fileSystemUtil.writeFile(CONFIG_FILE, configContent); + fileSystemUtil.writeFile(configJsonFile, configContent); } module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/nodeos/subcommands/start/options/path-option.js index 6eb0b5a..05c7b18 100644 --- a/cli-commands/nodeos/subcommands/start/options/path-option.js +++ b/cli-commands/nodeos/subcommands/start/options/path-option.js @@ -1,4 +1,4 @@ -const fileSystemUtil = require('../../../../helpers/file-system-util'); +const path = require('path'); const Option = require('../../../../option'); @@ -14,7 +14,7 @@ class PathOption extends Option { } async process(optionValue) { - return optionValue; + return path.resolve(optionValue); } } diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index b003969..01b6983 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -15,34 +15,31 @@ class StopCommand extends Command { } async execute(args) { - let nodeosDir; - let nodeosPid; - try { commandMessages.StoppingNodeos(); const configJsonFile = path.join(__dirname, '../../config.json'); if (fileSystemUtil.exists(configJsonFile)) { - nodeosDir = require(configJsonFile).nodeos_dir; + const nodeosDir = require(configJsonFile).nodeos_dir; const nodeosPidFile = path.join(nodeosDir, 'eosd.pid'); if (fileSystemUtil.exists(nodeosPidFile)) { - nodeosPid = fileSystemUtil.readFile(nodeosPidFile); - } - } + const nodeosPid = fileSystemUtil.readFile(nodeosPidFile); - if (nodeosPid) { - await fileSystemUtil.recursivelyDeleteDir(nodeosDir, false); + fileSystemUtil.rmFile(configJsonFile); + await fileSystemUtil.recursivelyDeleteDir(nodeosDir); - const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); - asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); - asyncKillExec.onSuccess(() => commandMessages.SuccessfullyStopped()); + const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); + asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); + asyncKillExec.onSuccess(() => commandMessages.SuccessfullyStopped()); - await asyncKillExec.exec(); - } else { - commandMessages.NoRunningNodeos(); + await asyncKillExec.exec(); + return true; + } } + + commandMessages.NoRunningNodeos(); } catch (error) { commandMessages.UnsuccessfulStopping(error); } diff --git a/cli-commands/table.js b/cli-commands/table.js new file mode 100644 index 0000000..64c60ee --- /dev/null +++ b/cli-commands/table.js @@ -0,0 +1,41 @@ +const chalk = require('chalk').default; +const CLITable = require('cli-table'); + +class Table { + constructor(tableHead) { + this.table = new CLITable(tableHead); + } + + addRow(rowData) { + this.table.push(rowData); + } + + addSection(sectionName, sectionRows) { + this.table.push({ [chalk.cyanBright(sectionName)]: + addEmptyColumns(this.table.options.head.length) }); + + if (sectionRows) { + for (let i = 0; i < sectionRows.length; i++) { + const sectionRow = sectionRows[i]; + sectionRow.unshift(''); + this.addRow(sectionRow); + } + } + } + + draw() { + console.log(this.table.toString()); + } +} + +const addEmptyColumns = function (n) { + let arr = []; + + for (let i = 0; i < n - 1; i++) { + arr[i] = ''; + } + + return arr; +} + +module.exports = Table; diff --git a/cli-commands/test/options/resource-usage-option/report-table.js b/cli-commands/test/options/resource-usage-option/report-table.js index cef3e58..706dffb 100644 --- a/cli-commands/test/options/resource-usage-option/report-table.js +++ b/cli-commands/test/options/resource-usage-option/report-table.js @@ -1,33 +1,12 @@ -const chalk = require('chalk').default; -const CLITable = require('cli-table'); +const Table = require('../../../table'); const TABLE_HEAD = { head: ['', 'Contract', 'Action', 'CPU ( MIN | MAX )', 'NET ( MIN | MAX )', 'RAM ( MIN | MAX )', 'Calls'] } -class ReportTable { +class ReportTable extends Table { constructor() { - this.table = new CLITable(TABLE_HEAD); - } - - addRow(rowData) { - this.table.push(rowData); - } - - addSection(sectionName, sectionRows) { - this.table.push({ [chalk.cyanBright(sectionName)]: ['', '', '', '', '', ''] }); - - if (sectionRows) { - for (let i = 0; i < sectionRows.length; i++) { - const sectionRow = sectionRows[i]; - sectionRow.unshift(''); - this.addRow(sectionRow); - } - } - } - - draw() { - console.log(this.table.toString()); + super(TABLE_HEAD); } } From de5b71240a602e3e4826412ebb30d5bc55d2005a Mon Sep 17 00:00:00 2001 From: vladimirhristov Date: Fri, 15 May 2020 16:33:09 +0300 Subject: [PATCH 16/17] cli command updated --- cli-commands/command-definer.js | 6 +- cli-commands/command.js | 1 + .../{parent-command.js => group-command.js} | 8 +-- cli-commands/helpers/async-soft-exec.js | 3 + cli-commands/nodeos/index.js | 12 ++-- cli-commands/nodeos/nodeos_data/config.json | 3 + .../accounts/accounts-table.js | 2 +- .../subcommands => }/accounts/accounts.json | 0 .../subcommands => }/accounts/definition.js | 0 .../{show/subcommands => }/accounts/index.js | 2 +- .../subcommands => }/accounts/messages.js | 0 .../{show/subcommands => }/logs/definition.js | 0 cli-commands/nodeos/subcommands/logs/index.js | 38 +++++++++++++ .../{show/subcommands => }/logs/messages.js | 0 .../logs/options/lines-option.js | 2 +- .../nodeos/subcommands/show/definition.js | 5 -- cli-commands/nodeos/subcommands/show/index.js | 19 ------- .../show/subcommands/logs/index.js | 43 -------------- .../nodeos/subcommands/start/index.js | 56 ++++++++----------- .../subcommands/start/options/path-option.js | 2 +- .../nodeos/subcommands/start/template.js | 6 +- cli-commands/nodeos/subcommands/stop/index.js | 35 ++++++------ cli-commands/table.js | 6 +- cli-commands/test/index.js | 3 +- cli.js | 4 +- 25 files changed, 116 insertions(+), 140 deletions(-) rename cli-commands/{parent-command.js => group-command.js} (71%) create mode 100644 cli-commands/nodeos/nodeos_data/config.json rename cli-commands/nodeos/subcommands/{show/subcommands => }/accounts/accounts-table.js (80%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/accounts/accounts.json (100%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/accounts/definition.js (100%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/accounts/index.js (94%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/accounts/messages.js (100%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/logs/definition.js (100%) create mode 100644 cli-commands/nodeos/subcommands/logs/index.js rename cli-commands/nodeos/subcommands/{show/subcommands => }/logs/messages.js (100%) rename cli-commands/nodeos/subcommands/{show/subcommands => }/logs/options/lines-option.js (87%) delete mode 100644 cli-commands/nodeos/subcommands/show/definition.js delete mode 100644 cli-commands/nodeos/subcommands/show/index.js delete mode 100644 cli-commands/nodeos/subcommands/show/subcommands/logs/index.js diff --git a/cli-commands/command-definer.js b/cli-commands/command-definer.js index 11f874e..1a69921 100644 --- a/cli-commands/command-definer.js +++ b/cli-commands/command-definer.js @@ -3,12 +3,12 @@ class CommandDefiner { this.yargs = yargs; } - define (command, ...params) { + define (command) { return { command: command.template, description: command.description, builder: this.build(command), - handler: this.handle(command, ...params) + handler: this.handle(command, command.params) } } @@ -26,7 +26,7 @@ class CommandDefiner { } } - handle (command, ...params) { + handle (command, params) { return async (args) => { const result = await command.execute(args, ...params); if (!result) { diff --git a/cli-commands/command.js b/cli-commands/command.js index fa1e38d..c756161 100644 --- a/cli-commands/command.js +++ b/cli-commands/command.js @@ -5,6 +5,7 @@ class Command { this.description = commandDefinition.description || ''; this.options = commandDefinition.options || []; this.subcommands = []; + this.params = []; } async processOptions(args) { diff --git a/cli-commands/parent-command.js b/cli-commands/group-command.js similarity index 71% rename from cli-commands/parent-command.js rename to cli-commands/group-command.js index a47bdac..639564d 100644 --- a/cli-commands/parent-command.js +++ b/cli-commands/group-command.js @@ -1,12 +1,12 @@ const Command = require('./command'); -class ParentCommand extends Command { +class GroupCommand extends Command { constructor(commandDefinition) { super(commandDefinition); } async execute (args) { - if (validate(args, this.options)) { + if (optionsProvided(args, this.options)) { await super.processOptions(args); return true; } @@ -15,7 +15,7 @@ class ParentCommand extends Command { } } -const validate = function (args, commandOptions) { +const optionsProvided = function (args, commandOptions) { for (let i = 0; i < commandOptions.length; i++) { const option = commandOptions[i]; if (args[option.name]) { @@ -26,4 +26,4 @@ const validate = function (args, commandOptions) { return false; } -module.exports = ParentCommand; +module.exports = GroupCommand; diff --git a/cli-commands/helpers/async-soft-exec.js b/cli-commands/helpers/async-soft-exec.js index d2af0d3..5c4d3cc 100644 --- a/cli-commands/helpers/async-soft-exec.js +++ b/cli-commands/helpers/async-soft-exec.js @@ -3,6 +3,9 @@ const exec = require('child_process').exec; class AsyncSoftExec { constructor(command) { this.command = command; + + this.errorCallback = () => {}; + this.successCallback = () => {}; } onError(callback) { diff --git a/cli-commands/nodeos/index.js b/cli-commands/nodeos/index.js index 7101281..6a53cf7 100644 --- a/cli-commands/nodeos/index.js +++ b/cli-commands/nodeos/index.js @@ -1,20 +1,22 @@ -const ParentCommand = require('../parent-command'); +const GroupCommand = require('../group-command'); const StartCommand = require('./subcommands/start'); const StopCommand = require('./subcommands/stop'); -const ShowCommand = require('./subcommands/show'); +const LogsCommand = require('./subcommands/logs'); +const AccountsCommand = require('./subcommands/accounts'); const nodeosCommandDefinition = require('./definition'); -// eoslime nodeos +// eoslime nodeos -class NodeosCommand extends ParentCommand { +class NodeosCommand extends GroupCommand { constructor() { super(nodeosCommandDefinition); this.subcommands.push(new StartCommand()); this.subcommands.push(new StopCommand()); - this.subcommands.push(new ShowCommand()); + this.subcommands.push(new LogsCommand()); + this.subcommands.push(new AccountsCommand()); } } diff --git a/cli-commands/nodeos/nodeos_data/config.json b/cli-commands/nodeos/nodeos_data/config.json new file mode 100644 index 0000000..41a907c --- /dev/null +++ b/cli-commands/nodeos/nodeos_data/config.json @@ -0,0 +1,3 @@ +{ + "nodeosPath": "" +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js b/cli-commands/nodeos/subcommands/accounts/accounts-table.js similarity index 80% rename from cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js rename to cli-commands/nodeos/subcommands/accounts/accounts-table.js index e5fffde..731f5e9 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts-table.js +++ b/cli-commands/nodeos/subcommands/accounts/accounts-table.js @@ -1,4 +1,4 @@ -const Table = require('../../../../../table'); +const Table = require('../../../table'); const TABLE_HEAD = { head: ['Account', 'Public Key', 'Private Key'] diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json b/cli-commands/nodeos/subcommands/accounts/accounts.json similarity index 100% rename from cli-commands/nodeos/subcommands/show/subcommands/accounts/accounts.json rename to cli-commands/nodeos/subcommands/accounts/accounts.json diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js b/cli-commands/nodeos/subcommands/accounts/definition.js similarity index 100% rename from cli-commands/nodeos/subcommands/show/subcommands/accounts/definition.js rename to cli-commands/nodeos/subcommands/accounts/definition.js diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js b/cli-commands/nodeos/subcommands/accounts/index.js similarity index 94% rename from cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js rename to cli-commands/nodeos/subcommands/accounts/index.js index fda8cf8..5e473d1 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/accounts/index.js +++ b/cli-commands/nodeos/subcommands/accounts/index.js @@ -1,5 +1,5 @@ const AccountsTable = require('./accounts-table'); -const Command = require('../../../../../command'); +const Command = require('../../../command'); const accounts = require('./accounts.json'); diff --git a/cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js b/cli-commands/nodeos/subcommands/accounts/messages.js similarity index 100% rename from cli-commands/nodeos/subcommands/show/subcommands/accounts/messages.js rename to cli-commands/nodeos/subcommands/accounts/messages.js diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js b/cli-commands/nodeos/subcommands/logs/definition.js similarity index 100% rename from cli-commands/nodeos/subcommands/show/subcommands/logs/definition.js rename to cli-commands/nodeos/subcommands/logs/definition.js diff --git a/cli-commands/nodeos/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/logs/index.js new file mode 100644 index 0000000..559de45 --- /dev/null +++ b/cli-commands/nodeos/subcommands/logs/index.js @@ -0,0 +1,38 @@ +const config = require('../../nodeos_data/config.json'); + +const Command = require('../../../command'); +const AsyncSoftExec = require('../../../helpers/async-soft-exec'); + +const commandMessages = require('./messages'); +const logsCommandDefinition = require('./definition'); +const fileSystemUtil = require('../../../helpers/file-system-util'); + +// eoslime nodeos show logs --lines + +class LogsCommand extends Command { + constructor() { + super(logsCommandDefinition); + } + + async execute(args) { + try { + const optionsResults = await super.processOptions(args); + + const nodeosLogFile = config.nodeosPath + '/nodeos.log'; + + if (fileSystemUtil.exists(nodeosLogFile)) { + const asyncSoftExec = new AsyncSoftExec(`tail -n ${optionsResults.lines} ${nodeosLogFile}`); + asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulShowing(error); }); + asyncSoftExec.onSuccess((logs) => { commandMessages.NodeosLogs(logs); }); + + await asyncSoftExec.exec(); + } + } catch (error) { + commandMessages.UnsuccessfulShowing(error); + } + + return true; + } +} + +module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js b/cli-commands/nodeos/subcommands/logs/messages.js similarity index 100% rename from cli-commands/nodeos/subcommands/show/subcommands/logs/messages.js rename to cli-commands/nodeos/subcommands/logs/messages.js diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js b/cli-commands/nodeos/subcommands/logs/options/lines-option.js similarity index 87% rename from cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js rename to cli-commands/nodeos/subcommands/logs/options/lines-option.js index 3596acb..8ecf706 100644 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/options/lines-option.js +++ b/cli-commands/nodeos/subcommands/logs/options/lines-option.js @@ -1,4 +1,4 @@ -const Option = require('../../../../../../option'); +const Option = require('../../../../option'); class LinesOption extends Option { constructor() { diff --git a/cli-commands/nodeos/subcommands/show/definition.js b/cli-commands/nodeos/subcommands/show/definition.js deleted file mode 100644 index fb18a40..0000000 --- a/cli-commands/nodeos/subcommands/show/definition.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - "template": "show", - "description": "Show local nodeos logs", - "options": [] -} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/show/index.js b/cli-commands/nodeos/subcommands/show/index.js deleted file mode 100644 index 134c600..0000000 --- a/cli-commands/nodeos/subcommands/show/index.js +++ /dev/null @@ -1,19 +0,0 @@ -const ParentCommand = require('../../../parent-command'); - -const LogsCommand = require('./subcommands/logs'); -const AccountsCommand = require('./subcommands/accounts'); - -const showCommandDefinition = require('./definition'); - -// eoslime nodeos show - -class ShowCommand extends ParentCommand { - constructor() { - super(showCommandDefinition); - - this.subcommands.push(new AccountsCommand()); - this.subcommands.push(new LogsCommand()); - } -} - -module.exports = ShowCommand; diff --git a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js b/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js deleted file mode 100644 index 2a3d80c..0000000 --- a/cli-commands/nodeos/subcommands/show/subcommands/logs/index.js +++ /dev/null @@ -1,43 +0,0 @@ -const path = require('path'); - -const Command = require('../../../../../command'); -const AsyncSoftExec = require('../../../../../helpers/async-soft-exec'); - -const commandMessages = require('./messages'); -const logsCommandDefinition = require('./definition'); -const fileSystemUtil = require('../../../../../helpers/file-system-util'); - -// eoslime nodeos show logs --lines - -class LogsCommand extends Command { - constructor() { - super(logsCommandDefinition); - } - - async execute(args) { - try { - const optionsResults = await super.processOptions(args); - - const configJsonFile = path.join(__dirname, '../../../../config.json'); - - if (fileSystemUtil.exists(configJsonFile)) { - const nodeosDir = require(configJsonFile).nodeos_dir; - const nodeosLogFile = path.join(nodeosDir, 'nodeos.log'); - - if (fileSystemUtil.exists(nodeosLogFile)) { - const asyncSoftExec = new AsyncSoftExec(`tail -n ${optionsResults.lines} ${nodeosLogFile}`); - asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulShowing(error); }); - asyncSoftExec.onSuccess((logs) => { commandMessages.NodeosLogs(logs); }); - - await asyncSoftExec.exec(); - } - } - } catch (error) { - commandMessages.UnsuccessfulShowing(error); - } - - return true; - } -} - -module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js index 594b74e..040680b 100644 --- a/cli-commands/nodeos/subcommands/start/index.js +++ b/cli-commands/nodeos/subcommands/start/index.js @@ -1,4 +1,5 @@ const path = require('path'); +const config = require('../../nodeos_data/config.json'); const Command = require('../../../command'); const AsyncSoftExec = require('../../../helpers/async-soft-exec'); @@ -9,8 +10,7 @@ const commandMessages = require('./messages'); const startCommandDefinition = require('./definition'); const fileSystemUtil = require('../../../helpers/file-system-util'); -const defaultNodeosDir = '/tmp/nodeos'; -const configJsonFile = path.join(__dirname, '../../config.json'); +const defaultPath = path.join(__dirname, '../../nodeos_data'); // eoslime nodeos start --path @@ -20,42 +20,32 @@ class StartCommand extends Command { } async execute(args) { - let nodeosDir; + let nodeosPath; try { commandMessages.StartingNodeos(); const optionsResults = await super.processOptions(args); - const configJsonFile = path.join(__dirname, '../../config.json'); - - if (!fileSystemUtil.exists(configJsonFile)) { - nodeosDir = optionsResults.path ? optionsResults.path : defaultNodeosDir; + if (!config.nodeosPath) { + nodeosPath = optionsResults.path ? optionsResults.path : defaultPath; + } else { + checkForNodeos(config.NODEOS_DIR); + nodeosPath = optionsResults.path ? optionsResults.path : config.nodeosPath; } - else { - nodeosDir = require(configJsonFile).nodeos_dir; - - if (fileSystemUtil.exists(path.join(nodeosDir, 'eosd.pid'))) { - commandMessages.NodeosAlreadyRunning(); - return true; - } - - nodeosDir = optionsResults.path ? optionsResults.path : nodeosDir; - } - - createNodeosDir(nodeosDir); - storeNodeosConfig({ nodeos_dir: nodeosDir }); - if (fileSystemUtil.exists(path.join(nodeosDir, 'eosd.pid'))) { - commandMessages.NodeosAlreadyRunning(); - return true; - } + checkForNodeos(nodeosPath); + storeNodeosConfig(nodeosPath); - const asyncSoftExec = new AsyncSoftExec(template(nodeosDir)); + const asyncSoftExec = new AsyncSoftExec(template.build(nodeosPath)); asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); - asyncSoftExec.onSuccess(() => { commandMessages.SuccessfullyStarted(); }); - await asyncSoftExec.exec(); + + if (fileSystemUtil.exists(nodeosPath + '/eosd.pid')) { + commandMessages.SuccessfullyStarted(); + } else { + commandMessages.UnsuccessfulStarting('Pid file has not been created'); + } } catch (error) { commandMessages.UnsuccessfulStarting(error); } @@ -64,13 +54,15 @@ class StartCommand extends Command { } } -const createNodeosDir = function (dirPath) { - fileSystemUtil.createDir(dirPath); +const checkForNodeos = function (dirPath) { + if (fileSystemUtil.exists(dirPath + '/eosd.pid')) { + throw new Error('Nodeos is already running'); + } } -const storeNodeosConfig = function (config) { - const configContent = JSON.stringify(config); - fileSystemUtil.writeFile(configJsonFile, configContent); +const storeNodeosConfig = function (dirPath) { + const configContent = JSON.stringify({ nodeosPath: dirPath }); + fileSystemUtil.writeFile(`${defaultPath}/config.json`, configContent); } module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/nodeos/subcommands/start/options/path-option.js index 05c7b18..bd806a3 100644 --- a/cli-commands/nodeos/subcommands/start/options/path-option.js +++ b/cli-commands/nodeos/subcommands/start/options/path-option.js @@ -14,7 +14,7 @@ class PathOption extends Option { } async process(optionValue) { - return path.resolve(optionValue); + return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/start/template.js b/cli-commands/nodeos/subcommands/start/template.js index f3a9522..825d719 100644 --- a/cli-commands/nodeos/subcommands/start/template.js +++ b/cli-commands/nodeos/subcommands/start/template.js @@ -1,3 +1,5 @@ -module.exports = (path) => { - return `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d ${path}/data --config-dir ${path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> ${path}/nodeos.log 2>&1 & echo $! > ${path}/eosd.pid` +module.exports = { + build: (path) => { + return `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d ${path}/data --config-dir ${path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> ${path}/nodeos.log 2>&1 & echo $! > ${path}/eosd.pid` + } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/nodeos/subcommands/stop/index.js index 01b6983..2b05533 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/nodeos/subcommands/stop/index.js @@ -1,4 +1,4 @@ -const path = require('path'); +const config = require('../../nodeos_data/config.json'); const Command = require('../../../command'); const AsyncSoftExec = require('../../../helpers/async-soft-exec'); @@ -18,25 +18,19 @@ class StopCommand extends Command { try { commandMessages.StoppingNodeos(); - const configJsonFile = path.join(__dirname, '../../config.json'); - - if (fileSystemUtil.exists(configJsonFile)) { - const nodeosDir = require(configJsonFile).nodeos_dir; - const nodeosPidFile = path.join(nodeosDir, 'eosd.pid'); + const nodeosPath = config.nodeosPath; + const nodeosPidFile = nodeosPath + '/eosd.pid'; - if (fileSystemUtil.exists(nodeosPidFile)) { - const nodeosPid = fileSystemUtil.readFile(nodeosPidFile); + if (fileSystemUtil.exists(nodeosPidFile)) { + const nodeosPid = fileSystemUtil.readFile(nodeosPidFile); - fileSystemUtil.rmFile(configJsonFile); - await fileSystemUtil.recursivelyDeleteDir(nodeosDir); + const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); + asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); + await asyncKillExec.exec(); - const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); - asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); - asyncKillExec.onSuccess(() => commandMessages.SuccessfullyStopped()); - - await asyncKillExec.exec(); - return true; - } + await cleanNodeosData(nodeosPath); + commandMessages.SuccessfullyStopped(); + return true; } commandMessages.NoRunningNodeos(); @@ -48,4 +42,11 @@ class StopCommand extends Command { } } +const cleanNodeosData = async function (dirPath) { + fileSystemUtil.rmFile(dirPath + '/eosd.pid'); + fileSystemUtil.rmFile(dirPath + '/nodeos.log'); + await fileSystemUtil.recursivelyDeleteDir(dirPath + '/data'); + await fileSystemUtil.recursivelyDeleteDir(dirPath + '/config'); +} + module.exports = StopCommand; diff --git a/cli-commands/table.js b/cli-commands/table.js index 64c60ee..afb96e9 100644 --- a/cli-commands/table.js +++ b/cli-commands/table.js @@ -28,11 +28,11 @@ class Table { } } -const addEmptyColumns = function (n) { +const addEmptyColumns = function (numberOfColumns) { let arr = []; - for (let i = 0; i < n - 1; i++) { - arr[i] = ''; + for (let i = 0; i < numberOfColumns - 1; i++) { + arr.push(''); } return arr; diff --git a/cli-commands/test/index.js b/cli-commands/test/index.js index 111cac6..4e970ba 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/test/index.js @@ -9,8 +9,9 @@ const testUtils = require('./utils'); class TestCommand extends Command { - constructor() { + constructor(...params) { super(testCommandDefinition); + this.params = params; } async execute(args, TestFramework) { diff --git a/cli.js b/cli.js index 779aede..e419bf2 100755 --- a/cli.js +++ b/cli.js @@ -18,14 +18,14 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const commandDefiner = new CommandDefiner(menu); const initCommand = new InitCommand(); - const testCommand = new TestCommand(); + const testCommand = new TestCommand(MochaFramework); const shapeCommand = new ShapeCommand(); const nodeosCommand = new NodeosCommand(); const deployCommand = new DeployCommand(); const compileCommand = new CompileCommand(); menu.command(commandDefiner.define(initCommand)); - menu.command(commandDefiner.define(testCommand, MochaFramework)); + menu.command(commandDefiner.define(testCommand)); menu.command(commandDefiner.define(shapeCommand)); menu.command(commandDefiner.define(nodeosCommand)); menu.command(commandDefiner.define(deployCommand)); From 898d7eda77485b9d784464d5bfbbe603dd5a7931 Mon Sep 17 00:00:00 2001 From: bakasura980 Date: Thu, 21 May 2020 20:21:59 +0300 Subject: [PATCH 17/17] Refactor some code --- README.md | 42 ++++++++++ cli-commands/command-definer.js | 6 +- cli-commands/{ => commands}/command.js | 10 +-- .../{ => commands}/compile/definition.js | 2 +- cli-commands/{ => commands}/compile/index.js | 10 +-- .../{ => commands}/compile/messages.js | 0 .../compile/options/path-option.js | 6 +- .../compile/specific}/directories.json | 0 .../{ => commands}/deploy/definition.js | 4 +- cli-commands/{ => commands}/deploy/index.js | 4 +- .../{ => commands}/deploy/messages.js | 0 .../deploy/options/deployer-option.js | 4 +- .../deploy/options/network-option.js | 9 +- .../deploy/options/path-option.js | 6 +- cli-commands/{ => commands}/group-command.js | 0 cli-commands/commands/init/definition.js | 8 ++ cli-commands/{ => commands}/init/index.js | 12 +-- cli-commands/{ => commands}/init/messages.js | 0 .../contract-example/eosio.token.abi | 7 +- .../contract-example/eosio.token.cpp | 54 ++++++------ .../contract-example/eosio.token.hpp | 4 +- .../contract-example/eosio.token.wasm | Bin 0 -> 25788 bytes .../deployment-example/deployment.js | 3 +- .../with-example/tests-example/tests.js | 0 .../with-example/with-example-option.js | 6 +- .../init/specific}/default-package.json | 0 .../init/specific}/directories.json | 0 .../{ => commands}/nodeos/definition.js | 0 cli-commands/{ => commands}/nodeos/index.js | 0 .../specific/nodeos-data/data-manager.js | 29 +++++++ .../nodeos/specific/nodeos-data/nodeos.json | 1 + .../nodeos/subcommands/accounts/definition.js | 0 .../nodeos/subcommands/accounts/index.js | 17 ++-- .../nodeos/subcommands/accounts/messages.js | 0 .../accounts/specific}/accounts-table.js | 2 +- .../nodeos/subcommands/common/accounts.js | 31 +++++++ .../nodeos/subcommands/logs/definition.js | 2 +- .../commands/nodeos/subcommands/logs/index.js | 37 ++++++++ .../nodeos/subcommands/logs/messages.js | 3 + .../subcommands/logs/options/lines-option.js | 0 .../nodeos/subcommands/start/definition.js | 2 +- .../nodeos/subcommands/start/index.js | 46 ++++++++++ .../nodeos/subcommands/start/messages.js | 2 +- .../subcommands/start/options/path-option.js | 9 +- .../subcommands/start/specific}/template.js | 2 +- .../nodeos/subcommands/stop/definition.js | 0 .../nodeos/subcommands/stop/index.js | 28 +++---- .../nodeos/subcommands/stop/messages.js | 1 - cli-commands/{ => commands}/option.js | 0 .../{ => commands}/shape/definition.js | 2 +- cli-commands/{ => commands}/shape/index.js | 2 +- cli-commands/{ => commands}/shape/messages.js | 0 .../shape/options/framework-option.js | 4 +- .../shape/specific}/repositories.json | 0 .../{ => commands}/test/definition.js | 2 +- cli-commands/{ => commands}/test/index.js | 15 ++-- cli-commands/{ => commands}/test/messages.js | 0 .../test/options/network-option.js | 7 +- .../test/options/path-option.js | 6 +- .../resource-usage-option/report-table.js | 2 +- .../resource-usage-option.js | 4 +- .../specific}/test-frameworks/mocha/index.js | 0 .../test-frameworks/mocha/mocha-config.json | 0 .../test/specific}/utils/index.js | 0 cli-commands/{ => common}/table.js | 11 +-- cli-commands/helpers/async-soft-exec.js | 26 +++--- cli-commands/helpers/file-system-util.js | 79 +++++++----------- cli-commands/init/definition.js | 8 -- .../contract-example/eosio.token.wasm | Bin 22604 -> 0 bytes cli-commands/nodeos/nodeos_data/config.json | 3 - .../nodeos/subcommands/accounts/accounts.json | 17 ---- cli-commands/nodeos/subcommands/logs/index.js | 38 --------- .../nodeos/subcommands/start/index.js | 68 --------------- cli.js | 22 ++--- package.json | 5 +- src/account/base-account.js | 2 +- src/account/normal-account/account-factory.js | 21 +++-- src/account/normal-account/account.js | 20 ++--- tests/account-tests.js | 48 ++++++++++- 79 files changed, 462 insertions(+), 359 deletions(-) rename cli-commands/{ => commands}/command.js (89%) rename cli-commands/{ => commands}/compile/definition.js (80%) rename cli-commands/{ => commands}/compile/index.js (84%) rename cli-commands/{ => commands}/compile/messages.js (100%) rename cli-commands/{ => commands}/compile/options/path-option.js (87%) rename cli-commands/{compile => commands/compile/specific}/directories.json (100%) rename cli-commands/{ => commands}/deploy/definition.js (72%) rename cli-commands/{ => commands}/deploy/index.js (94%) rename cli-commands/{ => commands}/deploy/messages.js (100%) rename cli-commands/{ => commands}/deploy/options/deployer-option.js (86%) rename cli-commands/{ => commands}/deploy/options/network-option.js (59%) rename cli-commands/{ => commands}/deploy/options/path-option.js (88%) rename cli-commands/{ => commands}/group-command.js (100%) create mode 100644 cli-commands/commands/init/definition.js rename cli-commands/{ => commands}/init/index.js (79%) rename cli-commands/{ => commands}/init/messages.js (100%) rename cli-commands/{ => commands}/init/options/with-example/contract-example/eosio.token.abi (98%) rename cli-commands/{ => commands}/init/options/with-example/contract-example/eosio.token.cpp (62%) rename cli-commands/{ => commands}/init/options/with-example/contract-example/eosio.token.hpp (97%) create mode 100755 cli-commands/commands/init/options/with-example/contract-example/eosio.token.wasm rename cli-commands/{ => commands}/init/options/with-example/deployment-example/deployment.js (66%) rename cli-commands/{ => commands}/init/options/with-example/tests-example/tests.js (100%) rename cli-commands/{ => commands}/init/options/with-example/with-example-option.js (88%) rename cli-commands/{init => commands/init/specific}/default-package.json (100%) rename cli-commands/{init => commands/init/specific}/directories.json (100%) rename cli-commands/{ => commands}/nodeos/definition.js (100%) rename cli-commands/{ => commands}/nodeos/index.js (100%) create mode 100644 cli-commands/commands/nodeos/specific/nodeos-data/data-manager.js create mode 100644 cli-commands/commands/nodeos/specific/nodeos-data/nodeos.json rename cli-commands/{ => commands}/nodeos/subcommands/accounts/definition.js (100%) rename cli-commands/{ => commands}/nodeos/subcommands/accounts/index.js (73%) rename cli-commands/{ => commands}/nodeos/subcommands/accounts/messages.js (100%) rename cli-commands/{nodeos/subcommands/accounts => commands/nodeos/subcommands/accounts/specific}/accounts-table.js (78%) create mode 100644 cli-commands/commands/nodeos/subcommands/common/accounts.js rename cli-commands/{ => commands}/nodeos/subcommands/logs/definition.js (84%) create mode 100644 cli-commands/commands/nodeos/subcommands/logs/index.js rename cli-commands/{ => commands}/nodeos/subcommands/logs/messages.js (77%) rename cli-commands/{ => commands}/nodeos/subcommands/logs/options/lines-option.js (100%) rename cli-commands/{ => commands}/nodeos/subcommands/start/definition.js (81%) create mode 100644 cli-commands/commands/nodeos/subcommands/start/index.js rename cli-commands/{ => commands}/nodeos/subcommands/start/messages.js (78%) rename cli-commands/{ => commands}/nodeos/subcommands/start/options/path-option.js (60%) rename cli-commands/{nodeos/subcommands/start => commands/nodeos/subcommands/start/specific}/template.js (55%) rename cli-commands/{ => commands}/nodeos/subcommands/stop/definition.js (100%) rename cli-commands/{ => commands}/nodeos/subcommands/stop/index.js (52%) rename cli-commands/{ => commands}/nodeos/subcommands/stop/messages.js (79%) rename cli-commands/{ => commands}/option.js (100%) rename cli-commands/{ => commands}/shape/definition.js (84%) rename cli-commands/{ => commands}/shape/index.js (95%) rename cli-commands/{ => commands}/shape/messages.js (100%) rename cli-commands/{ => commands}/shape/options/framework-option.js (82%) rename cli-commands/{shape => commands/shape/specific}/repositories.json (100%) rename cli-commands/{ => commands}/test/definition.js (84%) rename cli-commands/{ => commands}/test/index.js (69%) rename cli-commands/{ => commands}/test/messages.js (100%) rename cli-commands/{ => commands}/test/options/network-option.js (71%) rename cli-commands/{ => commands}/test/options/path-option.js (86%) rename cli-commands/{ => commands}/test/options/resource-usage-option/report-table.js (83%) rename cli-commands/{ => commands}/test/options/resource-usage-option/resource-usage-option.js (99%) rename cli-commands/{test => commands/test/specific}/test-frameworks/mocha/index.js (100%) rename cli-commands/{test => commands/test/specific}/test-frameworks/mocha/mocha-config.json (100%) rename cli-commands/{test => commands/test/specific}/utils/index.js (100%) rename cli-commands/{ => common}/table.js (77%) delete mode 100644 cli-commands/init/definition.js delete mode 100755 cli-commands/init/options/with-example/contract-example/eosio.token.wasm delete mode 100644 cli-commands/nodeos/nodeos_data/config.json delete mode 100644 cli-commands/nodeos/subcommands/accounts/accounts.json delete mode 100644 cli-commands/nodeos/subcommands/logs/index.js delete mode 100644 cli-commands/nodeos/subcommands/start/index.js diff --git a/README.md b/README.md index 713a14d..9f610ae 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,48 @@ EOS development and deployment framework based on eosjs.js. The framework's main Telegram - https://t.me/eoslime Documentation - https://lyubo.gitbook.io/eoslime/ +# Version 1.0.4 change log + +* **eoslime nodeos** + * **eoslime nodeos start --path="Some path"** + Run local predefined single node chain + * **eoslime nodeos stop** + Stop single node chain started by **eoslime nodeos start** + * **eoslime nodeos accounts** + Show preloaded accounts on **eoslime nodeos start** + * **eoslime nodeos logs** + Show chain logs + +* **Account.create(name, privateKey, ?creator)** +There are cases you have already generated your private key and you have a name for your account. You only need to create it on the chain. + +* **Contract.deployRaw(rawWasm, abiJSON, ?options)** +Used for deploying a contract from WASM string and ABI in JSON format +A typical use case for `deployRaw` is in CI/CD. You don't want to compile your contract every time, however your tests needs WASM and ABI. A good approach is to deploy your contract on a test network like Jungle one and retrieve its WASM and ABI for your tests. + ```javascript + const eoslime = eoslime.init('jungle'); + const deployedContract = 'your_contract_name'; + const contractA_ABI = await eoslime.Provider.getABI(deployedContract); + const contractA_WASM = await eoslime.Provider.getRawWASM(deployedContract); + + const contractB = await eoslime.Contract.deployRaw(contractA_WASM, contractA_ABI); + ``` +* **Contract.deployRawOnAccount(rawWasm, abiJSON, account, ?options)** +Used for deploying a contract from WASM string and ABI in JSON format + +* **Provider.getABI(contractName)** +Returns contract ABI in JSON format + +* **Provider.getRawWASM(contractName)** +Returns raw WASM useful for deploying another contract directly + +* **contractInstance.abi** +Returns contract ABI in JSON format + +* **contractInstance.getRawWASM()** +Returns contract raw WASM + + # Version 1.0.3 change log * **eoslime shape --framework=react** diff --git a/cli-commands/command-definer.js b/cli-commands/command-definer.js index 1a69921..8a0c821 100644 --- a/cli-commands/command-definer.js +++ b/cli-commands/command-definer.js @@ -8,7 +8,7 @@ class CommandDefiner { command: command.template, description: command.description, builder: this.build(command), - handler: this.handle(command, command.params) + handler: this.handle(command) } } @@ -26,9 +26,9 @@ class CommandDefiner { } } - handle (command, params) { + handle (command) { return async (args) => { - const result = await command.execute(args, ...params); + const result = await command.execute(args); if (!result) { this.yargs.showHelp(); } diff --git a/cli-commands/command.js b/cli-commands/commands/command.js similarity index 89% rename from cli-commands/command.js rename to cli-commands/commands/command.js index c756161..2aa7277 100644 --- a/cli-commands/command.js +++ b/cli-commands/commands/command.js @@ -1,14 +1,12 @@ - class Command { constructor(commandDefinition) { + this.subcommands = []; + this.options = commandDefinition.options || []; this.template = commandDefinition.template || ''; this.description = commandDefinition.description || ''; - this.options = commandDefinition.options || []; - this.subcommands = []; - this.params = []; } - async processOptions(args) { + async processOptions (args) { const optionResults = {}; for (let i = 0; i < this.options.length; i++) { @@ -23,7 +21,7 @@ class Command { return optionResults; } - execute(args) { } + execute (args) { } } diff --git a/cli-commands/compile/definition.js b/cli-commands/commands/compile/definition.js similarity index 80% rename from cli-commands/compile/definition.js rename to cli-commands/commands/compile/definition.js index 30fc2bd..7e9c399 100644 --- a/cli-commands/compile/definition.js +++ b/cli-commands/commands/compile/definition.js @@ -1,7 +1,7 @@ const pathOption = require('./options/path-option'); module.exports = { - "template": "compile [path]", + "template": "compile", "description": "Compile contract/s", "options": [pathOption] } \ No newline at end of file diff --git a/cli-commands/compile/index.js b/cli-commands/commands/compile/index.js similarity index 84% rename from cli-commands/compile/index.js rename to cli-commands/commands/compile/index.js index ece8c91..675a712 100644 --- a/cli-commands/compile/index.js +++ b/cli-commands/commands/compile/index.js @@ -1,11 +1,11 @@ -const AsyncSoftExec = require('./../helpers/async-soft-exec'); -const Command = require('./../command'); +const AsyncSoftExec = require('../../helpers/async-soft-exec'); +const Command = require('../command'); const commandMessages = require('./messages'); -const compiledDirectories = require('./directories.json'); +const compiledDirectories = require('./specific/directories.json'); const compileCommandDefinition = require('./definition'); -const fileSysUtils = require('./../helpers/file-system-util'); +const fileSysUtils = require('../../helpers/file-system-util'); // eoslime compile --path @@ -15,7 +15,7 @@ class CompileCommand extends Command { super(compileCommandDefinition); } - async execute(args) { + async execute (args) { try { commandMessages.StartCompilation(); diff --git a/cli-commands/compile/messages.js b/cli-commands/commands/compile/messages.js similarity index 100% rename from cli-commands/compile/messages.js rename to cli-commands/commands/compile/messages.js diff --git a/cli-commands/compile/options/path-option.js b/cli-commands/commands/compile/options/path-option.js similarity index 87% rename from cli-commands/compile/options/path-option.js rename to cli-commands/commands/compile/options/path-option.js index d9da827..935a823 100644 --- a/cli-commands/compile/options/path-option.js +++ b/cli-commands/commands/compile/options/path-option.js @@ -1,6 +1,6 @@ -const fileSystemUtil = require('./../../helpers/file-system-util'); +const fileSystemUtil = require('../../../helpers/file-system-util'); -const Option = require('./../../option'); +const Option = require('../../option'); class PathOption extends Option { @@ -15,7 +15,7 @@ class PathOption extends Option { ); } - async process(optionValue) { + async process (optionValue) { if (fileSystemUtil.isDir(optionValue)) { const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue); const contractsFiles = dirFiles.filter(dirFile => dirFile.fileName.endsWith('.cpp')); diff --git a/cli-commands/compile/directories.json b/cli-commands/commands/compile/specific/directories.json similarity index 100% rename from cli-commands/compile/directories.json rename to cli-commands/commands/compile/specific/directories.json diff --git a/cli-commands/deploy/definition.js b/cli-commands/commands/deploy/definition.js similarity index 72% rename from cli-commands/deploy/definition.js rename to cli-commands/commands/deploy/definition.js index 927c64f..027face 100644 --- a/cli-commands/deploy/definition.js +++ b/cli-commands/commands/deploy/definition.js @@ -3,7 +3,7 @@ const networkOption = require('./options/network-option'); const deployerOption = require('./options/deployer-option'); module.exports = { - "template": "deploy [path] [network] [deployer]", - "description": "Run deployment script", + "template": "deploy", + "description": "Run deployment script/s", options: [pathOption, networkOption, deployerOption] } diff --git a/cli-commands/deploy/index.js b/cli-commands/commands/deploy/index.js similarity index 94% rename from cli-commands/deploy/index.js rename to cli-commands/commands/deploy/index.js index 0527da7..4c0afdb 100644 --- a/cli-commands/deploy/index.js +++ b/cli-commands/commands/deploy/index.js @@ -1,4 +1,4 @@ -const Command = require('./../command'); +const Command = require('../command'); const commandMessages = require('./messages'); const deployCommandDefinition = require('./definition'); @@ -10,7 +10,7 @@ class DeployCommand extends Command { super(deployCommandDefinition); } - async execute(args) { + async execute (args) { try { commandMessages.StartDeployment(); const optionsResults = await super.processOptions(args); diff --git a/cli-commands/deploy/messages.js b/cli-commands/commands/deploy/messages.js similarity index 100% rename from cli-commands/deploy/messages.js rename to cli-commands/commands/deploy/messages.js diff --git a/cli-commands/deploy/options/deployer-option.js b/cli-commands/commands/deploy/options/deployer-option.js similarity index 86% rename from cli-commands/deploy/options/deployer-option.js rename to cli-commands/commands/deploy/options/deployer-option.js index cc78c08..53a5326 100644 --- a/cli-commands/deploy/options/deployer-option.js +++ b/cli-commands/commands/deploy/options/deployer-option.js @@ -1,7 +1,7 @@ const consoleInput = require('prompts'); const Option = require('../../option'); -const AccountFactory = require('../../../src/account/normal-account/account-factory'); +const AccountFactory = require('../../../../src/account/normal-account/account-factory'); class DeployerOption extends Option { constructor() { @@ -14,7 +14,7 @@ class DeployerOption extends Option { ); } - async process(accountName, args) { + async process (accountName, args) { const accountFactory = new AccountFactory(args.network); const deployerAuth = await consoleInput({ diff --git a/cli-commands/deploy/options/network-option.js b/cli-commands/commands/deploy/options/network-option.js similarity index 59% rename from cli-commands/deploy/options/network-option.js rename to cli-commands/commands/deploy/options/network-option.js index 7b62fd2..e8b11a8 100644 --- a/cli-commands/deploy/options/network-option.js +++ b/cli-commands/commands/deploy/options/network-option.js @@ -1,19 +1,20 @@ -const Option = require('./../../option'); -const eoslime = require('./../../../index'); +const Option = require('../../option'); +const eoslime = require('../../../../index'); class NetworkOption extends Option { constructor() { super( 'network', { - "describe": "The blockchain network you are going to deploy on.\n\nParameters: \nNetwork name or in case of custom: \n{ url: custom url, chainId: custom chain id }\n", + "alias": "n", + "describe": "The blockchain network you are going to test on.\n \nNetwork name or in case of custom: \n\"eoslime deploy -n.url=\"custom url\" -n.chainId=\"custom chain id\"", "type": "string", "default": "local", } ); } - process(optionValue) { + process (optionValue) { if (optionValue) { return eoslime.init(optionValue); } diff --git a/cli-commands/deploy/options/path-option.js b/cli-commands/commands/deploy/options/path-option.js similarity index 88% rename from cli-commands/deploy/options/path-option.js rename to cli-commands/commands/deploy/options/path-option.js index cd1dff0..710849d 100644 --- a/cli-commands/deploy/options/path-option.js +++ b/cli-commands/commands/deploy/options/path-option.js @@ -1,7 +1,7 @@ const path = require('path'); -const Option = require('./../../option'); +const Option = require('../../option'); -const fileSystemUtil = require('./../../helpers/file-system-util'); +const fileSystemUtil = require('../../../helpers/file-system-util'); class PathOption extends Option { constructor() { @@ -15,7 +15,7 @@ class PathOption extends Option { ); } - async process(optionValue) { + async process (optionValue) { let deploymentFilesFunctions = []; if (fileSystemUtil.isDir(optionValue)) { const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue); diff --git a/cli-commands/group-command.js b/cli-commands/commands/group-command.js similarity index 100% rename from cli-commands/group-command.js rename to cli-commands/commands/group-command.js diff --git a/cli-commands/commands/init/definition.js b/cli-commands/commands/init/definition.js new file mode 100644 index 0000000..d9a76a4 --- /dev/null +++ b/cli-commands/commands/init/definition.js @@ -0,0 +1,8 @@ +const withExampleOption = require('./options/with-example/with-example-option'); + + +module.exports = { + "template": "init", + "description": "Build a ready-to-use development structure", + "options": [withExampleOption] +} \ No newline at end of file diff --git a/cli-commands/init/index.js b/cli-commands/commands/init/index.js similarity index 79% rename from cli-commands/init/index.js rename to cli-commands/commands/init/index.js index 0fccf0d..3385bbe 100644 --- a/cli-commands/init/index.js +++ b/cli-commands/commands/init/index.js @@ -1,13 +1,13 @@ -const AsyncSoftExec = require('./../helpers/async-soft-exec'); -const Command = require('./../command'); +const AsyncSoftExec = require('../../helpers/async-soft-exec'); +const Command = require('../command'); -const initDirectories = require('./directories'); +const initDirectories = require('./specific/directories.json'); const initCommandDefinition = require('./definition'); const commandMessages = require('./messages'); -const fileSystemUtil = require('./../helpers/file-system-util'); +const fileSystemUtil = require('../../helpers/file-system-util'); -const defaultPackageJsonDestination = `${__dirname}/default-package.json`; +const defaultPackageJsonDestination = `${__dirname}/specific/default-package.json`; // eoslime init --with-example @@ -17,7 +17,7 @@ class InitCommand extends Command { super(initCommandDefinition); } - async execute(args) { + async execute (args) { try { commandMessages.Installation(); diff --git a/cli-commands/init/messages.js b/cli-commands/commands/init/messages.js similarity index 100% rename from cli-commands/init/messages.js rename to cli-commands/commands/init/messages.js diff --git a/cli-commands/init/options/with-example/contract-example/eosio.token.abi b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.abi similarity index 98% rename from cli-commands/init/options/with-example/contract-example/eosio.token.abi rename to cli-commands/commands/init/options/with-example/contract-example/eosio.token.abi index c1a00e1..afbe954 100644 --- a/cli-commands/init/options/with-example/contract-example/eosio.token.abi +++ b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.abi @@ -1,6 +1,7 @@ { - "____comment": "This file was generated with eosio-abigen. DO NOT EDIT Tue Jan 22 15:25:57 2019", + "____comment": "This file was generated with eosio-abigen. DO NOT EDIT ", "version": "eosio::abi/1.1", + "types": [], "structs": [ { "name": "account", @@ -131,7 +132,6 @@ ] } ], - "types": [], "actions": [ { "name": "close", @@ -181,6 +181,5 @@ } ], "ricardian_clauses": [], - "variants": [], - "abi_extensions": [] + "variants": [] } \ No newline at end of file diff --git a/cli-commands/init/options/with-example/contract-example/eosio.token.cpp b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.cpp similarity index 62% rename from cli-commands/init/options/with-example/contract-example/eosio.token.cpp rename to cli-commands/commands/init/options/with-example/contract-example/eosio.token.cpp index 544cb8a..e94c4fd 100644 --- a/cli-commands/init/options/with-example/contract-example/eosio.token.cpp +++ b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.cpp @@ -14,13 +14,13 @@ void token::create(name issuer, require_auth(_self); auto sym = maximum_supply.symbol; - eosio_assert(sym.is_valid(), "invalid symbol name"); - eosio_assert(maximum_supply.is_valid(), "invalid supply"); - eosio_assert(maximum_supply.amount > 0, "max-supply must be positive"); + check(sym.is_valid(), "invalid symbol name"); + check(maximum_supply.is_valid(), "invalid supply"); + check(maximum_supply.amount > 0, "max-supply must be positive"); stats statstable(_self, sym.code().raw()); auto existing = statstable.find(sym.code().raw()); - eosio_assert(existing == statstable.end(), "token with symbol already exists"); + check(existing == statstable.end(), "token with symbol already exists"); statstable.emplace(_self, [&](auto &s) { s.supply.symbol = maximum_supply.symbol; @@ -32,20 +32,20 @@ void token::create(name issuer, void token::issue(name to, asset quantity, string memo) { auto sym = quantity.symbol; - eosio_assert(sym.is_valid(), "invalid symbol name"); - eosio_assert(memo.size() <= 256, "memo has more than 256 bytes"); + check(sym.is_valid(), "invalid symbol name"); + check(memo.size() <= 256, "memo has more than 256 bytes"); stats statstable(_self, sym.code().raw()); auto existing = statstable.find(sym.code().raw()); - eosio_assert(existing != statstable.end(), "token with symbol does not exist, create token before issue"); + check(existing != statstable.end(), "token with symbol does not exist, create token before issue"); const auto &st = *existing; require_auth(st.issuer); - eosio_assert(quantity.is_valid(), "invalid quantity"); - eosio_assert(quantity.amount > 0, "must issue positive quantity"); + check(quantity.is_valid(), "invalid quantity"); + check(quantity.amount > 0, "must issue positive quantity"); - eosio_assert(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); - eosio_assert(quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply"); + check(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); + check(quantity.amount <= st.max_supply.amount - st.supply.amount, "quantity exceeds available supply"); statstable.modify(st, same_payer, [&](auto &s) { s.supply += quantity; @@ -63,19 +63,19 @@ void token::issue(name to, asset quantity, string memo) void token::retire(asset quantity, string memo) { auto sym = quantity.symbol; - eosio_assert(sym.is_valid(), "invalid symbol name"); - eosio_assert(memo.size() <= 256, "memo has more than 256 bytes"); + check(sym.is_valid(), "invalid symbol name"); + check(memo.size() <= 256, "memo has more than 256 bytes"); stats statstable(_self, sym.code().raw()); auto existing = statstable.find(sym.code().raw()); - eosio_assert(existing != statstable.end(), "token with symbol does not exist"); + check(existing != statstable.end(), "token with symbol does not exist"); const auto &st = *existing; require_auth(st.issuer); - eosio_assert(quantity.is_valid(), "invalid quantity"); - eosio_assert(quantity.amount > 0, "must retire positive quantity"); + check(quantity.is_valid(), "invalid quantity"); + check(quantity.amount > 0, "must retire positive quantity"); - eosio_assert(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); + check(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); statstable.modify(st, same_payer, [&](auto &s) { s.supply -= quantity; @@ -89,9 +89,9 @@ void token::transfer(name from, asset quantity, string memo) { - eosio_assert(from != to, "cannot transfer to self"); + check(from != to, "cannot transfer to self"); require_auth(from); - eosio_assert(is_account(to), "to account does not exist"); + check(is_account(to), "to account does not exist"); auto sym = quantity.symbol.code(); stats statstable(_self, sym.raw()); const auto &st = statstable.get(sym.raw()); @@ -99,10 +99,10 @@ void token::transfer(name from, require_recipient(from); require_recipient(to); - eosio_assert(quantity.is_valid(), "invalid quantity"); - eosio_assert(quantity.amount > 0, "must transfer positive quantity"); - eosio_assert(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); - eosio_assert(memo.size() <= 256, "memo has more than 256 bytes"); + check(quantity.is_valid(), "invalid quantity"); + check(quantity.amount > 0, "must transfer positive quantity"); + check(quantity.symbol == st.supply.symbol, "symbol precision mismatch"); + check(memo.size() <= 256, "memo has more than 256 bytes"); auto payer = has_auth(to) ? to : from; @@ -115,7 +115,7 @@ void token::sub_balance(name owner, asset value) accounts from_acnts(_self, owner.value); const auto &from = from_acnts.get(value.symbol.code().raw(), "no balance object found"); - eosio_assert(from.balance.amount >= value.amount, "overdrawn balance"); + check(from.balance.amount >= value.amount, "overdrawn balance"); from_acnts.modify(from, owner, [&](auto &a) { a.balance -= value; @@ -148,7 +148,7 @@ void token::open(name owner, const symbol &symbol, name ram_payer) stats statstable(_self, sym_code_raw); const auto &st = statstable.get(sym_code_raw, "symbol does not exist"); - eosio_assert(st.supply.symbol == symbol, "symbol precision mismatch"); + check(st.supply.symbol == symbol, "symbol precision mismatch"); accounts acnts(_self, owner.value); auto it = acnts.find(sym_code_raw); @@ -165,8 +165,8 @@ void token::close(name owner, const symbol &symbol) require_auth(owner); accounts acnts(_self, owner.value); auto it = acnts.find(symbol.code().raw()); - eosio_assert(it != acnts.end(), "Balance row already deleted or never existed. Action won't have any effect."); - eosio_assert(it->balance.amount == 0, "Cannot close because the balance is not zero."); + check(it != acnts.end(), "Balance row already deleted or never existed. Action won't have any effect."); + check(it->balance.amount == 0, "Cannot close because the balance is not zero."); acnts.erase(it); } diff --git a/cli-commands/init/options/with-example/contract-example/eosio.token.hpp b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.hpp similarity index 97% rename from cli-commands/init/options/with-example/contract-example/eosio.token.hpp rename to cli-commands/commands/init/options/with-example/contract-example/eosio.token.hpp index 5670994..03d3ac2 100644 --- a/cli-commands/init/options/with-example/contract-example/eosio.token.hpp +++ b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.hpp @@ -4,8 +4,8 @@ */ #pragma once -#include -#include +#include +#include #include diff --git a/cli-commands/commands/init/options/with-example/contract-example/eosio.token.wasm b/cli-commands/commands/init/options/with-example/contract-example/eosio.token.wasm new file mode 100755 index 0000000000000000000000000000000000000000..43e8679f6c30181c6b9672682a59be01f1542ed4 GIT binary patch literal 25788 zcmeI5e{5dYdEf7^_Xl~&>N;{2PIlb$-nb2w+KFZ-l$K--uj(I495;%awrZDwqQzGh zNr|M$SF+qWBD=bP{|E*TOHsE=QEx+%&7D!BYl|!y2CYllq$pNnttWa?qm$+2eHGZ;U(;NmNE+HFqFD+p8S04d(!^Om5KHKrOS)! z{ki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IcJUBa`Cq5%@Ke`SqF8K0Q{*GPfU0hvQJonhXnEmn4 z*rDkSj?G7`^7s0`002&bl&I+=i01m@#rgHeBs%WV^QgOrtZAdh9zF>3*{%G0=LduS z#Wlngv0PYiBJ04L2k=IG`I`a3P>51rMm}kVMM2$=ss1{Ddf`!?@U^Y{P0bUDSa`tO ztNGEPLG-5+M7>uSi5FQB$k2A@V7$DVf9LSSq49V}BrgLwBqWZ%IM6U#vqV}p#4cVU z$!`k{7gyl>MNM_MHH~<2BfoPOPYuMrEakn9{H_4lx4c1)^43NE?jch7zl%`oFeVtr gV31{8c1bwPPkBqS4bqgh^Nhc{z$qtZzB`Kk9~o9^!vFvP literal 0 HcmV?d00001 diff --git a/cli-commands/init/options/with-example/deployment-example/deployment.js b/cli-commands/commands/init/options/with-example/deployment-example/deployment.js similarity index 66% rename from cli-commands/init/options/with-example/deployment-example/deployment.js rename to cli-commands/commands/init/options/with-example/deployment-example/deployment.js index f85d3e0..c88398d 100644 --- a/cli-commands/init/options/with-example/deployment-example/deployment.js +++ b/cli-commands/commands/init/options/with-example/deployment-example/deployment.js @@ -7,7 +7,8 @@ let deploy = async function (eoslime, deployer) { deployer = await eoslime.Account.createRandom(); } - let tokenContract = await eoslime.Contract.deployOnAccount(TOKEN_WASM_PATH, TOKEN_ABI_PATH, deployer); + const tokenContract = await eoslime.Contract.deployOnAccount(TOKEN_WASM_PATH, TOKEN_ABI_PATH, deployer); + console.log(tokenContract.name); } module.exports = deploy; \ No newline at end of file diff --git a/cli-commands/init/options/with-example/tests-example/tests.js b/cli-commands/commands/init/options/with-example/tests-example/tests.js similarity index 100% rename from cli-commands/init/options/with-example/tests-example/tests.js rename to cli-commands/commands/init/options/with-example/tests-example/tests.js diff --git a/cli-commands/init/options/with-example/with-example-option.js b/cli-commands/commands/init/options/with-example/with-example-option.js similarity index 88% rename from cli-commands/init/options/with-example/with-example-option.js rename to cli-commands/commands/init/options/with-example/with-example-option.js index e2b2059..ee57beb 100644 --- a/cli-commands/init/options/with-example/with-example-option.js +++ b/cli-commands/commands/init/options/with-example/with-example-option.js @@ -1,7 +1,7 @@ const path = require('path'); -const fileSystemUtil = require('./../../../helpers/file-system-util'); +const fileSystemUtil = require('../../../../helpers/file-system-util'); -const Option = require('./../../../option'); +const Option = require('../../../option'); class WithExampleOption extends Option { @@ -15,7 +15,7 @@ class WithExampleOption extends Option { ); } - process(optionValue) { + process (optionValue) { if (optionValue) { fileSystemUtil.createDir('./contracts/example/'); diff --git a/cli-commands/init/default-package.json b/cli-commands/commands/init/specific/default-package.json similarity index 100% rename from cli-commands/init/default-package.json rename to cli-commands/commands/init/specific/default-package.json diff --git a/cli-commands/init/directories.json b/cli-commands/commands/init/specific/directories.json similarity index 100% rename from cli-commands/init/directories.json rename to cli-commands/commands/init/specific/directories.json diff --git a/cli-commands/nodeos/definition.js b/cli-commands/commands/nodeos/definition.js similarity index 100% rename from cli-commands/nodeos/definition.js rename to cli-commands/commands/nodeos/definition.js diff --git a/cli-commands/nodeos/index.js b/cli-commands/commands/nodeos/index.js similarity index 100% rename from cli-commands/nodeos/index.js rename to cli-commands/commands/nodeos/index.js diff --git a/cli-commands/commands/nodeos/specific/nodeos-data/data-manager.js b/cli-commands/commands/nodeos/specific/nodeos-data/data-manager.js new file mode 100644 index 0000000..e259471 --- /dev/null +++ b/cli-commands/commands/nodeos/specific/nodeos-data/data-manager.js @@ -0,0 +1,29 @@ +const nodeosJSON = require('./nodeos.json'); +const fileSystemUtil = require('../../../../helpers/file-system-util'); + +const nodeosDataManager = { + defaultPath: () => { return __dirname }, + nodeosPath: () => { + return nodeosJSON.nodeosPath; + }, + setNodeosPath: (path) => { + const newPath = JSON.stringify({ nodeosPath: path }); + fileSystemUtil.writeFile(`${__dirname}/nodeos.json`, newPath); + }, + nodeosIsRunning: function (path) { + try { + const pid = fileSystemUtil.readFile(path + '/eosd.pid').toString(); + return process.kill(pid, 0); + } + catch (e) { + return e.code === 'EPERM' + } + }, + requireRunningNodeos: function (path) { + if (!nodeosDataManager.nodeosIsRunning(path)) { + throw new Error('Check if another nodeos has been started already'); + } + } +} + +module.exports = nodeosDataManager; diff --git a/cli-commands/commands/nodeos/specific/nodeos-data/nodeos.json b/cli-commands/commands/nodeos/specific/nodeos-data/nodeos.json new file mode 100644 index 0000000..0920820 --- /dev/null +++ b/cli-commands/commands/nodeos/specific/nodeos-data/nodeos.json @@ -0,0 +1 @@ +{"nodeosPath":"/Users/lyubo/Projects/eoslime/EOS_LIME/eoslime/cli-commands/commands/nodeos/specific/nodeos-data"} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/accounts/definition.js b/cli-commands/commands/nodeos/subcommands/accounts/definition.js similarity index 100% rename from cli-commands/nodeos/subcommands/accounts/definition.js rename to cli-commands/commands/nodeos/subcommands/accounts/definition.js diff --git a/cli-commands/nodeos/subcommands/accounts/index.js b/cli-commands/commands/nodeos/subcommands/accounts/index.js similarity index 73% rename from cli-commands/nodeos/subcommands/accounts/index.js rename to cli-commands/commands/nodeos/subcommands/accounts/index.js index 5e473d1..046b74f 100644 --- a/cli-commands/nodeos/subcommands/accounts/index.js +++ b/cli-commands/commands/nodeos/subcommands/accounts/index.js @@ -1,11 +1,11 @@ -const AccountsTable = require('./accounts-table'); +const AccountsTable = require('./specific/accounts-table'); const Command = require('../../../command'); -const accounts = require('./accounts.json'); - const commandMessages = require('./messages'); const accountsCommandDefinition = require('./definition'); +const predefinedAccounts = require('../common/accounts'); + // eoslime nodeos show accounts class AccountsCommand extends Command { @@ -13,19 +13,22 @@ class AccountsCommand extends Command { super(accountsCommandDefinition); } - async execute(args) { + async execute (args) { try { commandMessages.PreloadedAccounts(); - - let accountsTable = new AccountsTable(); + + const accountsTable = new AccountsTable(); + const accounts = predefinedAccounts.accounts(); + for (let i = 0; i < accounts.length; i++) { accountsTable.addRow([accounts[i].name, accounts[i].publicKey, accounts[i].privateKey]); } + accountsTable.draw(); } catch (error) { commandMessages.UnsuccessfulShowing(error); } - + return true; } } diff --git a/cli-commands/nodeos/subcommands/accounts/messages.js b/cli-commands/commands/nodeos/subcommands/accounts/messages.js similarity index 100% rename from cli-commands/nodeos/subcommands/accounts/messages.js rename to cli-commands/commands/nodeos/subcommands/accounts/messages.js diff --git a/cli-commands/nodeos/subcommands/accounts/accounts-table.js b/cli-commands/commands/nodeos/subcommands/accounts/specific/accounts-table.js similarity index 78% rename from cli-commands/nodeos/subcommands/accounts/accounts-table.js rename to cli-commands/commands/nodeos/subcommands/accounts/specific/accounts-table.js index 731f5e9..fe00b42 100644 --- a/cli-commands/nodeos/subcommands/accounts/accounts-table.js +++ b/cli-commands/commands/nodeos/subcommands/accounts/specific/accounts-table.js @@ -1,4 +1,4 @@ -const Table = require('../../../table'); +const Table = require('../../../../../common/table'); const TABLE_HEAD = { head: ['Account', 'Public Key', 'Private Key'] diff --git a/cli-commands/commands/nodeos/subcommands/common/accounts.js b/cli-commands/commands/nodeos/subcommands/common/accounts.js new file mode 100644 index 0000000..c778d90 --- /dev/null +++ b/cli-commands/commands/nodeos/subcommands/common/accounts.js @@ -0,0 +1,31 @@ +const eoslime = require('../../../../../').init(); + +const preDefinedAccounts = [ + { + "name": "eoslimedavid", + "publicKey": "EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey": "5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + }, + { + "name": "eoslimekevin", + "publicKey": "EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey": "5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + }, + { + "name": "eoslimemarty", + "publicKey": "EOS7UyV15G2t47MqRm4WpUP6KTfy9sNU3HHGu9aAgR2A3ktxoBTLv", + "privateKey": "5KS9t8LGsaQZxLP6Ln5WK6XwYU8M3AYHcfx1x6zoGmbs34vQsPT" + } +] + +module.exports = { + accounts: () => { + return preDefinedAccounts; + }, + load: async () => { + for (let i = 0; i < preDefinedAccounts.length; i++) { + const account = preDefinedAccounts[i]; + await eoslime.Account.create(account.name, account.privateKey); + } + } +} \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/logs/definition.js b/cli-commands/commands/nodeos/subcommands/logs/definition.js similarity index 84% rename from cli-commands/nodeos/subcommands/logs/definition.js rename to cli-commands/commands/nodeos/subcommands/logs/definition.js index 4a21b4d..5339e61 100644 --- a/cli-commands/nodeos/subcommands/logs/definition.js +++ b/cli-commands/commands/nodeos/subcommands/logs/definition.js @@ -1,7 +1,7 @@ const linesOption = require('./options/lines-option'); module.exports = { - "template": "logs [lines]", + "template": "logs", "description": "Show last N lines from local nodeos logs", "options": [linesOption] } \ No newline at end of file diff --git a/cli-commands/commands/nodeos/subcommands/logs/index.js b/cli-commands/commands/nodeos/subcommands/logs/index.js new file mode 100644 index 0000000..d1f1ef9 --- /dev/null +++ b/cli-commands/commands/nodeos/subcommands/logs/index.js @@ -0,0 +1,37 @@ +const nodoesDataManager = require('../../specific/nodeos-data/data-manager'); + +const Command = require('../../../command'); +const AsyncSoftExec = require('../../../../helpers/async-soft-exec'); + +const commandMessages = require('./messages'); +const logsCommandDefinition = require('./definition'); + +// eoslime nodeos show logs --lines + +class LogsCommand extends Command { + constructor() { + super(logsCommandDefinition); + } + + async execute (args) { + if (!nodoesDataManager.nodeosIsRunning(nodoesDataManager.nodeosPath())) { + commandMessages.EmptyLogs(); + return true; + } + + try { + const optionsResults = await super.processOptions(args); + const nodeosLogFile = nodoesDataManager.nodeosPath() + '/nodeos.log'; + + const asyncSoftExec = new AsyncSoftExec(`tail -n ${optionsResults.lines} ${nodeosLogFile}`); + asyncSoftExec.onSuccess((logs) => { commandMessages.NodeosLogs(logs); }); + await asyncSoftExec.exec(); + } catch (error) { + commandMessages.UnsuccessfulShowing(error); + } + + return true; + } +} + +module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/logs/messages.js b/cli-commands/commands/nodeos/subcommands/logs/messages.js similarity index 77% rename from cli-commands/nodeos/subcommands/logs/messages.js rename to cli-commands/commands/nodeos/subcommands/logs/messages.js index 0f5b8a9..2ea92a0 100644 --- a/cli-commands/nodeos/subcommands/logs/messages.js +++ b/cli-commands/commands/nodeos/subcommands/logs/messages.js @@ -5,6 +5,9 @@ module.exports = { console.log(chalk.magentaBright('===== Nodeos logs =====')); console.log(logs); }, + 'EmptyLogs': () => { + console.log(chalk.blueBright('===== Empty logs =====')); + }, 'UnsuccessfulShowing': (error) => { console.log(chalk.redBright(`===== Logs has not been shown =====`)); console.log(error); diff --git a/cli-commands/nodeos/subcommands/logs/options/lines-option.js b/cli-commands/commands/nodeos/subcommands/logs/options/lines-option.js similarity index 100% rename from cli-commands/nodeos/subcommands/logs/options/lines-option.js rename to cli-commands/commands/nodeos/subcommands/logs/options/lines-option.js diff --git a/cli-commands/nodeos/subcommands/start/definition.js b/cli-commands/commands/nodeos/subcommands/start/definition.js similarity index 81% rename from cli-commands/nodeos/subcommands/start/definition.js rename to cli-commands/commands/nodeos/subcommands/start/definition.js index dd7d192..63acfd6 100644 --- a/cli-commands/nodeos/subcommands/start/definition.js +++ b/cli-commands/commands/nodeos/subcommands/start/definition.js @@ -1,7 +1,7 @@ const pathOption = require('./options/path-option'); module.exports = { - "template": "start [path]", + "template": "start", "description": "Start local nodeos", "options": [pathOption] } diff --git a/cli-commands/commands/nodeos/subcommands/start/index.js b/cli-commands/commands/nodeos/subcommands/start/index.js new file mode 100644 index 0000000..242fcb1 --- /dev/null +++ b/cli-commands/commands/nodeos/subcommands/start/index.js @@ -0,0 +1,46 @@ +const Command = require('../../../command'); +const AsyncSoftExec = require('../../../../helpers/async-soft-exec'); + +const commandMessages = require('./messages'); +const startCommandDefinition = require('./definition'); + +const template = require('./specific/template'); + +const predefinedAccounts = require('../common/accounts'); +const nodeosDataManager = require('../../specific/nodeos-data/data-manager'); + +// eoslime nodeos start --path + +class StartCommand extends Command { + constructor() { + super(startCommandDefinition); + } + + async execute (args) { + if (nodeosDataManager.nodeosIsRunning(nodeosDataManager.nodeosPath())) { + commandMessages.NodeosAlreadyRunning(); + return true; + } + + try { + commandMessages.StartingNodeos(); + const optionsResults = await super.processOptions(args); + + nodeosDataManager.setNodeosPath(optionsResults.path); + + const asyncSoftExec = new AsyncSoftExec(template.build(optionsResults.path)); + await asyncSoftExec.exec(); + + nodeosDataManager.requireRunningNodeos(optionsResults.path); + await predefinedAccounts.load(); + + commandMessages.SuccessfullyStarted(); + } catch (error) { + commandMessages.UnsuccessfulStarting(error); + } + + return true; + } +} + +module.exports = StartCommand; diff --git a/cli-commands/nodeos/subcommands/start/messages.js b/cli-commands/commands/nodeos/subcommands/start/messages.js similarity index 78% rename from cli-commands/nodeos/subcommands/start/messages.js rename to cli-commands/commands/nodeos/subcommands/start/messages.js index edce524..94119a1 100644 --- a/cli-commands/nodeos/subcommands/start/messages.js +++ b/cli-commands/commands/nodeos/subcommands/start/messages.js @@ -2,7 +2,7 @@ const chalk = require('chalk'); module.exports = { 'StartingNodeos': () => { console.log(chalk.magentaBright('===== Starting nodeos ... =====')); }, - 'NodeosAlreadyRunning': () => { console.log(chalk.redBright(`===== Nodeos is already running =====`)); }, + 'NodeosAlreadyRunning': () => { console.log(chalk.blueBright(`===== Nodeos is already running =====`)); }, 'SuccessfullyStarted': () => { console.log(chalk.greenBright(`===== Successfully started =====`)); }, 'UnsuccessfulStarting': (error) => { console.log(chalk.redBright(`===== Nodeos has not been started =====`)); diff --git a/cli-commands/nodeos/subcommands/start/options/path-option.js b/cli-commands/commands/nodeos/subcommands/start/options/path-option.js similarity index 60% rename from cli-commands/nodeos/subcommands/start/options/path-option.js rename to cli-commands/commands/nodeos/subcommands/start/options/path-option.js index bd806a3..d4a7a43 100644 --- a/cli-commands/nodeos/subcommands/start/options/path-option.js +++ b/cli-commands/commands/nodeos/subcommands/start/options/path-option.js @@ -1,19 +1,20 @@ -const path = require('path'); - const Option = require('../../../../option'); +const nodeosDataManager = require('../../../specific/nodeos-data/data-manager'); + class PathOption extends Option { constructor() { super( 'path', { "describe": "The path nodeos data will be stored", - "type": "string" + "type": "string", + "default": nodeosDataManager.defaultPath() } ); } - async process(optionValue) { + async process (optionValue) { return optionValue; } } diff --git a/cli-commands/nodeos/subcommands/start/template.js b/cli-commands/commands/nodeos/subcommands/start/specific/template.js similarity index 55% rename from cli-commands/nodeos/subcommands/start/template.js rename to cli-commands/commands/nodeos/subcommands/start/specific/template.js index 825d719..4cc989d 100644 --- a/cli-commands/nodeos/subcommands/start/template.js +++ b/cli-commands/commands/nodeos/subcommands/start/specific/template.js @@ -1,5 +1,5 @@ module.exports = { build: (path) => { - return `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d ${path}/data --config-dir ${path}/config --access-control-allow-origin="*" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> ${path}/nodeos.log 2>&1 & echo $! > ${path}/eosd.pid` + return `nodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::producer_api_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_plugin --plugin eosio::history_api_plugin -d ${path}/data --config-dir ${path}/config --access-control-allow-origin="*" --p2p-listen-endpoint="0.0.0.0:3001" --contracts-console --verbose-http-errors --http-validate-host=false --filter-on="*" >> ${path}/nodeos.log 2>&1 & echo $! > ${path}/eosd.pid && sleep 2s` } } \ No newline at end of file diff --git a/cli-commands/nodeos/subcommands/stop/definition.js b/cli-commands/commands/nodeos/subcommands/stop/definition.js similarity index 100% rename from cli-commands/nodeos/subcommands/stop/definition.js rename to cli-commands/commands/nodeos/subcommands/stop/definition.js diff --git a/cli-commands/nodeos/subcommands/stop/index.js b/cli-commands/commands/nodeos/subcommands/stop/index.js similarity index 52% rename from cli-commands/nodeos/subcommands/stop/index.js rename to cli-commands/commands/nodeos/subcommands/stop/index.js index 2b05533..816ef51 100644 --- a/cli-commands/nodeos/subcommands/stop/index.js +++ b/cli-commands/commands/nodeos/subcommands/stop/index.js @@ -1,11 +1,11 @@ -const config = require('../../nodeos_data/config.json'); +const fileSystemUtil = require('../../../../helpers/file-system-util'); +const nodeosDataManager = require('../../specific/nodeos-data/data-manager'); const Command = require('../../../command'); -const AsyncSoftExec = require('../../../helpers/async-soft-exec'); +const AsyncSoftExec = require('../../../../helpers/async-soft-exec'); const commandMessages = require('./messages'); const stopCommandDefinition = require('./definition'); -const fileSystemUtil = require('../../../helpers/file-system-util'); // eoslime nodeos stop @@ -14,26 +14,20 @@ class StopCommand extends Command { super(stopCommandDefinition); } - async execute(args) { + async execute (args) { try { commandMessages.StoppingNodeos(); - const nodeosPath = config.nodeosPath; - const nodeosPidFile = nodeosPath + '/eosd.pid'; - - if (fileSystemUtil.exists(nodeosPidFile)) { - const nodeosPid = fileSystemUtil.readFile(nodeosPidFile); - + if (nodeosDataManager.nodeosIsRunning(nodeosDataManager.nodeosPath())) { + const nodeosPid = fileSystemUtil.readFile( + nodeosDataManager.nodeosPath() + '/eosd.pid' + ); const asyncKillExec = new AsyncSoftExec(`kill ${nodeosPid}`); - asyncKillExec.onError((error) => commandMessages.UnsuccessfulStopping(error)); await asyncKillExec.exec(); - - await cleanNodeosData(nodeosPath); - commandMessages.SuccessfullyStopped(); - return true; } - commandMessages.NoRunningNodeos(); + await clearNodeosData(nodeosDataManager.nodeosPath()); + commandMessages.SuccessfullyStopped(); } catch (error) { commandMessages.UnsuccessfulStopping(error); } @@ -42,7 +36,7 @@ class StopCommand extends Command { } } -const cleanNodeosData = async function (dirPath) { +const clearNodeosData = async function (dirPath) { fileSystemUtil.rmFile(dirPath + '/eosd.pid'); fileSystemUtil.rmFile(dirPath + '/nodeos.log'); await fileSystemUtil.recursivelyDeleteDir(dirPath + '/data'); diff --git a/cli-commands/nodeos/subcommands/stop/messages.js b/cli-commands/commands/nodeos/subcommands/stop/messages.js similarity index 79% rename from cli-commands/nodeos/subcommands/stop/messages.js rename to cli-commands/commands/nodeos/subcommands/stop/messages.js index 718de12..7af7b3f 100644 --- a/cli-commands/nodeos/subcommands/stop/messages.js +++ b/cli-commands/commands/nodeos/subcommands/stop/messages.js @@ -2,7 +2,6 @@ const chalk = require('chalk'); module.exports = { 'StoppingNodeos': () => { console.log(chalk.magentaBright('===== Stopping nodeos ... =====')); }, - 'NoRunningNodeos': () => { console.log(chalk.redBright('===== There is no running nodeos ... =====')); }, 'SuccessfullyStopped': () => { console.log(chalk.greenBright(`===== Successfully stopped =====`)); }, 'UnsuccessfulStopping': (error) => { console.log(chalk.redBright(`===== Nodeos has not been stopped =====`)); diff --git a/cli-commands/option.js b/cli-commands/commands/option.js similarity index 100% rename from cli-commands/option.js rename to cli-commands/commands/option.js diff --git a/cli-commands/shape/definition.js b/cli-commands/commands/shape/definition.js similarity index 84% rename from cli-commands/shape/definition.js rename to cli-commands/commands/shape/definition.js index a5638ab..cf6267d 100644 --- a/cli-commands/shape/definition.js +++ b/cli-commands/commands/shape/definition.js @@ -1,7 +1,7 @@ const frameworkOption = require('./options/framework-option'); module.exports = { - "template": "shape [framework]", + "template": "shape", "description": "Shapes a ready to use DApp, based on specified framework", "options": [frameworkOption] } diff --git a/cli-commands/shape/index.js b/cli-commands/commands/shape/index.js similarity index 95% rename from cli-commands/shape/index.js rename to cli-commands/commands/shape/index.js index 779ac50..d8c3df6 100644 --- a/cli-commands/shape/index.js +++ b/cli-commands/commands/shape/index.js @@ -1,6 +1,6 @@ const git = require('simple-git/promise')() -const Command = require('./../command'); +const Command = require('../command'); const commandMessages = require('./messages'); const shapeCommandDefinition = require('./definition'); diff --git a/cli-commands/shape/messages.js b/cli-commands/commands/shape/messages.js similarity index 100% rename from cli-commands/shape/messages.js rename to cli-commands/commands/shape/messages.js diff --git a/cli-commands/shape/options/framework-option.js b/cli-commands/commands/shape/options/framework-option.js similarity index 82% rename from cli-commands/shape/options/framework-option.js rename to cli-commands/commands/shape/options/framework-option.js index 8534129..763b762 100644 --- a/cli-commands/shape/options/framework-option.js +++ b/cli-commands/commands/shape/options/framework-option.js @@ -1,5 +1,5 @@ const Option = require('../../option'); -const repositories = require('./../repositories.json'); +const repositories = require('../specific/repositories.json'); class FrameworkOption extends Option { constructor() { @@ -13,7 +13,7 @@ class FrameworkOption extends Option { ); } - process(optionValue) { + process (optionValue) { return repositories[optionValue]; } } diff --git a/cli-commands/shape/repositories.json b/cli-commands/commands/shape/specific/repositories.json similarity index 100% rename from cli-commands/shape/repositories.json rename to cli-commands/commands/shape/specific/repositories.json diff --git a/cli-commands/test/definition.js b/cli-commands/commands/test/definition.js similarity index 84% rename from cli-commands/test/definition.js rename to cli-commands/commands/test/definition.js index 37d008b..165c588 100644 --- a/cli-commands/test/definition.js +++ b/cli-commands/commands/test/definition.js @@ -3,7 +3,7 @@ const networkOption = require('./options/network-option'); const resourceReportOption = require('./options/resource-usage-option/resource-usage-option'); module.exports = { - "template": "test [path] [network] [resource-usage]", + "template": "test", "description": "Run tests", "options": [pathOption, networkOption, resourceReportOption] } \ No newline at end of file diff --git a/cli-commands/test/index.js b/cli-commands/commands/test/index.js similarity index 69% rename from cli-commands/test/index.js rename to cli-commands/commands/test/index.js index 4e970ba..64777db 100644 --- a/cli-commands/test/index.js +++ b/cli-commands/commands/test/index.js @@ -1,24 +1,23 @@ -const Command = require('./../command'); +const Command = require('../command'); const testCommandDefinition = require('./definition'); -const eoslime = require('./../../index'); +const eoslime = require('../../../index'); -const testUtils = require('./utils'); +const testUtils = require('./specific/utils'); // eoslime test --path --network --resource-usage= class TestCommand extends Command { - constructor(...params) { + constructor(TestFramework) { super(testCommandDefinition); - this.params = params; + this.TestFramework = TestFramework; } - async execute(args, TestFramework) { + async execute (args) { try { args.eoslime = eoslime.init(); - - args.testFramework = new TestFramework(); + args.testFramework = new this.TestFramework(); await super.processOptions(args); diff --git a/cli-commands/test/messages.js b/cli-commands/commands/test/messages.js similarity index 100% rename from cli-commands/test/messages.js rename to cli-commands/commands/test/messages.js diff --git a/cli-commands/test/options/network-option.js b/cli-commands/commands/test/options/network-option.js similarity index 71% rename from cli-commands/test/options/network-option.js rename to cli-commands/commands/test/options/network-option.js index 6a13327..a37eeb8 100644 --- a/cli-commands/test/options/network-option.js +++ b/cli-commands/commands/test/options/network-option.js @@ -1,18 +1,19 @@ -const Option = require('./../../option'); +const Option = require('../../option'); class NetworkOption extends Option { constructor() { super( 'network', { - "describe": "The blockchain network you are going to test on.\n\nParameters: \nNetwork name or in case of custom: \n\"{ url: custom url, chainId: custom chain id }\"\n", + "alias": "n", + "describe": "The blockchain network you are going to test on.\n \nNetwork name or in case of custom: \n\"eoslime test -n.url=\"custom url\" -n.chainId=\"custom chain id\"", "type": "object", "default": "local", } ); } - process(optionValue, args) { + process (optionValue, args) { let provider; if (optionValue) { provider = new args.eoslime.Provider(optionValue); diff --git a/cli-commands/test/options/path-option.js b/cli-commands/commands/test/options/path-option.js similarity index 86% rename from cli-commands/test/options/path-option.js rename to cli-commands/commands/test/options/path-option.js index 0bea219..d4465ee 100644 --- a/cli-commands/test/options/path-option.js +++ b/cli-commands/commands/test/options/path-option.js @@ -1,7 +1,7 @@ const path = require('path'); -const Option = require('./../../option'); +const Option = require('../../option'); -const fileSystemUtil = require('./../../helpers/file-system-util'); +const fileSystemUtil = require('../../../helpers/file-system-util'); class PathOption extends Option { constructor() { @@ -15,7 +15,7 @@ class PathOption extends Option { ); } - async process(optionValue, args) { + async process (optionValue, args) { let deploymentFilesFunctions = []; if (fileSystemUtil.isDir(optionValue)) { const dirFiles = await fileSystemUtil.recursivelyReadDir(optionValue); diff --git a/cli-commands/test/options/resource-usage-option/report-table.js b/cli-commands/commands/test/options/resource-usage-option/report-table.js similarity index 83% rename from cli-commands/test/options/resource-usage-option/report-table.js rename to cli-commands/commands/test/options/resource-usage-option/report-table.js index 706dffb..eceb4f1 100644 --- a/cli-commands/test/options/resource-usage-option/report-table.js +++ b/cli-commands/commands/test/options/resource-usage-option/report-table.js @@ -1,4 +1,4 @@ -const Table = require('../../../table'); +const Table = require('../../../../common/table'); const TABLE_HEAD = { head: ['', 'Contract', 'Action', 'CPU ( MIN | MAX )', 'NET ( MIN | MAX )', 'RAM ( MIN | MAX )', 'Calls'] diff --git a/cli-commands/test/options/resource-usage-option/resource-usage-option.js b/cli-commands/commands/test/options/resource-usage-option/resource-usage-option.js similarity index 99% rename from cli-commands/test/options/resource-usage-option/resource-usage-option.js rename to cli-commands/commands/test/options/resource-usage-option/resource-usage-option.js index 03f060b..27a13b1 100644 --- a/cli-commands/test/options/resource-usage-option/resource-usage-option.js +++ b/cli-commands/commands/test/options/resource-usage-option/resource-usage-option.js @@ -6,7 +6,7 @@ class ResourceReportOption extends Option { super( 'resource-usage', { - "describe": "Provides you RAM and Bandwidth report for a contract.", + "describe": "Provides you RAM and Bandwidth report for your tests", "type": "string", "default": "false" } @@ -15,7 +15,7 @@ class ResourceReportOption extends Option { this.reportTable = new ReportTable(); } - process(optionValue, args) { + process (optionValue, args) { if (optionValue != 'false') { const contractsResources = []; const deploymentsResources = []; diff --git a/cli-commands/test/test-frameworks/mocha/index.js b/cli-commands/commands/test/specific/test-frameworks/mocha/index.js similarity index 100% rename from cli-commands/test/test-frameworks/mocha/index.js rename to cli-commands/commands/test/specific/test-frameworks/mocha/index.js diff --git a/cli-commands/test/test-frameworks/mocha/mocha-config.json b/cli-commands/commands/test/specific/test-frameworks/mocha/mocha-config.json similarity index 100% rename from cli-commands/test/test-frameworks/mocha/mocha-config.json rename to cli-commands/commands/test/specific/test-frameworks/mocha/mocha-config.json diff --git a/cli-commands/test/utils/index.js b/cli-commands/commands/test/specific/utils/index.js similarity index 100% rename from cli-commands/test/utils/index.js rename to cli-commands/commands/test/specific/utils/index.js diff --git a/cli-commands/table.js b/cli-commands/common/table.js similarity index 77% rename from cli-commands/table.js rename to cli-commands/common/table.js index afb96e9..b232557 100644 --- a/cli-commands/table.js +++ b/cli-commands/common/table.js @@ -6,13 +6,14 @@ class Table { this.table = new CLITable(tableHead); } - addRow(rowData) { + addRow (rowData) { this.table.push(rowData); } - addSection(sectionName, sectionRows) { - this.table.push({ [chalk.cyanBright(sectionName)]: - addEmptyColumns(this.table.options.head.length) }); + addSection (sectionName, sectionRows) { + this.table.push({ + [chalk.cyanBright(sectionName)]: addEmptyColumns(this.table.options.head.length) + }); if (sectionRows) { for (let i = 0; i < sectionRows.length; i++) { @@ -23,7 +24,7 @@ class Table { } } - draw() { + draw () { console.log(this.table.toString()); } } diff --git a/cli-commands/helpers/async-soft-exec.js b/cli-commands/helpers/async-soft-exec.js index 5c4d3cc..f1f44de 100644 --- a/cli-commands/helpers/async-soft-exec.js +++ b/cli-commands/helpers/async-soft-exec.js @@ -4,28 +4,32 @@ class AsyncSoftExec { constructor(command) { this.command = command; - this.errorCallback = () => {}; - this.successCallback = () => {}; + this.successCallback = () => { }; + this.errorCallback = (error) => { throw new Error(error) }; } - onError(callback) { + onError (callback) { this.errorCallback = callback; } - onSuccess(callback) { + onSuccess (callback) { this.successCallback = callback; } - async exec() { + async exec () { return new Promise((resolve, reject) => { - exec(this.command, (error, stdout) => { - if (error) { - this.errorCallback(error); + exec(this.command, async (error, stdout) => { + try { + if (error) { + await this.errorCallback(error); + return void resolve(true); + } + + await this.successCallback(stdout); return void resolve(true); + } catch (error) { + reject(error); } - - this.successCallback(stdout); - return void resolve(true); }); }); } diff --git a/cli-commands/helpers/file-system-util.js b/cli-commands/helpers/file-system-util.js index 867aad3..71d9c84 100644 --- a/cli-commands/helpers/file-system-util.js +++ b/cli-commands/helpers/file-system-util.js @@ -30,63 +30,48 @@ const fileSystemUtils = { return fs.lstatSync(path).isFile(); }, recursivelyReadDir: async function (dirPath) { - return new Promise(async (resolve, reject) => { - let files = []; + let files = []; - fs.readdir(dirPath, async function (err, filenames) { - if (err) { - return void reject(err.message); - } - - for (let i = 0; i < filenames.length; i++) { - const fileName = filenames[i]; + await fileSystemUtils.forEachFileInDir(dirPath, async (fileName) => { - if (fileSystemUtils.isDir(`${dirPath}/${fileName}`)) { - const dirFiles = await fileSystemUtils.recursivelyReadDir(`${dirPath}/${fileName}`); - files = files.concat(dirFiles); - } else { - files.push({ - fileName: fileName, - fullPath: `${dirPath}/${fileName}` - }); - } - } - - resolve(files); - }); + if (fileSystemUtils.isDir(`${dirPath}/${fileName}`)) { + const dirFiles = await fileSystemUtils.recursivelyReadDir(`${dirPath}/${fileName}`); + files = files.concat(dirFiles); + } else { + files.push({ + fileName: fileName, + fullPath: `${dirPath}/${fileName}` + }); + } }); + + return files; }, recursivelyDeleteDir: async function (dirPath) { - return new Promise(async (resolve, reject) => { - fs.readdir(dirPath, async function (err, filenames) { + await fileSystemUtils.forEachFileInDir(dirPath, async (fileName) => { + if (fileSystemUtils.isDir(path.join(dirPath, fileName))) { + await fileSystemUtils.recursivelyDeleteDir(path.join(dirPath, fileName)); + } else { + fileSystemUtils.rmFile(path.join(dirPath, fileName)); + } + }); + + + fileSystemUtils.rmDir(dirPath); + }, + forEachFileInDir: (dirPath, actionCallback) => { + return new Promise((resolve, reject) => { + fs.readdir(dirPath, async function (err, fileNames) { if (err) { return void reject(err.message); } - - for (let i = 0; i < filenames.length; i++) { - const filename = filenames[i]; - - if (fileSystemUtils.isDir(path.join(dirPath, filename))) { - await fileSystemUtils.recursivelyDeleteDir(path.join(dirPath, filename)); - } else { - fileSystemUtils.rmFile(path.join(dirPath, filename)); - } + + for (let i = 0; i < fileNames.length; i++) { + const fileName = fileNames[i]; + await actionCallback(fileName); } - - fileSystemUtils.rmDir(dirPath); - - resolve(); - }); - }); - }, - forEachFileInDir: (dirPath, actionCallback) => { - fs.readdir(dirPath, function (err, filenames) { - if (err) { - throw new Error(err.message); - } - filenames.forEach(function (filename) { - actionCallback(filename); + resolve(); }); }); }, diff --git a/cli-commands/init/definition.js b/cli-commands/init/definition.js deleted file mode 100644 index 2364f1c..0000000 --- a/cli-commands/init/definition.js +++ /dev/null @@ -1,8 +0,0 @@ -const withExampleOption = require('./options/with-example/with-example-option'); - - -module.exports = { - "template": "init [with-example]", - "description": "Build a development structure with deployment, contracts and tests folders inside", - "options": [withExampleOption] -} \ No newline at end of file diff --git a/cli-commands/init/options/with-example/contract-example/eosio.token.wasm b/cli-commands/init/options/with-example/contract-example/eosio.token.wasm deleted file mode 100755 index a3e02afc75c8000667a0b6c0c56c667ab2cf1eb0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22604 zcmeI4e~ca1b>HXL`>{Lw#F0ZQTT)5yn+WhSmQ-4jm#n2$944ZuP?jiJjuqGS@^SZ3 z`}6IuxBQV(Tn2F(p@kb2iGe6>Pz8nMMuE_@h?~?wW5!i#rFK&Tj$j8!P!}+2H-8x@ zT*OIh_47S<=DoMe6(zM+(Ez2boi}&xJ@?%6`<#1cg3jhj7z9E1VtDJBc>BtBa3(k6_(*WAfdBs2i8w6+*VE#m3uDvVn_Rddibl0~QHo7yNt^Ryax2Epu z=ECYsXLGZ=(GMDGO6ShboLlJ4%`8mc6ExM5&2DXMbbI}ojqYrB;e2-^7_+f--0ZIc zPd&%g)S_u?ZLZVzZIRmQE8UgZwM#*&oAHIsna=F&>Q=8GOsL`J3MXJMtSvB$N31#D zp{MY)ZbGWpz1X*@S{j&jX8Q}Py%{F!%xo_FWH-3Unm4+gIi?sq3#|7zemOZ5L znVGHL>c(9E++Ci4jhUJ5`rxiPGqbX_+&_1BkO?lgojLjrZ#TEj4sIFR>kfua%)pw9 zTfNQxxy^;(W({xAw7lBs)40$-=MfmQZo@ul*=N{;QBV^S%$*bPca)HP+orXBUy0n@ z!ue5bmUm#&-`MKS_Rq}$W54=?E@ZCO4Z3BAO`6`R4h|B|oLyd>U7DTmEc9m9Ivbsp zZoj*+$_P=EHN#r_Tqc)zDcC9#un! zhR60>j}P?U^PbM~!c)DO^PT0He(<=OJBz!UKk!ZuXLtJ(Y6slz_79Ftgh3Ie^?RnK z-*fc#@n3o_ycfJb*-WDCCtKk}oa&Kam7O1NMIJ)KC3Mjc2IS)m8EXZp0T~4mOhjo4hG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z zhNesqBTEPUI$8m^$0N8C!S|Io33qmyB=AV8XIreTac&xm+Au)a#09^g8VhP_L7d9b zf*cJGl0JJH)maQ7hxVUYOI&Q5JweF499E)61}Y(`q1-205mUiv6H@;n77J195~(tp z^a4^`cHt8Fu`$hF+A}>Y`{=V$jdc@~pm-T=Kpr)VUr-Q4E>aa5Q}fLl|+bkkHe= zuonZNi4Uie^fEz)iGo5RQTm^KJVdLNz+lZ;i|f z*^M$m;wMzdtE4Qkw7oP`LtN9VH@(|PmhNBZ@foy*Ik$Of+wCfASn1wR@xmr z+OjXKt#p?8a@@?hjnx(Ybh~rzLTA&>bvOBz8aMq_x7u62%G(N?4^EJefX3{ zdf)Z1=2p9#uD9Cvz;1W5fbKKgCOz9dCs+%cn_EKX=ROytH&@hI-|F=G3;j#9KTrD) z82Z+8umU&IhYww(2TEeE>9dP`0kY>-7B*Kp{n>ed@YRbnuLgk4ER^1Ko%5ZA<<8mV zuJcr)BX4BwMUwh*(odhTbW2?kg~R-*=ji}$#o1B1@On);*;{pIJIkHk zY}c)xUF^>G-8nv1DIwuioAe!g@^NEsqjRBG_2R+jd2mZf&+D+_bY}YS@e<<3>ILM^ zOUztXf;i_^H(aj^RL}M9+?}qlk5{@2tG##ik)rcm*Xbc)=gxu6oy^A}&-Bh8@r0UP zUft{>s6P_~=tQ@d_DDZX4 z1-^|r*S*L{KF^hYe|KX8M1}c6?2T~IybtGmHRJTLHs55c7G7(9`b=2C zyw8PjmVI|m##>$KJ4YXm%=ZG%eyAje1jg~H%K_uHN>2+=<|KLgo|Vp1y@meP9BKoH zZSkEIedcvwOqaU=@wV`z(|0kBL&|A>qZyFRO$h|2nA0CDJ1+E)tQ8S+6dyWqfH=M5 zI;k-buPZd)V9Z@5VBhmi%FJ_QSnnNShW~DCWiePJtjGMzlwGG!6lc { commandMessages.UnsuccessfulShowing(error); }); - asyncSoftExec.onSuccess((logs) => { commandMessages.NodeosLogs(logs); }); - - await asyncSoftExec.exec(); - } - } catch (error) { - commandMessages.UnsuccessfulShowing(error); - } - - return true; - } -} - -module.exports = LogsCommand; diff --git a/cli-commands/nodeos/subcommands/start/index.js b/cli-commands/nodeos/subcommands/start/index.js deleted file mode 100644 index 040680b..0000000 --- a/cli-commands/nodeos/subcommands/start/index.js +++ /dev/null @@ -1,68 +0,0 @@ -const path = require('path'); -const config = require('../../nodeos_data/config.json'); - -const Command = require('../../../command'); -const AsyncSoftExec = require('../../../helpers/async-soft-exec'); - -const template = require('./template'); - -const commandMessages = require('./messages'); -const startCommandDefinition = require('./definition'); -const fileSystemUtil = require('../../../helpers/file-system-util'); - -const defaultPath = path.join(__dirname, '../../nodeos_data'); - -// eoslime nodeos start --path - -class StartCommand extends Command { - constructor() { - super(startCommandDefinition); - } - - async execute(args) { - let nodeosPath; - - try { - commandMessages.StartingNodeos(); - - const optionsResults = await super.processOptions(args); - - if (!config.nodeosPath) { - nodeosPath = optionsResults.path ? optionsResults.path : defaultPath; - } else { - checkForNodeos(config.NODEOS_DIR); - nodeosPath = optionsResults.path ? optionsResults.path : config.nodeosPath; - } - - checkForNodeos(nodeosPath); - storeNodeosConfig(nodeosPath); - - const asyncSoftExec = new AsyncSoftExec(template.build(nodeosPath)); - asyncSoftExec.onError((error) => { commandMessages.UnsuccessfulStarting(error); }); - await asyncSoftExec.exec(); - - if (fileSystemUtil.exists(nodeosPath + '/eosd.pid')) { - commandMessages.SuccessfullyStarted(); - } else { - commandMessages.UnsuccessfulStarting('Pid file has not been created'); - } - } catch (error) { - commandMessages.UnsuccessfulStarting(error); - } - - return true; - } -} - -const checkForNodeos = function (dirPath) { - if (fileSystemUtil.exists(dirPath + '/eosd.pid')) { - throw new Error('Nodeos is already running'); - } -} - -const storeNodeosConfig = function (dirPath) { - const configContent = JSON.stringify({ nodeosPath: dirPath }); - fileSystemUtil.writeFile(`${defaultPath}/config.json`, configContent); -} - -module.exports = StartCommand; diff --git a/cli.js b/cli.js index e419bf2..784b80f 100755 --- a/cli.js +++ b/cli.js @@ -2,14 +2,14 @@ const exec = require('child_process').exec; const CommandDefiner = require('./cli-commands/command-definer'); -const InitCommand = require('./cli-commands/init'); -const TestCommand = require('./cli-commands/test'); -const ShapeCommand = require('./cli-commands/shape'); -const NodeosCommand = require('./cli-commands/nodeos'); -const DeployCommand = require('./cli-commands/deploy'); -const CompileCommand = require('./cli-commands/compile'); +const InitCommand = require('./cli-commands/commands/init'); +const TestCommand = require('./cli-commands/commands/test'); +const ShapeCommand = require('./cli-commands/commands/shape'); +const NodeosCommand = require('./cli-commands/commands/nodeos'); +const DeployCommand = require('./cli-commands/commands/deploy'); +const CompileCommand = require('./cli-commands/commands/compile'); -const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); +const MochaFramework = require('./cli-commands/commands/test/specific/test-frameworks/mocha'); (() => { @@ -24,16 +24,16 @@ const MochaFramework = require('./cli-commands/test/test-frameworks/mocha'); const deployCommand = new DeployCommand(); const compileCommand = new CompileCommand(); + menu.command(commandDefiner.define(nodeosCommand)); menu.command(commandDefiner.define(initCommand)); + menu.command(commandDefiner.define(compileCommand)); menu.command(commandDefiner.define(testCommand)); - menu.command(commandDefiner.define(shapeCommand)); - menu.command(commandDefiner.define(nodeosCommand)); menu.command(commandDefiner.define(deployCommand)); - menu.command(commandDefiner.define(compileCommand)); + menu.command(commandDefiner.define(shapeCommand)); menu.command({ command: '*', - handler(args) { + handler (args) { exec(`${args['$0']} help`, (error, stdout, stderr) => { if (error) { throw new Error(`Could not execute help due to '${error}'`); diff --git a/package.json b/package.json index b332aca..e89ff86 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,11 @@ { "name": "eoslime", - "version": "1.0.3", + "version": "1.0.4", "description": "eoslime is an EOS development and deployment framework based on eosjs.js", "main": "index.js", "scripts": { "test": "bash ./tests/testing-contracts/compile.sh && nyc --check-coverage mocha './tests/*.js'", + "test-dev": "bash ./tests/testing-contracts/compile.sh && mocha './tests/*.js'", "coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov" }, "author": "Lyubomir Kiprov (Limechain)", @@ -43,4 +44,4 @@ "devDependencies": { "nyc": "14.1.1" } -} \ No newline at end of file +} diff --git a/src/account/base-account.js b/src/account/base-account.js index 25cc4ef..dd4fb37 100644 --- a/src/account/base-account.js +++ b/src/account/base-account.js @@ -14,7 +14,7 @@ class BaseAccount { this.publicKey = eosECC.PrivateKey.fromString(privateKey).toPublic().toString(); } - async getAuthorityInfo() { + async getAuthorityInfo () { const authority = arguments[0] ? arguments[0] : this.executiveAuthority.permission; const accountInfo = await this.provider.eos.getAccount(this.name); diff --git a/src/account/normal-account/account-factory.js b/src/account/normal-account/account-factory.js index e466003..08416aa 100644 --- a/src/account/normal-account/account-factory.js +++ b/src/account/normal-account/account-factory.js @@ -11,7 +11,7 @@ class AccountFactory { this.provider = provider; } - load(name, privateKey, authorityName = DEFAULT_AUTHORITY) { + load (name, privateKey, authorityName = DEFAULT_AUTHORITY) { try { return new Account(name, privateKey, this.provider, authorityName); } catch (error) { @@ -19,7 +19,16 @@ class AccountFactory { } } - async createFromName(accountName, accountCreator = this.provider.defaultAccount) { + async create (accountName, privateKey, accountCreator = this.provider.defaultAccount) { + is(accountCreator).instanceOf('BaseAccount'); + + const newAccount = new Account(accountName, privateKey, this.provider, DEFAULT_AUTHORITY); + await createAccountOnBlockchain(newAccount, accountCreator); + + return newAccount; + } + + async createFromName (accountName, accountCreator = this.provider.defaultAccount) { is(accountCreator).instanceOf('BaseAccount'); const accountPrivateKey = await utils.randomPrivateKey(); @@ -30,7 +39,7 @@ class AccountFactory { return newAccount; } - async createRandom(accountCreator = this.provider.defaultAccount) { + async createRandom (accountCreator = this.provider.defaultAccount) { is(accountCreator).instanceOf('BaseAccount'); const privateKey = await utils.randomPrivateKey(); @@ -41,7 +50,7 @@ class AccountFactory { return newAccount; } - async createRandoms(accountsCount, accountCreator = this.provider.defaultAccount) { + async createRandoms (accountsCount, accountCreator = this.provider.defaultAccount) { const accounts = []; for (let i = 0; i < accountsCount; i++) { const newAccount = await this.createRandom(accountCreator); @@ -51,7 +60,7 @@ class AccountFactory { return accounts; } - async createEncrypted(password, accountCreator = this.provider.defaultAccount) { + async createEncrypted (password, accountCreator = this.provider.defaultAccount) { try { const newAccount = await this.createRandom(accountCreator); const dataToBeEncrypted = { @@ -69,7 +78,7 @@ class AccountFactory { } } - fromEncrypted(encryptedAccount, password) { + fromEncrypted (encryptedAccount, password) { try { const decryptedAccount = JSON.parse(JSON.stringify(encryptedAccount)); diff --git a/src/account/normal-account/account.js b/src/account/normal-account/account.js index 1ab7792..3e68a25 100644 --- a/src/account/normal-account/account.js +++ b/src/account/normal-account/account.js @@ -9,7 +9,7 @@ class Account extends BaseAccount { super(name, privateKey, provider, permission); } - async buyRam(bytes, payer = this) { + async buyRam (bytes, payer = this) { is(payer).instanceOf('BaseAccount'); return this.provider.eos.transaction(tr => { @@ -21,7 +21,7 @@ class Account extends BaseAccount { }, { keyProvider: payer.privateKey }); } - async buyBandwidth(cpu, net, payer = this) { + async buyBandwidth (cpu, net, payer = this) { is(payer).instanceOf('BaseAccount'); return this.provider.eos.transaction(tr => { @@ -35,7 +35,7 @@ class Account extends BaseAccount { }, { keyProvider: payer.privateKey }); } - async send(receiver, amount, symbol = 'EOS') { + async send (receiver, amount, symbol = 'EOS') { is(receiver).instanceOf('BaseAccount'); return this.provider.eos.transfer( @@ -47,7 +47,7 @@ class Account extends BaseAccount { ); } - async createSubAuthority(authorityName, threshold = 1) { + async createSubAuthority (authorityName, threshold = 1) { const authorization = { threshold, keys: [{ key: this.publicKey, weight: threshold }] @@ -59,18 +59,18 @@ class Account extends BaseAccount { return AuthorityAccount.construct(authorityAccount, this.executiveAuthority.permission); } - async increaseThreshold(threshold) { + async increaseThreshold (threshold) { const authorityInfo = await this.getAuthorityInfo(); authorityInfo.required_auth.threshold = threshold; return updateAuthority.call(this, authorityInfo.perm_name, authorityInfo.parent, authorityInfo.required_auth); } - async addPermission(authorityName, weight = 1) { + async addPermission (authorityName, weight = 1) { return this.addOnBehalfAccount(this.name, authorityName, weight); } - async addOnBehalfAccount(accountName, authority = 'active', weight = 1) { + async addOnBehalfAccount (accountName, authority = 'active', weight = 1) { const authorityInfo = await this.getAuthorityInfo(); const hasAlreadyAccount = authorityInfo.required_auth.accounts.find((account) => { return account.permission.actor == accountName; @@ -82,7 +82,7 @@ class Account extends BaseAccount { } } - async addAuthorityKey(publicKey, weight = 1) { + async addAuthorityKey (publicKey, weight = 1) { if (!eosECC.isValidPublic(publicKey)) { throw new Error('Provided public key is not a valid one'); } @@ -98,7 +98,7 @@ class Account extends BaseAccount { } } - async setWeight(weight) { + async setWeight (weight) { const authorityInfo = await this.getAuthorityInfo(); authorityInfo.required_auth.keys.map(authorityKey => { if (authorityKey.key == this.publicKey) { @@ -109,7 +109,7 @@ class Account extends BaseAccount { return updateAuthority.call(this, authorityInfo.perm_name, authorityInfo.parent, authorityInfo.required_auth); } - async getBalance(symbol = 'EOS', code = 'eosio.token') { + async getBalance (symbol = 'EOS', code = 'eosio.token') { return this.provider.eos.getCurrencyBalance(code, this.name, symbol); } } diff --git a/tests/account-tests.js b/tests/account-tests.js index 7a52b5f..c798241 100644 --- a/tests/account-tests.js +++ b/tests/account-tests.js @@ -63,7 +63,7 @@ describe('Account', function () { /* Deploy eos token contract on local nodoes in order to send eos and buy ram / bandwidth */ - async function createEOSToken() { + async function createEOSToken () { const TOKEN_ABI_PATH = './tests/testing-contracts/compiled/eosio.token.abi'; const TOKEN_WASM_PATH = './tests/testing-contracts/compiled/eosio.token.wasm'; const TOTAL_SUPPLY = '1000000000.0000 SYS'; @@ -82,7 +82,7 @@ describe('Account', function () { await createEOSToken(); }); - function assertCorrectAccount(account) { + function assertCorrectAccount (account) { assert(account.name == ACCOUNT_NAME, 'Incorrect name'); assert(account.privateKey == ACCOUNT_PRIVATE_KEY, 'Incorrect private key'); assert(account.publicKey == ACCOUNT_PUBLIC_KEY, 'Incorrect public key'); @@ -523,6 +523,50 @@ describe('Account', function () { } }); + describe('Create', function () { + + it('Should create account [account creator]', async () => { + let creatorAccount = Account.load(ACCOUNT_NAME, ACCOUNT_PRIVATE_KEY); + + let accountName = await eoslime.utils.randomName(); + let privateKey = await eoslime.utils.randomPrivateKey(); + + await Account.create(accountName, privateKey, creatorAccount); + + assert(await Provider.eos.getAccount(accountName), 'Account is not created on blockchain'); + }); + + it('Should create account [default account]', async () => { + let accountName = await eoslime.utils.randomName(); + let privateKey = await eoslime.utils.randomPrivateKey(); + + await Account.create(accountName, privateKey); + + assert(await Provider.eos.getAccount(accountName), 'Account is not created on blockchain'); + }); + + it('Should throw if one try to create an already existing account', async () => { + try { + await Account.create(ACCOUNT_NAME, ACCOUNT_PRIVATE_KEY); + assert(false, 'Should throw'); + } catch (error) { + assert(error.includes('that name is already taken')); + } + }); + + it('Should throw if one provide incorrect account as account creator', async () => { + try { + let accountName = await eoslime.utils.randomName(); + let privateKey = await eoslime.utils.randomPrivateKey(); + + await Account.create(accountName, privateKey, 'Fake creator'); + assert(false, 'Should throw'); + } catch (error) { + assert(error.message.includes('Provided String is not an instance of BaseAccount')); + } + }); + }); + describe('Create from name', function () { it('Should create account from name [account creator]', async () => {