From 2a71b1f49a4586ab233294ef60cb1c49b4345118 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Dec 2018 15:30:53 +0300 Subject: [PATCH 1/4] Adding `node version` `node height` commands --- ops/node.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ops/node.js diff --git a/ops/node.js b/ops/node.js new file mode 100644 index 0000000..84ff431 --- /dev/null +++ b/ops/node.js @@ -0,0 +1,53 @@ +/* +*/ +const config = require('../helpers/configReader.js') +const popsicle = require('popsicle') +var possibleTypes=['height', 'version'] +module.exports=function (vorpal) { + return vorpal.command('node ').description('Fetch information about node. Available types: height, version').autocomplete(possibleTypes).action(function(args, callback) { + if (!possibleTypes.includes(args.type)) { + this.log('Not valid type') + if (callback) + callback() + return {success: false, error:'Not valid type'} + } + else { + var endpoint='' + var multipleSelect = false + if (args.input=='?') { + var multipleSelect = true + } + if (!multipleSelect) { + switch (args.type) { + case 'height': + endpoint = '/api/blocks/getHeight' + break + case 'version': + endpoint = '/api/peers/version' + break + default: + this.log('Not implemented yet') + if (callback) + callback() + return {success: false, error:'Not implemented yet'} + } + } else { + this.log('Not implemented yet') + if (callback) + callback() + return {success: false, error:'Not implemented yet'} + } + var self = this + return popsicle.request({ + method: 'GET', + url: config.getNodeConnectString() + endpoint + }).then(function (res) { + var answer = JSON.parse(res.body) + self.log(JSON.stringify(answer,null,4)) + if (callback) + callback() + return answer + }) + } + }) +} \ No newline at end of file From a3e5cf75314620e43ae0b1ac5d3da5dc96d8e824 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Dec 2018 18:19:22 +0300 Subject: [PATCH 2/4] adding `node` methods, reformating --- ops/rpc_server.js | 60 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/ops/rpc_server.js b/ops/rpc_server.js index b3e80f9..3585bec 100644 --- a/ops/rpc_server.js +++ b/ops/rpc_server.js @@ -22,7 +22,7 @@ module.exports = function (vorpal) { var cmd = 'get address ' var err = null var data = {success: false} - if (!args.length || args.length>1) { + if (!args.length || args.length > 1) { err = this.error(-32602) reject(err) } else { @@ -52,7 +52,7 @@ module.exports = function (vorpal) { var cmd = 'get block ' var err = null var data = {success: false} - if (!args.length || args.length>1) { + if (!args.length || args.length > 1) { err = this.error(-32602) reject(err) } else { @@ -82,7 +82,7 @@ module.exports = function (vorpal) { var cmd = 'get delegate ' var err = null var data = {success: false} - if (!args.length || args.length>1) { + if (!args.length || args.length > 1) { err = this.error(-32602) reject(err) } else { @@ -112,7 +112,7 @@ module.exports = function (vorpal) { var cmd = 'get transaction ' var err = null var data = {success: false} - if (!args.length || args.length>1) { + if (!args.length || args.length > 1) { err = this.error(-32602) reject(err) } else { @@ -141,7 +141,7 @@ module.exports = function (vorpal) { var cmd = 'get transactions ' var err = null var data = {success: false} - if (!args.length || args.length>1) { + if (!args.length || args.length > 1) { err = this.error(-32602) reject(err) } else { @@ -194,6 +194,56 @@ module.exports = function (vorpal) { } }) }, + nodeHeight: function (args) { + return new Promise(function (resolve, reject) { + var cmd = 'node height ' + var err = null + var data = {success: false} + + data = vorpal.execSync(cmd) + data.then(function (data) { + if (data) { + if (data.success === false) { + err = server.error(1, data.error) + } else { + data = data.height + } + } + if (err) + reject(err) + else + resolve(data) + }).catch(function (err) { + reject(err) + }) + + }) + }, + nodeVersion: function (args) { + return new Promise(function (resolve, reject) { + var cmd = 'node version ' + var err = null + var data = {success: false} + + data = vorpal.execSync(cmd) + data.then(function (data) { + if (data) { + if (data.success === false) { + err = server.error(1, data.error) + } else { + data = {commit: data.commit, version: data.version} + } + } + if (err) + reject(err) + else + resolve(data) + }).catch(function (err) { + reject(err) + }) + + }) + }, sendTokens: function (args) { return new Promise(function (resolve, reject) { var cmd = 'send tokens ' From 670f2730269613f697862cb4b7e44f207a999e36 Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Dec 2018 18:33:37 +0300 Subject: [PATCH 3/4] Adding `client version` command --- ops/client_version.js | 17 +++++++++++++++++ ops/rpc_server.js | 9 +++++++++ 2 files changed, 26 insertions(+) create mode 100644 ops/client_version.js diff --git a/ops/client_version.js b/ops/client_version.js new file mode 100644 index 0000000..d87f4ac --- /dev/null +++ b/ops/client_version.js @@ -0,0 +1,17 @@ +/* + +*/ +const package = require('../package.json') +module.exports = function (vorpal) { + return vorpal.command('client version').description('Shows adamant-console version').action(function (args, callback) { + answer = { + success: true, + version: package.version + } + this.log(JSON.stringify(answer, null, 4)) + if (callback) + callback() + else + return answer + }); +}; \ No newline at end of file diff --git a/ops/rpc_server.js b/ops/rpc_server.js index 3585bec..78454e5 100644 --- a/ops/rpc_server.js +++ b/ops/rpc_server.js @@ -17,6 +17,15 @@ module.exports = function (vorpal) { } else resolve(data.account); }) }, + clientVersion: function (args) { + return new Promise(function (resolve, reject) { + var cmd = 'client version ' + var err = null + var data = {success: false} + data = vorpal.execSync(cmd) + resolve(data.version) + }) + }, getAddress: function (args) { return new Promise(function (resolve, reject) { var cmd = 'get address ' From df981d8e86b7493c616890683cc0a0078fa0490b Mon Sep 17 00:00:00 2001 From: Zyuhel Date: Thu, 6 Dec 2018 18:33:57 +0300 Subject: [PATCH 4/4] Change version to 1.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eaa1a1a..36ed27a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "adamant-console", - "version": "1.4.0", + "version": "1.4.1", "description": "console tools for ADAMANT.im", "main": "index.js", "dependencies": {