Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(explorer): better view on mempool #3763

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applications/tari_base_node/windows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 40 additions & 41 deletions applications/tari_explorer/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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,
Expand Down Expand Up @@ -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++) {
Expand All @@ -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) {
Expand Down
51 changes: 41 additions & 10 deletions applications/tari_explorer/routes/mempool.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion applications/tari_explorer/views/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
{{#each mempool}}
{{#with this.transaction.body}}
<tr>
<td><a href="/mempool/{{json this}}">{{#each this.kernels}}<span>{{hex this.excess_sig.signature}}</span>{{/each}}</a></td>
<td><a href="/mempool/{{#each this.kernels}}{{hex this.excess_sig.signature}}+{{/each}}">{{#each this.kernels}}<span>{{hex this.excess_sig.signature}}</span>{{/each}}</a></td>
<td>{{this.total_fees}}</td>
<td>{{this.outputs.length}}</td>
<td>{{this.kernels.length}}</td>
Expand Down
20 changes: 16 additions & 4 deletions applications/tari_explorer/views/mempool.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<a href="/">Back</a>
{{#with this.tx }}
<h3>Meta</h3>
<table border="1" width="100%" cellpadding="5" bordercolor="#EFEFEF">
<thead>
<tr><th>Offset</th></tr>
</thead>
<tbody>
<tr>
<td>{{hex this.offset}}</td></tr>
</tbody>
</table>
<h3>Inputs</h3>
<table border="1" width="100%" cellpadding="5" bordercolor="#EFEFEF">
<thead>
Expand All @@ -13,7 +24,7 @@
</tr>
</thead>
<tbody>
{{#each this.inputs}}
{{#each this.body.inputs}}
<tr>
<td><i>Flags</i><br />
{{features.flags}}<hr /><i>Maturity</i><br />
Expand Down Expand Up @@ -48,7 +59,7 @@
</tr>
</thead>
<tbody>
{{#each this.outputs}}
{{#each this.body.outputs}}
<tr>
<td><i>Flags</i><br />
{{features.flags}}<hr /><i>Maturity</i><br />
Expand Down Expand Up @@ -84,7 +95,7 @@
</tr>
</thead>
<tbody>
{{#each this.kernels}}
{{#each this.body.kernels}}
<tr>
<td>{{features}}</td>
<td>{{fee}}</td>
Expand All @@ -97,4 +108,5 @@
</tr>
{{/each}}
</tbody>
</table>
</table>
{{/with}}