Browse Source

Fix #16

- remove use of deprecated getinfo RPC
- more info about status of IBD
- minor UI tweaks
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
8ced42a1f4
  1. 25
      app/rpcApi.js
  2. 25
      routes/baseActionsRouter.js
  3. 3
      views/index.pug
  4. 41
      views/node-info.pug

25
app/rpcApi.js

@ -35,9 +35,11 @@ var genesisCoinbaseTransaction = {
"blocktime": 1230988505 "blocktime": 1230988505
}; };
function getInfo() {
function getBlockchainInfo() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
client.cmd('getinfo', function(err, result, resHeaders) { client.cmd('getblockchaininfo', function(err, result, resHeaders) {
if (err) { if (err) {
console.log("Error 3207fh0f: " + err); console.log("Error 3207fh0f: " + err);
@ -51,6 +53,22 @@ function getInfo() {
}); });
} }
function getNetworkInfo() {
return new Promise(function(resolve, reject) {
client.cmd('getnetworkinfo', function(err, result, resHeaders) {
if (err) {
console.log("Error 239r7ger7gy: " + err);
reject(err);
return;
}
resolve(result);
});
});
}
function getMempoolInfo() { function getMempoolInfo() {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
client.cmd('getmempoolinfo', function(err, result, resHeaders) { client.cmd('getmempoolinfo', function(err, result, resHeaders) {
@ -394,7 +412,8 @@ function getBlockData(rpcClient, blockHash, txLimit, txOffset) {
} }
module.exports = { module.exports = {
getInfo: getInfo, getBlockchainInfo: getBlockchainInfo,
getNetworkInfo: getNetworkInfo,
getMempoolInfo: getMempoolInfo, getMempoolInfo: getMempoolInfo,
getBlockByHeight: getBlockByHeight, getBlockByHeight: getBlockByHeight,
getBlocksByHeight: getBlocksByHeight, getBlocksByHeight: getBlocksByHeight,

25
routes/baseActionsRouter.js

@ -29,13 +29,13 @@ router.get("/", function(req, res) {
var client = global.client; var client = global.client;
rpcApi.getInfo().then(function(getinfo) { rpcApi.getBlockchainInfo().then(function(getblockchaininfo) {
res.locals.getinfo = getinfo; res.locals.getblockchaininfo = getblockchaininfo;
var blockHeights = []; var blockHeights = [];
if (getinfo.blocks) { if (getblockchaininfo.blocks) {
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
blockHeights.push(getinfo.blocks - i); blockHeights.push(getblockchaininfo.blocks - i);
} }
} }
@ -54,10 +54,21 @@ router.get("/", function(req, res) {
router.get("/node-info", function(req, res) { router.get("/node-info", function(req, res) {
var client = global.client; var client = global.client;
rpcApi.getInfo().then(function(getinfo) { rpcApi.getBlockchainInfo().then(function(getblockchaininfo) {
res.locals.getinfo = getinfo; res.locals.getblockchaininfo = getblockchaininfo;
res.render("node-info"); rpcApi.getNetworkInfo().then(function(getnetworkinfo) {
res.locals.getnetworkinfo = getnetworkinfo;
res.render("node-info");
}).catch(function(err) {
res.locals.userMessage = "Unable to connect to Bitcoin Node at " + env.bitcoind.host + ":" + env.bitcoind.port;
res.render("node-info");
});
}).catch(function(err) { }).catch(function(err) {
res.locals.userMessage = "Unable to connect to Bitcoin Node at " + env.bitcoind.host + ":" + env.bitcoind.port; res.locals.userMessage = "Unable to connect to Bitcoin Node at " + env.bitcoind.host + ":" + env.bitcoind.port;

3
views/index.pug

@ -13,6 +13,9 @@ block content
if (latestBlocks) if (latestBlocks)
h3 Latest Blocks h3 Latest Blocks
if (getblockchaininfo.initialblockdownload)
small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind)
- var blocks = latestBlocks; - var blocks = latestBlocks;
- var blockOffset = 0; - var blockOffset = 0;

41
views/node-info.pug

@ -7,9 +7,11 @@ block content
h1 Node Info h1 Node Info
hr hr
if (getinfo) if (getblockchaininfo)
p Data from RPC command p Data from RPC commands
a(href="https://bitcoin.org/en/developer-reference#getinfo") getinfo a(href="https://bitcoin.org/en/developer-reference#getblockchaininfo") getblockchaininfo
span and
a(href="https://bitcoin.org/en/developer-reference#getnetworkinfo") getnetworkinfo
if (false) if (false)
pre pre
@ -17,34 +19,45 @@ block content
if (true) if (true)
table(class="table") table(class="table")
tr
th(class="table-active properties-header") Chain
td(class="monospace") #{getblockchaininfo.chain}
tr tr
th(class="table-active properties-header") Version th(class="table-active properties-header") Version
td(class="monospace") #{getinfo.version} td(class="monospace") #{getnetworkinfo.version}
tr tr
th(class="table-active properties-header") Protocol Version th(class="table-active properties-header") Protocol Version
td(class="monospace") #{getinfo.protocolversion} td(class="monospace") #{getnetworkinfo.protocolversion}
tr tr
th(class="table-active properties-header") Connections th(class="table-active properties-header") Connections
td(class="monospace") #{getinfo.connections.toLocaleString()} td(class="monospace") #{getnetworkinfo.connections.toLocaleString()}
tr tr
th(class="table-active properties-header") Block Count th(class="table-active properties-header") Block Count
td(class="monospace") #{getinfo.blocks.toLocaleString()} td(class="monospace") #{getblockchaininfo.blocks.toLocaleString()}
tr
th(class="table-active properties-header") Testnet?
td(class="monospace") #{getinfo.testnet}
tr tr
th(class="table-active properties-header") Errors th(class="table-active properties-header") Header Count
td(class="monospace") #{getinfo.errors} td(class="monospace") #{getblockchaininfo.headers.toLocaleString()}
tr tr
- var scales = [ {val:1000000000000000, name:"quadrillion"}, {val:1000000000000, name:"trillion"}, {val:1000000000, name:"billion"}, {val:1000000, name:"million"} ]; - var scales = [ {val:1000000000000000, name:"quadrillion"}, {val:1000000000000, name:"trillion"}, {val:1000000000, name:"billion"}, {val:1000000, name:"million"} ];
- var scaleDone = false; - var scaleDone = false;
th(class="table-active properties-header") Difficulty th(class="table-active properties-header") Difficulty
td(class="monospace") td(class="monospace")
span #{getinfo.difficulty.toLocaleString()} span #{getblockchaininfo.difficulty.toLocaleString()}
each item in scales each item in scales
if (!scaleDone) if (!scaleDone)
- var fraction = Math.floor(getinfo.difficulty / item.val); - var fraction = Math.floor(getblockchaininfo.difficulty / item.val);
if (fraction >= 1) if (fraction >= 1)
- scaleDone = true; - scaleDone = true;
span(class="text-muted") (#{fraction} #{item.name}) span(class="text-muted") (#{fraction} #{item.name})
tr
th(class="table-active properties-header") Status
td(class="monospace")
if (getblockchaininfo.initialblockdownload)
span Initial block download progress #{(100 * getblockchaininfo.verificationprogress).toLocaleString()}%
else
span Up-to-date
tr
th(class="table-active properties-header") Warnings
td(class="monospace") #{getblockchaininfo.warnings}
Loading…
Cancel
Save