Skip to content
This repository was archived by the owner on Sep 18, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions logic/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down Expand Up @@ -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);

Expand All @@ -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
};
15 changes: 15 additions & 0 deletions routes/v1/bitcoind/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions services/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -109,6 +112,7 @@ function help() {
}

module.exports = {
getMiningInfo,
getBlockHash,
getBlock,
getTransaction,
Expand Down