From e410a1fc36caf670069202733aa1812e36749877 Mon Sep 17 00:00:00 2001 From: Dan Janosik Date: Wed, 27 May 2020 16:51:45 -0400 Subject: [PATCH] Tx IO displays - For fun, add the following: - highlight coinbase spends - highlight very old (5+ year) UTXO spends To do this, when summarizing tx details store whether it's a coinbase spend and the time of input txs --- app/api/coreApi.js | 7 ++++++- views/includes/transaction-io-details.pug | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/api/coreApi.js b/app/api/coreApi.js index 3a05c6d..12b79a8 100644 --- a/app/api/coreApi.js +++ b/app/api/coreApi.js @@ -19,7 +19,7 @@ var rpcApi = require("./rpcApi.js"); // this value should be incremented whenever data format changes, to avoid // pulling old-format data from a persistent cache -var cacheKeyVersion = "v0"; +var cacheKeyVersion = "v1"; const ONE_SEC = 1000; @@ -581,6 +581,11 @@ function getSummarizedTransactionOutput(txid, voutIndex) { } vout.txid = txid; + vout.utxoTime = rawTx.time; + + if (rawTx.vin.length == 1 && rawTx.vin[0].coinbase) { + vout.coinbaseSpend = true; + } resolve(vout); diff --git a/views/includes/transaction-io-details.pug b/views/includes/transaction-io-details.pug index cf0175c..4219bac 100644 --- a/views/includes/transaction-io-details.pug +++ b/views/includes/transaction-io-details.pug @@ -63,6 +63,20 @@ div.row.text-monospace div.word-wrap small.data-tag.bg-dark.mr-2 span(title=`Input Type: ${utils.outputTypeName(vout.scriptPubKey.type)}`, data-toggle="tooltip") #{utils.outputTypeAbbreviation(vout.scriptPubKey.type)} + + if (vout.coinbaseSpend) + small.data-tag.bg-success.mr-2 + span(title=`This input spends a coinbase output (mining reward).`, data-toggle="tooltip") coinbase-spend + + if (vout.utxoTime) + - var deltaT = tx.time - vout.utxoTime + - var deltaTYears = deltaT / 60 / 60 / 24 / 365 + + if (deltaTYears > 5) + span.mr-2(title=`This UTXO was very old! It existed for ${parseInt(deltaTYears)}+ years - from ${moment.utc(new Date(vout.utxoTime * 1000)).format('MMM D, Y')} until ${moment.utc(new Date(tx.time * 1000)).format('MMM D, Y')} - before being spent (destroyed) in this transaction!`, data-toggle="tooltip") + i.fas.fa-certificate.text-primary + + a(href=("/tx/" + txInput.txid + "#output-" + txVin.vout)) #{utils.ellipsize(txInput.txid, 26)} span ##{txVin.vout}