From ca8d67e34a47594471a7cc88b1e4a33fabbb1a88 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 1 Nov 2024 12:09:03 +0000 Subject: [PATCH] webapi: Distinguish between current/old xpub Showing current and old pubkeys under separate headers makes the information easier to parse, and also fixes a bug where the current pubkey was showing a retired timestamp of unix epoch. --- internal/webapi/admin.go | 19 +++++++++++++++---- internal/webapi/templates/admin.html | 24 +++++++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/internal/webapi/admin.go b/internal/webapi/admin.go index d52963e..6af358c 100644 --- a/internal/webapi/admin.go +++ b/internal/webapi/admin.go @@ -160,13 +160,23 @@ func (w *WebAPI) renderAdmin(c *gin.Context, searchResult *searchResult) { missed.SortByPurchaseHeight() - xpubs, err := w.db.AllXPubs() + currentXPub, err := w.db.FeeXPub() if err != nil { - w.log.Errorf("db.AllXPubs error: %v", err) - c.String(http.StatusInternalServerError, "Error getting xpubs from db") + w.log.Errorf("db.FeeXPub error: %v", err) + c.String(http.StatusInternalServerError, "Error getting current xpub from db") return } + oldXPubs, err := w.db.AllXPubs() + if err != nil { + w.log.Errorf("db.AllXPubs error: %v", err) + c.String(http.StatusInternalServerError, "Error getting all xpubs from db") + return + } + + // Remove current xpub from the list of old xpubs. + delete(oldXPubs, currentXPub.ID) + c.HTML(http.StatusOK, "admin.html", gin.H{ "SearchResult": searchResult, "WebApiCache": cacheData, @@ -174,7 +184,8 @@ func (w *WebAPI) renderAdmin(c *gin.Context, searchResult *searchResult) { "WalletStatus": w.walletStatus(c), "DcrdStatus": w.dcrdStatus(c), "MissedTickets": missed, - "XPubs": xpubs, + "CurrentXPub": currentXPub, + "OldXPubs": oldXPubs, }) } diff --git a/internal/webapi/templates/admin.html b/internal/webapi/templates/admin.html index f6a7255..018223c 100644 --- a/internal/webapi/templates/admin.html +++ b/internal/webapi/templates/admin.html @@ -251,8 +251,26 @@
-

All X Pubs

- {{ with .XPubs }} +

Current X Pub

+ + + + + + + + + + + + + +
IDKeyLast Address Index
{{ .CurrentXPub.ID }}{{ .CurrentXPub.Key }}{{ .CurrentXPub.LastUsedIdx }}
+
+ + {{ with .OldXPubs }} +
+

Old X Pubs

@@ -271,8 +289,8 @@ {{ end }}
ID
- {{ end}}
+ {{ end }}