From caa28374d53b618b335eba014c96fb7f8c7df0dd Mon Sep 17 00:00:00 2001 From: Mike the Tike Date: Thu, 27 Jan 2022 20:14:09 +0200 Subject: [PATCH] feat(explorer): better view on mempool (#3763) Better detail view of mempool transactions --- applications/tari_base_node/windows/README.md | 2 +- applications/tari_explorer/routes/index.js | 81 +++++++++---------- applications/tari_explorer/routes/mempool.js | 51 +++++++++--- applications/tari_explorer/views/index.hbs | 2 +- applications/tari_explorer/views/mempool.hbs | 20 ++++- 5 files changed, 99 insertions(+), 57 deletions(-) diff --git a/applications/tari_base_node/windows/README.md b/applications/tari_base_node/windows/README.md index defa2e1279..6e691955a1 100644 --- a/applications/tari_base_node/windows/README.md +++ b/applications/tari_base_node/windows/README.md @@ -150,7 +150,7 @@ depending on the choices you make when prompted: environment variable (hint: type `path` in a command console to verify). - Tor Services - - Donwload + - Download [Tor Windows Expert Bundle](https://www.torproject.org/download/tor/). - Extract to local path, e.g. `%USERPROFILE%\.tor_services`. - Add the path to the Tari environment variable, e.g. type diff --git a/applications/tari_explorer/routes/index.js b/applications/tari_explorer/routes/index.js index d115650700..fe9cdd9273 100644 --- a/applications/tari_explorer/routes/index.js +++ b/applications/tari_explorer/routes/index.js @@ -6,35 +6,34 @@ var router = express.Router() /* GET home page. */ router.get("/", async function (req, res) { try { - let client = createClient() - let from = parseInt(req.query.from || 0) - let limit = parseInt(req.query.limit || "20") + let client = createClient() + let from = parseInt(req.query.from || 0) + let limit = parseInt(req.query.limit || "20") let tipInfo = await client.getTipInfo({}) - console.log("Getting headers") - // Algo split - let last100Headers = await client.listHeaders({ + // Algo split + let last100Headers = await client.listHeaders({ from_height: 0, num_headers: 101, }) - let monero = [0, 0, 0, 0] - let sha = [0, 0, 0, 0] + let monero = [0, 0, 0, 0] + let sha = [0, 0, 0, 0] - console.log(last100Headers) + // console.log(last100Headers) - for (let i = 0; i < last100Headers.length - 1; i++) { - let arr = last100Headers[i].pow.pow_algo === "0" ? monero : sha - if (i < 10) { - arr[0] += 1 - } - if (i < 20) { - arr[1] += 1 - } - if (i < 50) { - arr[2] += 1 - } - arr[3] += 1 + for (let i = 0; i < last100Headers.length - 1; i++) { + let arr = last100Headers[i].pow.pow_algo === "0" ? monero : sha + if (i < 10) { + arr[0] += 1 + } + if (i < 20) { + arr[1] += 1 + } + if (i < 50) { + arr[2] += 1 + } + arr[3] += 1 } const algoSplit = { monero10: monero[0], @@ -47,7 +46,7 @@ router.get("/", async function (req, res) { sha100: sha[3], } - console.log(algoSplit) + // console.log(algoSplit) // Get one more header than requested so we can work out the difference in MMR_size let headers = await client.listHeaders({ from_height: from, @@ -75,6 +74,7 @@ router.get("/", async function (req, res) { // -- mempool let mempool = await client.getMempoolTransactions({}) + console.log(mempool) for (let i = 0; i < mempool.length; i++) { let sum = 0 for (let j = 0; j < mempool[i].transaction.body.kernels.length; j++) { @@ -83,25 +83,24 @@ router.get("/", async function (req, res) { mempool[i].transaction.body.total_fees = sum } res.render("index", { - title: "Blocks", - tipInfo: tipInfo, - mempool: mempool, - headers: headers, - pows: { 0: "Monero", 2: "SHA" }, - nextPage: firstHeight - limit, - prevPage: firstHeight + limit, - limit: limit, - from: from, - algoSplit: algoSplit, - blockTimes: getBlockTimes(last100Headers), - moneroTimes: getBlockTimes(last100Headers, "0"), - shaTimes: getBlockTimes(last100Headers, "1"), - }) - -} catch (error) { - res.status(500) - res.render("error", { error: error }) -} + title: "Blocks", + tipInfo: tipInfo, + mempool: mempool, + headers: headers, + pows: { 0: "Monero", 2: "SHA" }, + nextPage: firstHeight - limit, + prevPage: firstHeight + limit, + limit: limit, + from: from, + algoSplit: algoSplit, + blockTimes: getBlockTimes(last100Headers), + moneroTimes: getBlockTimes(last100Headers, "0"), + shaTimes: getBlockTimes(last100Headers, "1"), + }) + } catch (error) { + res.status(500) + res.render("error", { error: error }) + } }) function getBlockTimes(last100Headers, algo) { diff --git a/applications/tari_explorer/routes/mempool.js b/applications/tari_explorer/routes/mempool.js index 9224c8797b..1d8408b0fa 100644 --- a/applications/tari_explorer/routes/mempool.js +++ b/applications/tari_explorer/routes/mempool.js @@ -1,17 +1,48 @@ var express = require("express") +const { createClient } = require("../baseNodeClient") var router = express.Router() /* GET mempool page. */ -router.get("/:tx", async function (req, res) { - let tx = JSON.parse(Buffer.from(req.params.tx, "base64")) - console.log("========== stringify 2 ========") - console.log(tx.inputs) - console.log("===============") - res.render("Mempool", { - inputs: tx.inputs, - outputs: tx.outputs, - kernels: tx.kernels, - }) +router.get("/:excessSigs", async function (req, res) { + try { + let client = createClient() + let txId = req.params.excessSigs.split("+") + console.log(txId) + let mempool = await client.getMempoolTransactions({}) + let tx = null + for (let i = 0; i < mempool.length; i++) { + for (let j = 0; j < mempool[i].transaction.body.kernels.length; j++) { + for (let k = 0; k < txId.length; k++) { + if ( + txId[k] === + Buffer.from( + mempool[i].transaction.body.kernels[j].excess_sig.signature + ).toString("hex") + ) { + tx = mempool[i].transaction + break + } + } + if (tx) { + break + } + } + } + + if (!tx) { + res.status(404) + res.render("error", { error: "Tx not found" }) + return + } + console.log(tx) + console.log("===============") + res.render("Mempool", { + tx, + }) + } catch (error) { + res.status(500) + res.render("error", { error: error }) + } }) module.exports = router diff --git a/applications/tari_explorer/views/index.hbs b/applications/tari_explorer/views/index.hbs index 409660acbf..6a3ba79797 100644 --- a/applications/tari_explorer/views/index.hbs +++ b/applications/tari_explorer/views/index.hbs @@ -137,7 +137,7 @@ {{#each mempool}} {{#with this.transaction.body}} - {{#each this.kernels}}{{hex this.excess_sig.signature}}{{/each}} + {{#each this.kernels}}{{hex this.excess_sig.signature}}{{/each}} {{this.total_fees}} {{this.outputs.length}} {{this.kernels.length}} diff --git a/applications/tari_explorer/views/mempool.hbs b/applications/tari_explorer/views/mempool.hbs index 71bea60c43..448ba99e38 100644 --- a/applications/tari_explorer/views/mempool.hbs +++ b/applications/tari_explorer/views/mempool.hbs @@ -1,4 +1,15 @@ Back +{{#with this.tx }} +

Meta

+ + + + + + + + +
Offset
{{hex this.offset}}

Inputs

@@ -13,7 +24,7 @@ - {{#each this.inputs}} + {{#each this.body.inputs}} - {{#each this.outputs}} + {{#each this.body.outputs}} - {{#each this.kernels}} + {{#each this.body.kernels}} @@ -97,4 +108,5 @@ {{/each}} -
Flags
{{features.flags}}
Maturity
@@ -48,7 +59,7 @@
Flags
{{features.flags}}
Maturity
@@ -84,7 +95,7 @@
{{features}} {{fee}}
\ No newline at end of file + +{{/with}} \ No newline at end of file