Improved xyzpub screen with some address details

- global balance in header
- balance and transaction count in each address
- possibility to use extended public keys in btcFun.js
This commit is contained in:
Thierry61 2023-03-22 23:09:10 +01:00
parent 268db37c28
commit 31125ea220
3 changed files with 57 additions and 23 deletions

View file

@ -700,9 +700,6 @@ router.get("/xyzpub/:extendedPubkey", asyncHandler(async (req, res, next) => {
res.locals.relatedKeys = [];
const receiveAddresses = [];
const changeAddresses = [];
const xpub_tpub = global.activeBlockchain == "main" ? "xpub" : "tpub";
const ypub_upub = global.activeBlockchain == "main" ? "ypub" : "upub";
const zpub_vpub = global.activeBlockchain == "main" ? "zpub" : "vpub";
@ -838,6 +835,34 @@ router.get("/xyzpub/:extendedPubkey", asyncHandler(async (req, res, next) => {
res.locals.bip32Path = "-";
}
// Cumulate balanceSat of all addresses
res.locals.balanceSat = 0;
// Loop over the 2 types addresses (first receive and then change)
let allAddresses = [res.locals.receiveAddresses, res.locals.changeAddresses];
res.locals.receiveAddresses = [];
res.locals.changeAddresses = [];
for (let i = 0; i < allAddresses.length; i++) {
// Duplicate addresses and change them to addressDetails objects with 3 properties (address, balanceSat, txCount)
let addresses = [...allAddresses[i]];
for (let j = 0; j < addresses.length; j++) {
const address = addresses[j];
const validateaddressResult = await coreApi.getAddress(address);
// No need to paginate request => use a high limit value
const addressDetailsResult = await addressApi.getAddressDetails(address, validateaddressResult.scriptPubKey, "desc", 100, 0);
// In case of errors, we just skip this address result
if (Array.isArray(addressDetailsResult.errors) && addressDetailsResult.errors.length == 0) {
res.locals.balanceSat += addressDetailsResult.addressDetails.balanceSat;
const addressDetails = { ...addressDetailsResult.addressDetails, address};
if (i == 0)
res.locals.receiveAddresses.push(addressDetails);
else
res.locals.changeAddresses.push(addressDetails);
}
}
}
await utils.timePromise("extended-public-key.render", async () => {
res.render("extended-public-key");

View file

@ -11,7 +11,7 @@ block content
.mb-n3 !{markdown("Wallet software often presents users with an XPUB. Exposure of your XPUB, although it doesn't risk theft of your bitcoin, **harms your privacy** by allowing anyone with access to your XPUB to know all of your addresses and the details of all transactions sent to and from them. This page is meant to demonstrate that fact - search for any XPUB (xpub, ypub, zpub...) and this tool will display all of the addresses derived from that key.")}
+contentSection("Summary")
+summaryRow(3 + (balance ? 1 : 0) + (changeBalance ? 1 : 0) + (xpub ? 1 : 0))
+summaryRow(4)
+summaryItem("Key Type", "A simple shorthand for the type of extended public key. Each type (xpub, ypub, zpub...) is interpreted slightly differently, resulting in a different sequence of addresses.")
| #{keyType}
@ -24,11 +24,10 @@ block content
+summaryItem("BIP32 Path", "BIP32 defines a standard for deriving child keys from an extended parent key. This 'path', also known as the 'derivation path', comes from that standard and instructs software how to generate child keys.")
| #{bip32Path}
if (balance)
+summaryItem("Balance")
if (changeBalance)
+summaryItem("Change Balance")
+summaryItem("Balance")
span(class=(balanceSat > 0 ? "text-success" : false))
- var currencyValue = new Decimal(balanceSat).dividedBy(coinConfig.baseCurrencyUnit.multiplier);
+valueDisplay(currencyValue)
if (relatedKeys)
@ -95,20 +94,24 @@ block content
tr
th.text-end Index
th Address
//th N(tx)
//th Balance
th.text-end Transactions
th Balance
tbody
each address, addressIndex in receiveAddresses
each addressDetails, addressIndex in receiveAddresses
tr
td.text-end
.text-muted ##{(offset + addressIndex).toLocaleString()}
td
a(href=`./address/${address}`) #{utils.ellipsizeMiddle(address, 24)}
+copyTextButton(address)
a(href=`./address/${addressDetails.address}`) #{utils.ellipsizeMiddle(addressDetails.address, 24)}
+copyTextButton(addressDetails.address)
//td -
//td -
td.text-end #{addressDetails.txCount.toLocaleString()}
td
span(class=(addressDetails.balanceSat > 0 ? "text-success" : false))
- var currencyValue = new Decimal(addressDetails.balanceSat).dividedBy(coinConfig.baseCurrencyUnit.multiplier);
+valueDisplay(currencyValue)
.col
@ -119,19 +122,23 @@ block content
tr
th.text-end Index
th Address
//th N(tx)
//th Balance
th.text-end Transactions
th Balance
tbody
each address, addressIndex in changeAddresses
each addressDetails, addressIndex in changeAddresses
tr
td.text-end
.text-muted ##{(offset + addressIndex).toLocaleString()}
td
a(href=`./address/${address}`) #{utils.ellipsizeMiddle(address, 24)}
+copyTextButton(address)
a(href=`./address/${addressDetails.address}`) #{utils.ellipsizeMiddle(addressDetails.address, 24)}
+copyTextButton(addressDetails.address)
//td -
//td -
td.text-end #{addressDetails.txCount.toLocaleString()}
td
span(class=(addressDetails.balanceSat > 0 ? "text-success" : false))
- var currencyValue = new Decimal(addressDetails.balanceSat).dividedBy(coinConfig.baseCurrencyUnit.multiplier);
+valueDisplay(currencyValue)
.mt-4

View file

@ -85,6 +85,8 @@ mixin itemTable(items)
a(href=`./block/${item.blockHash}`) #{item.summary}
else if (item.type == "address")
a(href=`./address/${item.address}`) #{item.summary}
else if (item.type == "extendedPubKey")
a(href=`./xyzpub/${item.extendedPubKey}`) #{item.summary}
else if (item.type == "link")
a(href=item.url) #{item.summary}