From 77d6ebd938d8c59cc2f299032614cd954a3ebe83 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Tue, 8 Aug 2017 11:59:19 -0400 Subject: [PATCH] show basic mempool info on homepage tab --- app/rpcApi.js | 13 +++++++++++++ routes/baseActionsRouter.js | 22 +++++++++++++--------- views/index.pug | 11 +++++++++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/rpcApi.js b/app/rpcApi.js index 58fa515..b28515a 100644 --- a/app/rpcApi.js +++ b/app/rpcApi.js @@ -45,6 +45,18 @@ function getInfo() { }); } +function getMempoolInfo() { + return new Promise(function(resolve, reject) { + client.cmd('getmempoolinfo', function(err, result, resHeaders) { + if (err) { + return console.log("Error 23407rhwe07fg: " + err); + } + + resolve(result); + }); + }); +} + function getBlockByHeight(blockHeight) { console.log("getBlockByHeight: " + blockHeight); @@ -260,6 +272,7 @@ function getBlockData(rpcClient, blockHash, txLimit, txOffset) { module.exports = { getInfo: getInfo, + getMempoolInfo: getMempoolInfo, getBlockByHeight: getBlockByHeight, getBlocksByHeight: getBlocksByHeight, getBlockByHash: getBlockByHash, diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index b3c22e3..ce6775e 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -31,19 +31,23 @@ router.get("/", function(req, res) { var client = global.client; rpcApi.getInfo().then(function(getinfo) { - res.locals.result = getinfo; + res.locals.getinfo = getinfo; - var blockHeights = []; - if (getinfo.blocks) { - for (var i = 0; i < 10; i++) { - blockHeights.push(getinfo.blocks - i); + rpcApi.getMempoolInfo().then(function(getmempoolinfo) { + res.locals.getmempoolinfo = getmempoolinfo; + + var blockHeights = []; + if (getinfo.blocks) { + for (var i = 0; i < 10; i++) { + blockHeights.push(getinfo.blocks - i); + } } - } - rpcApi.getBlocksByHeight(blockHeights).then(function(latestBlocks) { - res.locals.latestBlocks = latestBlocks; + rpcApi.getBlocksByHeight(blockHeights).then(function(latestBlocks) { + res.locals.latestBlocks = latestBlocks; - res.render("index"); + res.render("index"); + }); }); }); }); diff --git a/views/index.pug b/views/index.pug index 990d97a..e8c51ad 100644 --- a/views/index.pug +++ b/views/index.pug @@ -18,6 +18,8 @@ block content a(data-toggle="tab", href="#tab-latest-tx", class="nav-link active", role="tab") Latest Blocks li(class="nav-item") a(data-toggle="tab", href="#tab-getinfo", class="nav-link", role="tab") Node Info + li(class="nav-item") + a(data-toggle="tab", href="#tab-getmempoolinfo", class="nav-link", role="tab") Mempool Info div(class="tab-content") div(id="tab-latest-tx", class="tab-pane active", role="tabpanel") @@ -32,6 +34,11 @@ block content a(href="/blocks", class="btn btn-primary btn-block") See more div(id="tab-getinfo", class="tab-pane", role="tabpanel") - h3 Node Info (getinfo) + h3 Node Info + pre + code #{JSON.stringify(getinfo, null, 4)} + + div(id="tab-getmempoolinfo", class="tab-pane", role="tabpanel") + h3 Mempool Info pre - code #{JSON.stringify(result, null, 4)} \ No newline at end of file + code #{JSON.stringify(getmempoolinfo, null, 4)} \ No newline at end of file