diff --git a/logic/bitcoind.js b/logic/bitcoind.js index 03151de..31aee43 100644 --- a/logic/bitcoind.js +++ b/logic/bitcoind.js @@ -77,7 +77,7 @@ async function getLocalSyncInfo() { return { percent: percentSynced, currentBlock: blockCount, - headerCount: headerCount // eslint-disable-line object-shorthand + headerCount: headerCount // eslint-disable-line object-shorthand, }; } @@ -130,6 +130,12 @@ async function getTransaction(txid) { } } +async function getNetworkInfo() { + const networkInfo = await bitcoindService.getNetworkInfo(); + + return networkInfo.result; // eslint-disable-line object-shorthand +} + async function getBlockHash(height) { const getBlockHashObj = await bitcoindService.getBlockHash(height); @@ -138,14 +144,46 @@ async function getBlockHash(height) { } } +async function nodeStatusDump() { + const blockchainInfo = await bitcoindService.getBlockChainInfo(); + const networkInfo = await bitcoindService.getNetworkInfo(); + const mempoolInfo = await bitcoindService.getMempoolInfo(); + const miningInfo = await bitcoindService.getMiningInfo(); + + return { + blockchain_info: blockchainInfo.result, + network_info: networkInfo.result, + mempool: mempoolInfo.result, + mining_info: miningInfo.result + } +} + +async function nodeStatusSummary() { + const blockchainInfo = await bitcoindService.getBlockChainInfo(); + const networkInfo = await bitcoindService.getNetworkInfo(); + const mempoolInfo = await bitcoindService.getMempoolInfo(); + const miningInfo = await bitcoindService.getMiningInfo(); + + return { + difficulty: blockchainInfo.result.difficulty, + size: blockchainInfo.result.sizeOnDisk, + mempool: mempoolInfo.result.bytes, + connections: networkInfo.result.connections, + networkhashps: miningInfo.result.networkhashps + } +} + module.exports = { getBlockHash, getTransaction, getBlock, getBlockCount, getConnectionsCount, + getNetworkInfo, getMempoolInfo, getStatus, getSyncStatus, - getVersion + getVersion, + nodeStatusDump, + nodeStatusSummary }; diff --git a/routes/v1/bitcoind/info.js b/routes/v1/bitcoind/info.js index d37b0b7..2bc402b 100644 --- a/routes/v1/bitcoind/info.js +++ b/routes/v1/bitcoind/info.js @@ -5,6 +5,11 @@ const bitcoind = require('logic/bitcoind.js'); const auth = require('middlewares/auth.js'); const safeHandler = require('utils/safeHandler'); +router.get('/mempool', auth.jwt, safeHandler((req, res) => + bitcoind.getMempoolInfo() + .then(mempool => res.json(mempool.result)) +)); + router.get('/addresses', auth.jwt, safeHandler((req, res) => networkLogic.getBitcoindAddresses() .then(addresses => res.json(addresses)) @@ -35,6 +40,16 @@ router.get('/version', auth.jwt, safeHandler((req, res) => .then(version => res.json(version)) )); +router.get('/statsDump', auth.jwt, safeHandler((req, res) => + bitcoind.nodeStatusDump() + .then(statusdump => res.json(statusdump)) +)); + +router.get('/stats', auth.jwt, safeHandler((req, res) => + bitcoind.nodeStatusSummary() + .then(statussumarry => res.json(statussumarry)) +)); + router.get('/block', auth.jwt, safeHandler((req, res) => { if (req.query.hash !== undefined && req.query.hash !== null) { bitcoind.getBlock(req.query.hash) diff --git a/services/bitcoind.js b/services/bitcoind.js index 871208a..72b3efe 100644 --- a/services/bitcoind.js +++ b/services/bitcoind.js @@ -96,6 +96,9 @@ function getNetworkInfo() { return promiseify(rpcClient, rpcClient.getNetworkInfo, 'network info'); } +function getMiningInfo() { + return promiseify(rpcClient, rpcClient.getMiningInfo, 'mining info'); +} function help() { // TODO: missing from the library, but can add it not sure how to package. // rpc.uptime(function (err, res) { @@ -109,6 +112,7 @@ function help() { } module.exports = { + getMiningInfo, getBlockHash, getBlock, getTransaction,