Browse Source

Add ancestors/descendants to tx details page, fixes #126

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
e6fd90eeb4
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 7
      app/api/coreApi.js
  2. 55
      app/api/rpcApi.js
  3. 15
      routes/baseActionsRouter.js
  4. 41
      views/transaction.pug

7
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,

55
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,

15
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;

41
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)}

Loading…
Cancel
Save