Skip to content

Commit

Permalink
webapi: List xpubs on admin page.
Browse files Browse the repository at this point in the history
A new tab is added to the admin page to display current and historic
xpub keys used by vspd.
  • Loading branch information
jholdstock committed Jun 27, 2024
1 parent 4e41213 commit 844d2ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
18 changes: 17 additions & 1 deletion internal/webapi/admin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 The Decred developers
// Copyright (c) 2020-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -155,12 +155,20 @@ func (w *WebAPI) adminPage(c *gin.Context) {

missed.SortByPurchaseHeight()

xpubs, err := w.db.AllXPubs()
if err != nil {
w.log.Errorf("db.AllXPubs error: %v", err)
c.String(http.StatusInternalServerError, "Error getting xpubs from db")
return
}

c.HTML(http.StatusOK, "admin.html", gin.H{
"WebApiCache": cacheData,
"WebApiCfg": w.cfg,
"WalletStatus": w.walletStatus(c),
"DcrdStatus": w.dcrdStatus(c),
"MissedTickets": missed,
"XPubs": xpubs,
})
}

Expand Down Expand Up @@ -231,6 +239,13 @@ func (w *WebAPI) ticketSearch(c *gin.Context) {

missed.SortByPurchaseHeight()

xpubs, err := w.db.AllXPubs()
if err != nil {
w.log.Errorf("db.AllXPubs error: %v", err)
c.String(http.StatusInternalServerError, "Error getting xpubs from db")
return
}

c.HTML(http.StatusOK, "admin.html", gin.H{
"SearchResult": searchResult{
Hash: hash,
Expand All @@ -246,6 +261,7 @@ func (w *WebAPI) ticketSearch(c *gin.Context) {
"WalletStatus": w.walletStatus(c),
"DcrdStatus": w.dcrdStatus(c),
"MissedTickets": missed,
"XPubs": xpubs,
})
}

Expand Down
10 changes: 7 additions & 3 deletions internal/webapi/public/css/vspd.css
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ table.missed-tickets td {
.tabset > input:nth-child(4):focus ~ ul li:nth-child(4) label,
.tabset > input:nth-child(4):hover ~ ul li:nth-child(4) label,
.tabset > input:nth-child(5):focus ~ ul li:nth-child(5) label,
.tabset > input:nth-child(5):hover ~ ul li:nth-child(5) label {
.tabset > input:nth-child(5):hover ~ ul li:nth-child(5) label,
.tabset > input:nth-child(6):focus ~ ul li:nth-child(6) label,
.tabset > input:nth-child(6):hover ~ ul li:nth-child(6) label {
cursor: pointer;
color: #091440;
}
Expand All @@ -255,7 +257,8 @@ table.missed-tickets td {
.tabset > input:nth-child(2):checked ~ ul li:nth-child(2) label,
.tabset > input:nth-child(3):checked ~ ul li:nth-child(3) label,
.tabset > input:nth-child(4):checked ~ ul li:nth-child(4) label,
.tabset > input:nth-child(5):checked ~ ul li:nth-child(5) label {
.tabset > input:nth-child(5):checked ~ ul li:nth-child(5) label,
.tabset > input:nth-child(6):checked ~ ul li:nth-child(6) label {
border-bottom: 5px solid #2ed8a3;
color: #091440;
cursor: default;
Expand All @@ -275,6 +278,7 @@ table.missed-tickets td {
.tabset > input:nth-child(2):checked ~ div > section:nth-child(2),
.tabset > input:nth-child(3):checked ~ div > section:nth-child(3),
.tabset > input:nth-child(4):checked ~ div > section:nth-child(4),
.tabset > input:nth-child(5):checked ~ div > section:nth-child(5) {
.tabset > input:nth-child(5):checked ~ div > section:nth-child(5),
.tabset > input:nth-child(6):checked ~ div > section:nth-child(6) {
position:static;
}
35 changes: 33 additions & 2 deletions internal/webapi/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,19 @@ <h1>Admin Panel</h1>
id="tabset_1_5"
hidden
>
<input
type="radio"
name="tabset_1"
id="tabset_1_6"
hidden
>
<ul>
<li><label for="tabset_1_1">VSP Status</label></li>
<li><label for="tabset_1_2">Ticket Search</label></li>
<li><label for="tabset_1_3">Missed Tickets</label></li>
<li><label for="tabset_1_4">Database</label></li>
<li><label for="tabset_1_5">Logout</label></li>
<li><label for="tabset_1_4">Fee X Pubs</label></li>
<li><label for="tabset_1_5">Database</label></li>
<li><label for="tabset_1_6">Logout</label></li>
</ul>

<div>
Expand Down Expand Up @@ -222,6 +229,30 @@ <h1>{{ pluralize (len .MissedTickets) "Missed Ticket" }}</h1>
{{ end}}
</section>

<section>
<h1>All X Pubs</h1>
{{ with .XPubs }}
<table class="mx-auto">
<thead>
<th>ID</th>
<th>Key</th>
<th>Last Address Index</th>
<th>Retired</th>
</thead>
<tbody>
{{ range . }}
<tr>
<td>{{ .ID }}</td>
<td>{{ .Key }}</td>
<td>{{ .LastUsedIdx }}</td>
<td>{{ dateTime .Retired }}</td>
</tr>
{{ end }}
</tbody>
</table>
{{ end}}
</section>

<section>
<p>Database size: {{ .WebApiCache.DatabaseSize }}</p>
<a class="btn btn-primary" href="/admin/backup" download>Download Backup</a>
Expand Down

0 comments on commit 844d2ce

Please sign in to comment.