From e6fd90eeb468e9678e6afeb385667d9e6405d0b4 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Sun, 11 Aug 2019 17:05:30 -0400 Subject: [PATCH] Add ancestors/descendants to tx details page, fixes #126 --- app/api/coreApi.js | 7 +++++ app/api/rpcApi.js | 55 ++++++++++++++++++++++++++++++++++--- routes/baseActionsRouter.js | 15 ++++++++++ views/transaction.pug | 41 +++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 4 deletions(-) diff --git a/app/api/coreApi.js b/app/api/coreApi.js index d1f9e18..52a3660 100644 --- a/app/api/coreApi.js +++ b/app/api/coreApi.js @@ -652,6 +652,12 @@ function getUtxo(txid, outputIndex) { }); } +function getMempoolTxDetails(txid) { + return tryCacheThenRpcApi(miscCache, "mempoolTxDetails-" + txid, 3600000, function() { + return rpcApi.getMempoolTxDetails(txid); + }); +} + function getAddress(address) { return tryCacheThenRpcApi(miscCache, "getAddress-" + address, 3600000, function() { return rpcApi.getAddress(address); @@ -930,6 +936,7 @@ module.exports = { getRawTransactions: getRawTransactions, getRawTransactionsWithInputs: getRawTransactionsWithInputs, getTxUtxos: getTxUtxos, + getMempoolTxDetails: getMempoolTxDetails, getMempoolStats: getMempoolStats, getUptimeSeconds: getUptimeSeconds, getHelp: getHelp, diff --git a/app/api/rpcApi.js b/app/api/rpcApi.js index d024156..4c654a2 100644 --- a/app/api/rpcApi.js +++ b/app/api/rpcApi.js @@ -140,21 +140,17 @@ function getUtxo(txid, outputIndex) { return new Promise(function(resolve, reject) { getRpcDataWithParams({method:"gettxout", parameters:[txid, outputIndex]}).then(function(result) { if (result == null) { - console.log("haha: " + JSON.stringify(result)); resolve("0"); return; } if (result.code && result.code < 0) { - console.log("haha2: " + JSON.stringify(result)); reject(result); return; } - console.log("haha3: " + JSON.stringify(result)); - resolve(result); }).catch(function(err) { @@ -163,6 +159,56 @@ function getUtxo(txid, outputIndex) { }); } +function getMempoolTxDetails(txid) { + debugLog("getMempoolTxDetails: %s", txid); + + var promises = []; + + var mempoolDetails = {}; + + promises.push(new Promise(function(resolve, reject) { + getRpcDataWithParams({method:"getmempoolentry", parameters:[txid]}).then(function(result) { + mempoolDetails.entry = result; + + resolve(); + + }).catch(function(err) { + reject(err); + }); + })); + + promises.push(new Promise(function(resolve, reject) { + getRpcDataWithParams({method:"getmempoolancestors", parameters:[txid]}).then(function(result) { + mempoolDetails.ancestors = result; + + resolve(); + + }).catch(function(err) { + reject(err); + }); + })); + + promises.push(new Promise(function(resolve, reject) { + getRpcDataWithParams({method:"getmempooldescendants", parameters:[txid]}).then(function(result) { + mempoolDetails.descendants = result; + + resolve(); + + }).catch(function(err) { + reject(err); + }); + })); + + return new Promise(function(resolve, reject) { + Promise.all(promises).then(function() { + resolve(mempoolDetails); + + }).catch(function(err) { + reject(err); + }); + }); +} + function getHelp() { return getRpcData("help"); } @@ -236,6 +282,7 @@ module.exports = { getBlockByHash: getBlockByHash, getRawTransaction: getRawTransaction, getUtxo: getUtxo, + getMempoolTxDetails: getMempoolTxDetails, getRawMempool: getRawMempool, getUptimeSeconds: getUptimeSeconds, getHelp: getHelp, diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index f4f6421..ed2f921 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -559,6 +559,21 @@ router.get("/tx/:transactionId", function(req, res, next) { }); })); + if (rawTxResult.confirmations == null) { + promises.push(new Promise(function(resolve, reject) { + coreApi.getMempoolTxDetails(txid).then(function(mempoolDetails) { + res.locals.mempoolDetails = mempoolDetails; + + resolve(); + + }).catch(function(err) { + res.locals.pageErrors.push(utils.logError("0q83hreuwgd", err)); + + reject(err); + }); + })); + } + promises.push(new Promise(function(resolve, reject) { client.command('getblock', rawTxResult.blockhash, function(err3, result3, resHeaders3) { res.locals.result.getblock = result3; diff --git a/views/transaction.pug b/views/transaction.pug index bba8ade..326bbc1 100644 --- a/views/transaction.pug +++ b/views/transaction.pug @@ -237,6 +237,41 @@ block content - blockHeight = result.getblock.height; include includes/transaction-io-details.pug + if (mempoolDetails) + if (mempoolDetails.ancestors.length > 0) + div(class="card mb-3 shadow-sm") + div(class="card-header") + h2(class="h6 mb-0") + span #{mempoolDetails.ancestors.length.toLocaleString()} + if (mempoolDetails.ancestors.length == 1) + span Ancestor + else + span Ancestors + + + div(class="card-body") + ol.mb-0 + each ancestorTxid, ancestorIndex in mempoolDetails.ancestors + li + a.text-monospace(href=("/tx/" + ancestorTxid)) #{ancestorTxid} + + if (mempoolDetails.descendants.length > 0) + div(class="card mb-3 shadow-sm") + div(class="card-header") + h2(class="h6 mb-0") + span #{mempoolDetails.descendants.length.toLocaleString()} + if (mempoolDetails.descendants.length == 1) + span Descendant + else + span Descendants + + + div(class="card-body") + ol.mb-0 + each descendantTxid, descendantIndex in mempoolDetails.descendants + li + a.text-monospace(href=("/tx/" + descendantTxid)) #{descendantTxid} + - var fontawesomeInputName = "sign-in-alt"; - var fontawesomeOutputName = "sign-out-alt"; @@ -305,6 +340,12 @@ block content pre code(class="json bg-light", data-lang="json") #{JSON.stringify(utxos, null, 4)} + if (mempoolDetails) + h3.h5 Mempool Details + div(class="highlight") + pre + code(class="json bg-light", data-lang="json") #{JSON.stringify(mempoolDetails, null, 4)} + //pre #{JSON.stringify(result.txInputs, null, 4)}