Skip to content
This repository was archived by the owner on Sep 18, 2022. It is now read-only.

Commit db41e5d

Browse files
Merge pull request #10 from nolim1t/mempool-and-blockchaininfo
Expose mempoolinfo and blockchaininfo
2 parents af60c69 + 7f149c6 commit db41e5d

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

logic/bitcoind.js

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function getLocalSyncInfo() {
7777
return {
7878
percent: percentSynced,
7979
currentBlock: blockCount,
80-
headerCount: headerCount // eslint-disable-line object-shorthand
80+
headerCount: headerCount // eslint-disable-line object-shorthand,
8181
};
8282
}
8383

@@ -130,6 +130,12 @@ async function getTransaction(txid) {
130130
}
131131
}
132132

133+
async function getNetworkInfo() {
134+
const networkInfo = await bitcoindService.getNetworkInfo();
135+
136+
return networkInfo.result; // eslint-disable-line object-shorthand
137+
}
138+
133139
async function getBlockHash(height) {
134140
const getBlockHashObj = await bitcoindService.getBlockHash(height);
135141

@@ -138,14 +144,46 @@ async function getBlockHash(height) {
138144
}
139145
}
140146

147+
async function nodeStatusDump() {
148+
const blockchainInfo = await bitcoindService.getBlockChainInfo();
149+
const networkInfo = await bitcoindService.getNetworkInfo();
150+
const mempoolInfo = await bitcoindService.getMempoolInfo();
151+
const miningInfo = await bitcoindService.getMiningInfo();
152+
153+
return {
154+
blockchain_info: blockchainInfo.result,
155+
network_info: networkInfo.result,
156+
mempool: mempoolInfo.result,
157+
mining_info: miningInfo.result
158+
}
159+
}
160+
161+
async function nodeStatusSummary() {
162+
const blockchainInfo = await bitcoindService.getBlockChainInfo();
163+
const networkInfo = await bitcoindService.getNetworkInfo();
164+
const mempoolInfo = await bitcoindService.getMempoolInfo();
165+
const miningInfo = await bitcoindService.getMiningInfo();
166+
167+
return {
168+
difficulty: blockchainInfo.result.difficulty,
169+
size: blockchainInfo.result.sizeOnDisk,
170+
mempool: mempoolInfo.result.bytes,
171+
connections: networkInfo.result.connections,
172+
networkhashps: miningInfo.result.networkhashps
173+
}
174+
}
175+
141176
module.exports = {
142177
getBlockHash,
143178
getTransaction,
144179
getBlock,
145180
getBlockCount,
146181
getConnectionsCount,
182+
getNetworkInfo,
147183
getMempoolInfo,
148184
getStatus,
149185
getSyncStatus,
150-
getVersion
186+
getVersion,
187+
nodeStatusDump,
188+
nodeStatusSummary
151189
};

routes/v1/bitcoind/info.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ const bitcoind = require('logic/bitcoind.js');
55
const auth = require('middlewares/auth.js');
66
const safeHandler = require('utils/safeHandler');
77

8+
router.get('/mempool', auth.jwt, safeHandler((req, res) =>
9+
bitcoind.getMempoolInfo()
10+
.then(mempool => res.json(mempool.result))
11+
));
12+
813
router.get('/addresses', auth.jwt, safeHandler((req, res) =>
914
networkLogic.getBitcoindAddresses()
1015
.then(addresses => res.json(addresses))
@@ -35,6 +40,16 @@ router.get('/version', auth.jwt, safeHandler((req, res) =>
3540
.then(version => res.json(version))
3641
));
3742

43+
router.get('/statsDump', auth.jwt, safeHandler((req, res) =>
44+
bitcoind.nodeStatusDump()
45+
.then(statusdump => res.json(statusdump))
46+
));
47+
48+
router.get('/stats', auth.jwt, safeHandler((req, res) =>
49+
bitcoind.nodeStatusSummary()
50+
.then(statussumarry => res.json(statussumarry))
51+
));
52+
3853
router.get('/block', auth.jwt, safeHandler((req, res) => {
3954
if (req.query.hash !== undefined && req.query.hash !== null) {
4055
bitcoind.getBlock(req.query.hash)

services/bitcoind.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ function getNetworkInfo() {
9696
return promiseify(rpcClient, rpcClient.getNetworkInfo, 'network info');
9797
}
9898

99+
function getMiningInfo() {
100+
return promiseify(rpcClient, rpcClient.getMiningInfo, 'mining info');
101+
}
99102
function help() {
100103
// TODO: missing from the library, but can add it not sure how to package.
101104
// rpc.uptime(function (err, res) {
@@ -109,6 +112,7 @@ function help() {
109112
}
110113

111114
module.exports = {
115+
getMiningInfo,
112116
getBlockHash,
113117
getBlock,
114118
getTransaction,

0 commit comments

Comments
 (0)