diff --git a/README.md b/README.md index 437a0d4..495ba27 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,6 @@ This project is a fork of [Ciquidus Explorer](https://github.com/suprnurd/ciquid - **getinfo:** Returns an object containing various state info - **getpeerinfo:** Returns data about each connected network node as a json array of objects - **gettxoutsetinfo:** Returns an object with statistics about the unspent transaction output set - - **getsupply:** Returns the current money supply - - **getmaxmoney:** Returns the number of coins that will be produced in total - - **getmaxvote:** Returns the maximum allowed vote for the current phase of voting - - **getvote:** Returns the current block reward vote setting - - **getphase:** Returns the current voting phase name - - **getreward:** Returns the current block reward - - **getnextrewardestimate:** Returns an estimate for the next block reward based on the current state of decentralized voting - - **getnextrewardwhenstr:** Returns a string describing how long until the votes are tallied and the next block reward is computed - **getvotelist:** Returns an object with details regarding the current vote list - **getmasternodecount:** Returns a json object containing the total number of masternodes on the network - **getmasternodelist:** Returns a json array containing status information for all masternodes on the network @@ -46,6 +38,15 @@ This project is a fork of [Ciquidus Explorer](https://github.com/suprnurd/ciquid - **address:** The wallet address to use for the signature. - **signature:** The signature provided by the signer in base 64 encoding. - **message:** The message that was signed. +- Support for additional heavy rpc/api cmds: + - **getmaxmoney:** Returns the number of coins that will be produced in total + - **getmaxvote:** Returns the maximum allowed vote for the current phase of voting + - **getvote:** Returns the current block reward vote setting + - **getphase:** Returns the current voting phase name + - **getreward:** Returns the current block reward + - **getnextrewardestimate:** Returns an estimate for the next block reward based on the current state of decentralized voting + - **getnextrewardwhenstr:** Returns a string describing how long until the votes are tallied and the next block reward is computed + - **getsupply:** Returns the current money supply ### See it in action diff --git a/app.js b/app.js index 6941420..9b3e90d 100644 --- a/app.js +++ b/app.js @@ -14,31 +14,24 @@ var express = require('express') , request = require('postman-request'); var app = express(); +var apiAccessList = []; -// nodeapi +// pass wallet rpc connection info to nodeapi nodeapi.setWalletDetails(settings.wallet); -if (settings.heavy != true) { - nodeapi.setAccess('only', ['getinfo', 'getnetworkhashps', 'getmininginfo','getdifficulty', 'getconnectioncount', - 'getmasternodecount', 'getmasternodelist', 'getvotelist', 'getblockcount', 'getblockhash', 'getblock', 'getrawtransaction', - 'getpeerinfo', 'gettxoutsetinfo', 'verifymessage']); -} else { - // enable additional heavy api calls - /* - getvote - Returns the current block reward vote setting. - getmaxvote - Returns the maximum allowed vote for the current phase of voting. - getphase - Returns the current voting phase ('Mint', 'Limit' or 'Sustain'). - getreward - Returns the current block reward, which has been decided democratically in the previous round of block reward voting. - getnextrewardestimate - Returns an estimate for the next block reward based on the current state of decentralized voting. - getnextrewardwhenstr - Returns string describing how long until the votes are tallied and the next block reward is computed. - getnextrewardwhensec - Same as above, but returns integer seconds. - getsupply - Returns the current money supply. - getmaxmoney - Returns the maximum possible money supply. - */ - nodeapi.setAccess('only', ['getinfo', 'getstakinginfo', 'getnetworkhashps', 'getdifficulty', 'getconnectioncount', - 'getmasternodecount', 'getmasternodelist', 'getvotelist', 'getblockcount', 'getblockhash', - 'getblock', 'getrawtransaction', 'getmaxmoney', 'getvote', 'getmaxvote', 'getphase', 'getreward', 'getpeerinfo', - 'getnextrewardestimate', 'getnextrewardwhenstr', 'getnextrewardwhensec', 'getsupply', 'gettxoutsetinfo', 'verifymessage']); +// dynamically build the nodeapi cmd access list by adding all non-heavy api cmds that have a value +Object.keys(settings.api_cmds).forEach(function(key, index, map) { + if (key != 'heavies' && settings.api_cmds[key] != null && settings.api_cmds[key] != '') + apiAccessList.push(key); +}); +if (settings.heavy) { + // add all heavy api cmds that have a value + Object.keys(settings.api_cmds.heavies).forEach(function(key, index, map) { + if (settings.api_cmds.heavies[key] != null && settings.api_cmds.heavies[key] != '') + apiAccessList.push(key); + }); } +// whitelist the cmds in the nodeapi access list +nodeapi.setAccess('only', apiAccessList); // determine if cors should be enabled if (settings.usecors == true) { app.use(function(req, res, next) { diff --git a/lib/explorer.js b/lib/explorer.js index 0a99069..9063864 100644 --- a/lib/explorer.js +++ b/lib/explorer.js @@ -389,7 +389,7 @@ module.exports = { }, get_maxmoney: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getmaxmoney); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getmaxmoney); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -417,7 +417,7 @@ module.exports = { }, get_maxvote: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getmaxvote); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getmaxvote); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -445,7 +445,7 @@ module.exports = { }, get_vote: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getvote); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getvote); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -473,7 +473,7 @@ module.exports = { }, get_phase: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getphase); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getphase); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -501,7 +501,7 @@ module.exports = { }, get_reward: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getreward); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getreward); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -529,7 +529,7 @@ module.exports = { }, get_estnext: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getnextrewardestimate); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getnextrewardestimate); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -557,7 +557,7 @@ module.exports = { }, get_nextin: function(cb) { - var cmd = prepareRpcCommand(settings.api_cmds.getnextrewardwhenstr); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getnextrewardwhenstr); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { @@ -642,7 +642,7 @@ module.exports = { get_supply: function(cb) { if (settings.supply == 'HEAVY') { // attempt to get the supply from the getsupply or similar api cmd that returns the current money supply as a single positive decimal value - var cmd = prepareRpcCommand(settings.api_cmds.getsupply); + var cmd = prepareRpcCommand(settings.api_cmds.heavies.getsupply); if (!(cmd.method == '' && cmd.parameters.length == 0)) { if (settings.use_rpc) { diff --git a/lib/nodeapi.js b/lib/nodeapi.js index f7370e4..5113180 100644 --- a/lib/nodeapi.js +++ b/lib/nodeapi.js @@ -125,10 +125,16 @@ module.exports = function(){ case 'getdifficulty': case 'getconnectioncount': case 'getblockcount': - case 'getsupply': case 'getinfo': case 'getpeerinfo': case 'gettxoutsetinfo': + case 'getvotelist': + case 'getmasternodecount': + case 'getmasternodelist': + var cmd = prepareRpcCommand(settings.api_cmds[method_name]); + method_name = cmd.method; + params = cmd.parameters; + break; case 'getmaxmoney': case 'getmaxvote': case 'getvote': @@ -136,10 +142,8 @@ module.exports = function(){ case 'getreward': case 'getnextrewardestimate': case 'getnextrewardwhenstr': - case 'getvotelist': - case 'getmasternodecount': - case 'getmasternodelist': - var cmd = prepareRpcCommand(settings.api_cmds[method_name]); + case 'getsupply': + var cmd = prepareRpcCommand(settings.api_cmds.heavies[method_name]); method_name = cmd.method; params = cmd.parameters; break; diff --git a/lib/settings.js b/lib/settings.js index 0b5731f..5f5945c 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -196,18 +196,20 @@ exports.api_cmds = { "getinfo": "getinfo", "getpeerinfo": "getpeerinfo", "gettxoutsetinfo": "gettxoutsetinfo", - "getsupply": "getsupply", - "getmaxmoney": "getmaxmoney", - "getmaxvote": "getmaxvote", - "getvote": "getvote", - "getphase": "getphase", - "getreward": "getreward", - "getnextrewardestimate": "getnextrewardestimate", - "getnextrewardwhenstr": "getnextrewardwhenstr", "getvotelist": "masternodelist votes", "getmasternodecount": "getmasternodecount", "getmasternodelist": "listmasternodes", - "verifymessage": "verifymessage" + "verifymessage": "verifymessage", + "heavies": { + "getmaxmoney": "getmaxmoney", + "getmaxvote": "getmaxvote", + "getvote": "getvote", + "getphase": "getphase", + "getreward": "getreward", + "getnextrewardestimate": "getnextrewardestimate", + "getnextrewardwhenstr": "getnextrewardwhenstr", + "getsupply": "getsupply" + } }; exports.reloadSettings = function reloadSettings() { diff --git a/settings.json.template b/settings.json.template index 4a11312..43fef32 100644 --- a/settings.json.template +++ b/settings.json.template @@ -271,21 +271,23 @@ // getinfo: Returns an object containing various state info. // getpeerinfo: Returns data about each connected network node as a json array of objects. // gettxoutsetinfo: Returns an object with statistics about the unspent transaction output set. - // getsupply: Returns the current money supply. This should be a positive whole or decimal number. - // getmaxmoney: Returns the number of coins that will be produced in total. This should be a positive whole or decimal number. - // getmaxvote: Returns the maximum allowed vote for the current phase of voting. This should be a positive whole number. - // getvote: Returns the current block reward vote setting. This should be a positive whole number. - // getphase: Returns the current voting phase name. This should be a string value. - // getreward: Returns the current block reward. This should be a positive whole or decimal number. - // getnextrewardestimate: Returns an estimate for the next block reward based on the current state of decentralized voting. This should be a positive whole or decimal number. - // getnextrewardwhenstr: Returns a string describing how long until the votes are tallied and the next block reward is computed. // getvotelist: Returns an object with details regarding the current vote list. // getmasternodecount: Returns a json object containing the total number of masternodes on the network. // getmasternodelist: Returns a json array containing status information for all masternodes on the network. // verifymessage: Verify a signed message. Must accept the following arguments: - // address: The wallet address to use for the signature. - // signature: The signature provided by the signer in base 64 encoding. - // message: The message that was signed. + // address: The wallet address to use for the signature. + // signature: The signature provided by the signer in base 64 encoding. + // message: The message that was signed. + // + // heavies: A collection of commands that are enabled when the "heavy" setting is set to "true" + // getmaxmoney: Returns the number of coins that will be produced in total. This should be a positive whole or decimal number. + // getmaxvote: Returns the maximum allowed vote for the current phase of voting. This should be a positive whole number. + // getvote: Returns the current block reward vote setting. This should be a positive whole number. + // getphase: Returns the current voting phase name. This should be a string value. + // getreward: Returns the current block reward. This should be a positive whole or decimal number. + // getnextrewardestimate: Returns an estimate for the next block reward based on the current state of decentralized voting. This should be a positive whole or decimal number. + // getnextrewardwhenstr: Returns a string describing how long until the votes are tallied and the next block reward is computed. + // getsupply: Returns the current money supply. This should be a positive whole or decimal number. "api_cmds": { "getnetworkhashps": "getnetworkhashps", "getmininginfo": "getmininginfo", @@ -298,17 +300,19 @@ "getinfo": "getinfo", "getpeerinfo": "getpeerinfo", "gettxoutsetinfo": "gettxoutsetinfo", - "getsupply": "getsupply", - "getmaxmoney": "getmaxmoney", - "getmaxvote": "getmaxvote", - "getvote": "getvote", - "getphase": "getphase", - "getreward": "getreward", - "getnextrewardestimate": "getnextrewardestimate", - "getnextrewardwhenstr": "getnextrewardwhenstr", "getvotelist": "masternodelist votes", "getmasternodecount": "getmasternodecount", - "getmasternodelist": "listmasternodes" - "verifymessage": "verifymessage" + "getmasternodelist": "listmasternodes", + "verifymessage": "verifymessage", + "heavies": { + "getmaxmoney": "getmaxmoney", + "getmaxvote": "getmaxvote", + "getvote": "getvote", + "getphase": "getphase", + "getreward": "getreward", + "getnextrewardestimate": "getnextrewardestimate", + "getnextrewardwhenstr": "getnextrewardwhenstr", + "getsupply": "getsupply" + } } } \ No newline at end of file diff --git a/views/info.pug b/views/info.pug index 006a254..95cf683 100644 --- a/views/info.pug +++ b/views/info.pug @@ -88,56 +88,56 @@ block content em #{settings.locale.api_getmasternodelist} a(href='/api/getmasternodelist') #{address}/api/getmasternodelist if settings.heavy == true - if settings.api_cmds['getmaxmoney'] != null && settings.api_cmds['getmaxmoney'] != '' + if settings.api_cmds.heavies['getmaxmoney'] != null && settings.api_cmds.heavies['getmaxmoney'] != '' li p div.font-weight-bold getmaxmoney div em #{settings.locale.api_getmaxmoney} a(href='/api/getmaxmoney') #{address}/api/getmaxmoney - if settings.api_cmds['getmaxvote'] != null && settings.api_cmds['getmaxvote'] != '' + if settings.api_cmds.heavies['getmaxvote'] != null && settings.api_cmds.heavies['getmaxvote'] != '' li p div.font-weight-bold getmaxvote div em #{settings.locale.api_getmaxvote} a(href='/api/getmaxvote') #{address}/api/getmaxvote - if settings.api_cmds['getvote'] != null && settings.api_cmds['getvote'] != '' + if settings.api_cmds.heavies['getvote'] != null && settings.api_cmds.heavies['getvote'] != '' li p div.font-weight-bold getvote div em #{settings.locale.api_getvote} a(href='/api/getvote') #{address}/api/getvote - if settings.api_cmds['getphase'] != null && settings.api_cmds['getphase'] != '' + if settings.api_cmds.heavies['getphase'] != null && settings.api_cmds.heavies['getphase'] != '' li p div.font-weight-bold getphase div em #{settings.locale.api_getphase} a(href='/api/getphase') #{address}/api/getphase - if settings.api_cmds['getreward'] != null && settings.api_cmds['getreward'] != '' + if settings.api_cmds.heavies['getreward'] != null && settings.api_cmds.heavies['getreward'] != '' li p div.font-weight-bold getreward div em #{settings.locale.api_getreward} a(href='/api/getreward') #{address}/api/getreward - if settings.api_cmds['getsupply'] != null && settings.api_cmds['getsupply'] != '' + if settings.api_cmds.heavies['getsupply'] != null && settings.api_cmds.heavies['getsupply'] != '' li p div.font-weight-bold getsupply div em #{settings.locale.api_getsupply} a(href='/api/getsupply') #{address}/api/getsupply - if settings.api_cmds['getnextrewardestimate'] != null && settings.api_cmds['getnextrewardestimate'] != '' + if settings.api_cmds.heavies['getnextrewardestimate'] != null && settings.api_cmds.heavies['getnextrewardestimate'] != '' li p div.font-weight-bold getnextrewardestimate div em #{settings.locale.api_getnextrewardestimate} a(href='/api/getnextrewardestimate') #{address}/api/getnextrewardestimate - if settings.api_cmds['getnextrewardwhenstr'] != null && settings.api_cmds['getnextrewardwhenstr'] != '' + if settings.api_cmds.heavies['getnextrewardwhenstr'] != null && settings.api_cmds.heavies['getnextrewardwhenstr'] != '' li p div.font-weight-bold getnextrewardwhenstr