Browse Source

- clean up "magic hashes", styling, and logging

- new page for "interesting transactions"
fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
e763d2243f
  1. 4
      app.js
  2. 56
      app/rpcApi.js
  3. 6
      public/css/styling.css
  4. 9
      routes/baseActionsRouter.js
  5. 8
      views/includes/block-content.pug
  6. 2
      views/index.pug
  7. 28
      views/interesting-transactions.pug
  8. 2
      views/layout.pug
  9. 2
      views/transaction.pug

4
app.js

@ -17,6 +17,7 @@ var Decimal = require('decimal.js');
var bitcoin = require("bitcoin");
var pug = require("pug");
var momentDurationFormat = require("moment-duration-format");
var rpcApi = require("./app/rpcApi.js");
var baseActionsRouter = require('./routes/baseActionsRouter');
@ -72,6 +73,9 @@ app.use(function(req, res, next) {
res.locals.host = req.session.host;
res.locals.port = req.session.port;
res.locals.genesisBlockHash = rpcApi.getGenesisBlockHash();
res.locals.genesisCoinbaseTransactionId = rpcApi.getGenesisCoinbaseTransactionId();
if (!["/", "/connect"].includes(req.originalUrl)) {
if (utils.redirectToConnectPageIfNeeded(req, res)) {
return;

56
app/rpcApi.js

@ -1,6 +1,8 @@
var utils = require("./utils.js");
var genesisCoinbaseTransactionTxid = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
var genesisBlockHash = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
var genesisCoinbaseTransactionId = "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b";
var genesisCoinbaseTransaction = {
"hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0804ffff001d02fd04ffffffff0100f2052a01000000434104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac00000000",
"txid": "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b",
@ -30,12 +32,51 @@ var genesisCoinbaseTransaction = {
}
}
],
"blockhash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
"blockhash": genesisBlockHash,
"time": 1230988505,
"blocktime": 1230988505
};
var interestingTx = [
{
txid: genesisCoinbaseTransactionId,
note: "The coinbase transaction of the genesis block.",
referenceUrl: ""
},
{
txid: "7dff938918f07619abd38e4510890396b1cef4fbeca154fb7aafba8843295ea2",
note: "First bitcoin traded for fiat currency.",
referenceUrl: ""
},
{
txid: "8f907925d2ebe48765103e6845C06f1f2bb77c6adc1cc002865865eb5cfd5c1c",
note: "First SegWit transaction.",
referenceUrl: ""
},
{
txid: "143a3d7e7599557f9d63e7f224f34d33e9251b2c23c38f95631b3a54de53f024",
note: "Star Wars: A New Hope",
referenceUrl: ""
},
{
txid: "a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d",
note: "Bitcoin Pizza Transaction",
referenceUrl: ""
},
{
txid: "5d80a29be1609db91658b401f85921a86ab4755969729b65257651bb9fd2c10d",
note: "Destroyed bitcoin",
referenceUrl: "https://www.reddit.com/r/Bitcoin/comments/7mhoks/til_in_2011_a_user_running_a_modified_mining/"
}
];
function getGenesisBlockHash() {
return genesisBlockHash;
}
function getGenesisCoinbaseTransactionId() {
return genesisCoinbaseTransactionId;
}
function getBlockchainInfo() {
return new Promise(function(resolve, reject) {
@ -309,7 +350,7 @@ function getTransactionInputs(rpcClient, transaction, inputLimit=0) {
function getRawTransaction(txid) {
return new Promise(function(resolve, reject) {
if (txid == genesisCoinbaseTransactionTxid) {
if (txid == genesisCoinbaseTransactionId) {
getBlockByHeight(0).then(function(blockZeroResult) {
var result = genesisCoinbaseTransaction;
result.confirmations = blockZeroResult.getblock.confirmations;
@ -578,7 +619,13 @@ function getRpcMethodHelp(methodName) {
});
}
function getInterestingTransactions() {
return interestingTx;
}
module.exports = {
getGenesisBlockHash: getGenesisBlockHash,
getGenesisCoinbaseTransactionId: getGenesisCoinbaseTransactionId,
getBlockchainInfo: getBlockchainInfo,
getNetworkInfo: getNetworkInfo,
getNetTotals: getNetTotals,
@ -593,5 +640,6 @@ module.exports = {
getMempoolStats: getMempoolStats,
getUptimeSeconds: getUptimeSeconds,
getHelp: getHelp,
getRpcMethodHelp: getRpcMethodHelp
getRpcMethodHelp: getRpcMethodHelp,
getInterestingTransactions: getInterestingTransactions
};

6
public/css/styling.css

@ -19,7 +19,7 @@ code, .monospace {
}
.properties-header {
width: 180px;
width: 190px;
text-align: right;
}
@ -38,4 +38,8 @@ code, .monospace {
#subheader a {
margin-right: 20px;
}
.table th {
border-top: none;
}

9
routes/baseActionsRouter.js

@ -457,9 +457,6 @@ router.get("/rpc-browser", function(req, res) {
var argDetails = result2.args;
var argValues = [];
console.log("argA: " + JSON.stringify(result2.args, null, 4));
console.log("argB: " + JSON.stringify(req.query.args, null, 4));
if (req.query.args) {
for (var i = 0; i < req.query.args.length; i++) {
var argProperties = argDetails[i].properties;
@ -485,7 +482,6 @@ router.get("/rpc-browser", function(req, res) {
}
res.locals.argValues = argValues;
console.log("argV: " + JSON.stringify(argValues, null, 4));
client.cmd([{method:req.query.method, params:argValues}], function(err3, result3, resHeaders3) {
if (err3) {
@ -520,5 +516,10 @@ router.get("/rpc-browser", function(req, res) {
});
});
router.get("/interesting-transactions", function(req, res) {
res.locals.interestingTransactions = rpcApi.getInterestingTransactions();
res.render("interesting-transactions");
});
module.exports = router;

8
views/includes/block-content.pug

@ -8,7 +8,7 @@ ul(class='nav nav-tabs mb-3')
div(class="tab-content")
div(id="tab-summary", class="tab-pane active", role="tabpanel")
if (result.getblock.hash == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
if (result.getblock.hash == genesisBlockHash)
div(class="alert alert-success", style="padding-bottom: 0;")
h4(class="alert-heading h5") This is the Bitcoin Genesis Block!
:markdown-it
@ -26,7 +26,7 @@ div(class="tab-content")
if (result.getblock.previousblockhash)
a(href=("/block/" + result.getblock.previousblockhash)) #{result.getblock.previousblockhash}
else if (result.getblock.hash == "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f")
else if (result.getblock.hash == genesisBlockHash)
span N/A - This is the
a(href="https://en.bitcoin.it/wiki/Genesis_block") Bitcoin Genesis Block
@ -56,8 +56,7 @@ div(class="tab-content")
th(class="table-active properties-header") Size
td(class="monospace")
span #{result.getblock.size.toLocaleString()} bytes
br
span(class="text-muted") (weight: #{result.getblock.weight.toLocaleString()})
span(class="text-muted") (weight: #{result.getblock.weight.toLocaleString()})
tr
th(class="table-active properties-header") Confirmations
@ -234,4 +233,3 @@ div(class="tab-content")
pre
code #{JSON.stringify(result.getblock, null, 4)}

2
views/index.pug

@ -17,10 +17,12 @@ block content
h3 Latest Blocks
if (getblockchaininfo.initialblockdownload)
small (#{(getblockchaininfo.headers - getblockchaininfo.blocks).toLocaleString()} behind)
div(class="col")
span(style="float: right;")
a(href="/blocks") Browse Blocks &raquo;
hr
- var blocks = latestBlocks;
- var blockOffset = 0;

28
views/interesting-transactions.pug

@ -0,0 +1,28 @@
extends layout
block headContent
title Interesting Transactions
block content
h1(class="h2") Interesting Transactions
hr
table(class="table table-striped table-responsive-sm mt-4")
thead
tr
th(class="data-header") Note
th(class="data-header") TxID
th(class="data-header") Read More
tbody
each tx, index in interestingTransactions
tr
td(class="data-cell") #{tx.note}
td(class="data-cell monospace")
a(href=("/tx/" + tx.txid)) #{tx.txid.substring(0, 25)}...
td(class="data-cell")
if (tx.referenceUrl && tx.referenceUrl.trim().length > 0)
a(href=tx.referenceUrl) Read More
else
span -

2
views/layout.pug

@ -50,6 +50,8 @@ html
a(href="/rpc-terminal", class="nav-link") RPC Terminal
li(class="nav-item")
a(href="/mempool-summary", class="nav-link") Mempool Summary
li(class="nav-item")
a(href="/interesting-transactions", class="nav-link") Interesting Transactions
hr

2
views/transaction.pug

@ -40,7 +40,7 @@ block content
div(class="tab-content")
div(id="tab-summary", class="tab-pane active", role="tabpanel")
if (txid == "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
if (txid == genesisCoinbaseTransactionId)
div(class="alert alert-warning", style="padding-bottom: 0;")
h4(class="alert-heading h5") This transaction doesn't really exist!
:markdown-it

Loading…
Cancel
Save