diff --git a/README.md b/README.md index 288dad3..816bedc 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,7 @@ Table of Contents - **getblock:** Returns an object with information about the block - **getrawtransaction:** Returns raw transaction data - **getinfo:** Returns an object containing various state info + - **getblockchaininfo:** Returns an object containing various state info regarding blockchain processing - **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 - **getvotelist:** Returns an object with details regarding the current vote list diff --git a/lib/explorer.js b/lib/explorer.js index def5af1..e26f951 100644 --- a/lib/explorer.js +++ b/lib/explorer.js @@ -908,6 +908,34 @@ module.exports = { // cmd not in use. return null. return cb(null); } + } else if (settings.sync.supply == 'GETBLOCKCHAININFO') { + // attempt to get the supply from the getblockchaininfo or similar api cmd that returns and object containing various state info. Must include a value called "moneysupply" which represents the current running total of coins + var cmd = prepareRpcCommand(settings.api_cmds.getblockchaininfo); + + if (!(cmd.method == '' && cmd.parameters.length == 0)) { + if (settings.api_cmds.use_rpc) { + rpcCommand([{method:cmd.method, parameters: cmd.parameters}], function(response) { + // check if an error msg was received from the rpc server + if (!response || !response.moneysupply || response == 'There was an error. Check your console.') + return cb(null); + else + return cb(response.moneysupply); + }); + } else { + var uri = base_url + 'getblockchaininfo'; + + request({uri: uri, json: true}, function (error, response, body) { + // check if an error msg was received from the web api server + if (!body || !body.moneysupply ||body == 'There was an error. Check your console.') + return cb(null); + else + return cb(body.moneysupply); + }); + } + } else { + // cmd not in use. return null. + return cb(null); + } } else { // returns coinbase total sent as current coin supply coinbase_supply(function(supply) { diff --git a/lib/nodeapi.js b/lib/nodeapi.js index cb7c9c6..ebb56e0 100644 --- a/lib/nodeapi.js +++ b/lib/nodeapi.js @@ -43,6 +43,7 @@ module.exports = function() { case 'getrawtransaction': case 'getsupply': case 'getinfo': + case 'getblockchaininfo': case 'getpeerinfo': case 'gettxoutsetinfo': case 'getmaxmoney': @@ -156,6 +157,7 @@ module.exports = function() { case 'getconnectioncount': case 'getblockcount': case 'getinfo': + case 'getblockchaininfo': case 'getpeerinfo': case 'gettxoutsetinfo': case 'getvotelist': diff --git a/lib/settings.js b/lib/settings.js index 2e0b881..3c1e98f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -1123,6 +1123,7 @@ exports.sync = { // Valid options: // COINBASE : retrieve the total coins sent from the coinbase (Often used for PoW coins) // GETINFO : retrieved from getinfo rpc cmd (Often used for PoS coins) + // GETBLOCKCHAININFO : retrieved from getblockchaininfo rpc cmd // HEAVY: retrieved from getsupply rpc cmd (The "blockchain_specific.heavycoin.enabled" setting must be set to true and the "blockchain_specific.heavycoin.api_cmds.getsupply" setting must be set up correctly for this option to work properly) // BALANCES : get the supply by running a query on the addresses collection and summing up all positive balances (potentially a long running query for blockchains with tons of addresses) // TXOUTSET : retrieved from gettxoutsetinfo rpc cmd @@ -1160,6 +1161,8 @@ exports.api_cmds = { "getrawtransaction": "getrawtransaction", // getinfo: Returns an object containing various state info "getinfo": "getinfo", + // getblockchaininfo: Returns an object containing various state info regarding blockchain processing + "getblockchaininfo": "getblockchaininfo", // getpeerinfo: Returns data about each connected network node as a json array of objects "getpeerinfo": "getpeerinfo", // gettxoutsetinfo: Returns an object with statistics about the unspent transaction output set diff --git a/settings.json.template b/settings.json.template index e91b9b0..cd0ff51 100644 --- a/settings.json.template +++ b/settings.json.template @@ -1207,6 +1207,7 @@ // Valid options: // COINBASE : retrieve the total coins sent from the coinbase (Often used for PoW coins) // GETINFO : retrieved from getinfo rpc cmd (Often used for PoS coins) + // GETBLOCKCHAININFO : retrieved from getblockchaininfo rpc cmd // HEAVY: retrieved from getsupply rpc cmd (The "blockchain_specific.heavycoin.enabled" setting must be set to true and the "blockchain_specific.heavycoin.api_cmds.getsupply" setting must be set up correctly for this option to work properly) // BALANCES : get the supply by running a query on the addresses collection and summing up all positive balances (potentially a long running query for blockchains with tons of addresses) // TXOUTSET : retrieved from gettxoutsetinfo rpc cmd @@ -1277,6 +1278,8 @@ "getrawtransaction": "getrawtransaction", // getinfo: Returns an object containing various state info "getinfo": "getinfo", + // getblockchaininfo: Returns an object containing various state info regarding blockchain processing + "getblockchaininfo": "getblockchaininfo", // getpeerinfo: Returns data about each connected network node as a json array of objects "getpeerinfo": "getpeerinfo", // gettxoutsetinfo: Returns an object with statistics about the unspent transaction output set