mirror of
https://github.com/janoside/btc-rpc-explorer.git
synced 2026-08-13 12:33:13 +02:00
/test router
single action so far, to render a page with a curated list of txs on it (txs that have unique properties to test tx display logic)
This commit is contained in:
parent
2b3366a2d5
commit
56566a6512
4 changed files with 149 additions and 0 deletions
6
app.js
6
app.js
|
|
@ -111,6 +111,7 @@ const internalApiActionsRouter = require('./routes/internalApiRouter.js');
|
|||
const apiActionsRouter = require('./routes/apiRouter.js');
|
||||
const snippetActionsRouter = require('./routes/snippetRouter.js');
|
||||
const adminActionsRouter = require('./routes/adminRouter.js');
|
||||
const testActionsRouter = require('./routes/testRouter.js');
|
||||
|
||||
const expressApp = express();
|
||||
|
||||
|
|
@ -837,6 +838,11 @@ expressApp.use(config.baseUrl + 'api/', apiActionsRouter);
|
|||
expressApp.use(config.baseUrl + 'snippet/', snippetActionsRouter);
|
||||
expressApp.use(config.baseUrl + 'admin/', adminActionsRouter);
|
||||
|
||||
if (expressApp.get("env") === "local") {
|
||||
expressApp.use(config.baseUrl + 'test/', testActionsRouter);
|
||||
}
|
||||
|
||||
|
||||
expressApp.use(function(req, res, next) {
|
||||
var time = Date.now() - req.startTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -420,6 +420,61 @@ module.exports = {
|
|||
"utxo_size_inc": 117
|
||||
}
|
||||
},
|
||||
testData: {
|
||||
txDisplayTestList: {
|
||||
"634b57cf0673c50b98560dbdf48d0a8633303b5d9162175e08b304df159c259e" : {
|
||||
blockHeight: 694670, blockHash: "0000000000000000000ba61d43854a2460b219b5281db2c731ae03a4347eaf43"
|
||||
},
|
||||
"f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16" : {
|
||||
blockHeight: 170, blockHash: "00000000d1145790a8694403d4063f323d499e655c83426834d4ce2f8dd4a2ee"
|
||||
},
|
||||
"a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d" : {
|
||||
blockHeight: 57043, blockHash: "00000000152340ca42227603908689183edc47355204e7aca59383b0aaac1fd8"
|
||||
},
|
||||
"7b6e490670a5cfcc9b66d8aab142ac2e9b489ae7f40cadadfc69c19878ae81b0" : {
|
||||
blockHeight: 227835, blockHash: "00000000000001aa077d7aa84c532a4d69bdbff519609d1da0835261b7a74eb6"
|
||||
},
|
||||
"8f7f13d6b56ea9013f13d298bc0e9e9f4f9825f3e7fd96083a564b10b01025d9" : {
|
||||
blockHeight: 694521, blockHash: "00000000000000000009974b5f6011d7ec8af460dafcc668c7ede4324896b9ca"
|
||||
},
|
||||
"3215f4a32a26938ddf9eeb4de7f5f42e751410876500f6e93d943abb2c3cccc4" : {
|
||||
blockHeight: 694521, blockHash: "00000000000000000009974b5f6011d7ec8af460dafcc668c7ede4324896b9ca"
|
||||
},
|
||||
"333d5f27c6fc2d07ef8c19e17d33568706bc3d6875198aba6cff0a996698d46e" : {
|
||||
blockHeight: 694521, blockHash: "00000000000000000009974b5f6011d7ec8af460dafcc668c7ede4324896b9ca"
|
||||
},
|
||||
"a9ceb47b092f703c30b29cb8b864fb8fa895a5999b24aa56ae08a967b643087c" : {
|
||||
blockHeight: 694521, blockHash: "00000000000000000009974b5f6011d7ec8af460dafcc668c7ede4324896b9ca"
|
||||
},
|
||||
"bc968c93c6ff39f022f974504a22d548902fe5a8c4fb294f052f845e4c388fcb" : {
|
||||
blockHeight: 694521, blockHash: "00000000000000000009974b5f6011d7ec8af460dafcc668c7ede4324896b9ca"
|
||||
},
|
||||
"e4bd7949cbf067d17629a5f588bba051b4436d29b5978d674118539356745bd0" : {
|
||||
blockHeight: 227835, blockHash: "00000000000001aa077d7aa84c532a4d69bdbff519609d1da0835261b7a74eb6"
|
||||
},
|
||||
"54e48e5f5c656b26c3bca14a8c95aa583d07ebe84dde3b7dd4a78f4e4186e713" : {
|
||||
blockHeight: 230009, blockHash: "00000000000000ecbbff6bafb7efa2f7df05b227d5c73dca8f2635af32a2e949"
|
||||
},
|
||||
"d29c9c0e8e4d2a9790922af73f0b8d51f0bd4bb19940d9cf910ead8fbe85bc9b" : {
|
||||
blockHeight: 268060, blockHash: "000000000000000743aee48cf264e1aa4a05fc3018677be3c1bdbd2429ffeede"
|
||||
},
|
||||
"143a3d7e7599557f9d63e7f224f34d33e9251b2c23c38f95631b3a54de53f024" : {
|
||||
blockHeight: 306204, blockHash: "000000000000000038dea6f503ed3593b1495e135d9ed646c2ebb97a1ff35bd7"
|
||||
},
|
||||
"8f907925d2ebe48765103e6845c06f1f2bb77c6adc1cc002865865eb5cfd5c1c" : {
|
||||
blockHeight: 481824, blockHash: "0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893"
|
||||
},
|
||||
"8f5834d39a634c1b4c6283b546e16e931cb34d28570c77860de1a86256c4344d" : {
|
||||
blockHeight: 629999, blockHash: "0000000000000000000d656be18bb095db1b23bd797266b0ac3ba720b1962b1e"
|
||||
},
|
||||
"7836d12e741ffc6e50dba9b461e117cfbe444e7daa73df648b3a441d5a9ee958" : {
|
||||
blockHeight: 230009, blockHash: "00000000000000ecbbff6bafb7efa2f7df05b227d5c73dca8f2635af32a2e949"
|
||||
},
|
||||
"29a3efd3ef04f9153d47a990bd7b048a4b2d213daaa5fb8ed670fb85f13bdbcf" : {
|
||||
blockHeight: 153509, blockHash: "00000000000000fb62bbadc0a9dcda556925b2d0c1ad8634253ac2e83ab8382f"
|
||||
}
|
||||
}
|
||||
},
|
||||
genesisCoinbaseOutputAddressScripthash:"8b01df4e368ea28f8dc0423bcf7a4923e3a12d307c875e47a0cfbf90b5c39161",
|
||||
historicalData: btcFun.items,
|
||||
exchangeRateData:{
|
||||
|
|
|
|||
75
routes/testRouter.js
Normal file
75
routes/testRouter.js
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
"use strict";
|
||||
|
||||
const debug = require("debug");
|
||||
const debugLog = debug("btcexp:router");
|
||||
|
||||
const express = require('express');
|
||||
const csurf = require('csurf');
|
||||
const router = express.Router();
|
||||
const util = require('util');
|
||||
const moment = require('moment');
|
||||
const bitcoinCore = require("btc-rpc-client");
|
||||
const qrcode = require('qrcode');
|
||||
const bitcoinjs = require('bitcoinjs-lib');
|
||||
const bip32 = require('bip32');
|
||||
const bs58check = require('bs58check');
|
||||
const { bech32, bech32m } = require("bech32");
|
||||
const sha256 = require("crypto-js/sha256");
|
||||
const hexEnc = require("crypto-js/enc-hex");
|
||||
const Decimal = require("decimal.js");
|
||||
const semver = require("semver");
|
||||
const markdown = require("markdown-it")();
|
||||
const asyncHandler = require("express-async-handler");
|
||||
|
||||
const utils = require('./../app/utils.js');
|
||||
const coins = require("./../app/coins.js");
|
||||
const config = require("./../app/config.js");
|
||||
const coreApi = require("./../app/api/coreApi.js");
|
||||
const addressApi = require("./../app/api/addressApi.js");
|
||||
const rpcApi = require("./../app/api/rpcApi.js");
|
||||
const btcQuotes = require("./../app/coins/btcQuotes.js");
|
||||
|
||||
|
||||
router.get("/tx-display", asyncHandler(async (req, res, next) => {
|
||||
res.locals.transactions = [];
|
||||
res.locals.txInputsByTransaction = {};
|
||||
res.locals.blockHeightsByTxid = {};
|
||||
|
||||
var txidOrder = [];
|
||||
|
||||
const promises = [];
|
||||
for (const [txid, data] of Object.entries(global.coinConfig.testData.txDisplayTestList)) {
|
||||
txidOrder.push(txid);
|
||||
|
||||
const blockHash = data.blockHash;
|
||||
|
||||
res.locals.blockHeightsByTxid[txid] = data.blockHeight;
|
||||
|
||||
promises.push(utils.safePromise("tx_display_getRawTransactionsWithInputs", async () => {
|
||||
const transactionData = await coreApi.getRawTransactionsWithInputs([txid], 5, blockHash);
|
||||
|
||||
res.locals.transactions.push(transactionData.transactions[0]);
|
||||
|
||||
for (const [resultTxid, resultData] of Object.entries(transactionData.txInputsByTransaction)) {
|
||||
res.locals.txInputsByTransaction[resultTxid] = resultData;
|
||||
}
|
||||
//console.log(JSON.stringify(transactionData.txInputsByTransaction));
|
||||
}));
|
||||
}
|
||||
|
||||
res.locals.maxTxOutputDisplayCount = 12;
|
||||
|
||||
// todo: include a random mempool tx
|
||||
|
||||
await Promise.all(promises);
|
||||
|
||||
res.locals.transactions.sort((a, b) => {
|
||||
return txidOrder.indexOf(a.txid) - txidOrder.indexOf(b.txid);
|
||||
});
|
||||
|
||||
res.render("test/tx-display.pug");
|
||||
|
||||
next();
|
||||
}));
|
||||
|
||||
module.exports = router;
|
||||
13
views/test/tx-display.pug
Normal file
13
views/test/tx-display.pug
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
extends ../layout
|
||||
|
||||
block headContent
|
||||
title Test: Transaction Display
|
||||
|
||||
block content
|
||||
+pageTitle("Test: Transaction Display")
|
||||
|
||||
+txList(transactions, transactions.length, transactions.length, 0, txInputsByTransaction, {blockHeightsByTxid:blockHeightsByTxid})
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue