-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Adamant-im/rpc-server
Rpc server
- Loading branch information
Showing
4 changed files
with
135 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <type>').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 | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters