Skip to content

Commit 0b78c9c

Browse files
ukane-philemonjholdstock
authored andcommitted
Show altsignaddress req/res in admin UI
1 parent 0fd9638 commit 0b78c9c

File tree

6 files changed

+70
-38
lines changed

6 files changed

+70
-38
lines changed

database/altsignaddr.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ type AltSignAddrData struct {
2626
// AltSignAddr is the new alternate signing address. It is base 58 encoded.
2727
AltSignAddr string
2828
// Req is the original request to set an alternate signing address.
29-
Req []byte
29+
Req string
3030
// ReqSig is the request's signature signed by the commitment address of the
3131
// corresponding ticket. It is base 64 encoded.
3232
ReqSig string
3333
// Resp is the original response from the server to the alternate signing
3434
// address.
35-
Resp []byte
35+
Resp string
3636
// RespSig is the response's signature signed by the server. It is base 64
3737
// encoded.
3838
RespSig string
@@ -66,15 +66,15 @@ func (vdb *VspDatabase) InsertAltSignAddr(ticketHash string, data *AltSignAddrDa
6666
return err
6767
}
6868

69-
if err := bkt.Put(reqK, data.Req); err != nil {
69+
if err := bkt.Put(reqK, []byte(data.Req)); err != nil {
7070
return err
7171
}
7272

7373
if err := bkt.Put(reqSigK, []byte(data.ReqSig)); err != nil {
7474
return err
7575
}
7676

77-
if err := bkt.Put(respK, data.Resp); err != nil {
77+
if err := bkt.Put(respK, []byte(data.Resp)); err != nil {
7878
return err
7979
}
8080
return bkt.Put(respSigK, []byte(data.RespSig))
@@ -113,9 +113,9 @@ func (vdb *VspDatabase) AltSignAddrData(ticketHash string) (*AltSignAddrData, er
113113
}
114114
h = &AltSignAddrData{
115115
AltSignAddr: string(bkt.Get(altSignAddrK)),
116-
Req: bkt.Get(reqK),
116+
Req: string(bkt.Get(reqK)),
117117
ReqSig: string(bkt.Get(reqSigK)),
118-
Resp: bkt.Get(respK),
118+
Resp: string(bkt.Get(respK)),
119119
RespSig: string(bkt.Get(respSigK)),
120120
}
121121
return nil

database/altsignaddr_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
func exampleAltSignAddrData() *AltSignAddrData {
1313
return &AltSignAddrData{
1414
AltSignAddr: randString(35, addrCharset),
15-
Req: randBytes(1000),
15+
Req: string(randBytes(1000)),
1616
ReqSig: randString(96, sigCharset),
17-
Resp: randBytes(1000),
17+
Resp: string(randBytes(1000)),
1818
RespSig: randString(96, sigCharset),
1919
}
2020
}

webapi/admin.go

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ type DcrdStatus struct {
3838
}
3939

4040
type searchResult struct {
41-
Hash string
42-
Found bool
43-
Ticket database.Ticket
44-
AltSignAddr string
45-
VoteChanges map[uint32]database.VoteChangeRecord
46-
MaxVoteChanges int
41+
Hash string
42+
Found bool
43+
Ticket database.Ticket
44+
AltSignAddrData *database.AltSignAddrData
45+
VoteChanges map[uint32]database.VoteChangeRecord
46+
MaxVoteChanges int
4747
}
4848

4949
func dcrdStatus(c *gin.Context) DcrdStatus {
@@ -176,19 +176,14 @@ func ticketSearch(c *gin.Context) {
176176
return
177177
}
178178

179-
altSignAddr := ""
180-
if altSignAddrData != nil {
181-
altSignAddr = altSignAddrData.AltSignAddr
182-
}
183-
184179
c.HTML(http.StatusOK, "admin.html", gin.H{
185180
"SearchResult": searchResult{
186-
Hash: hash,
187-
Found: found,
188-
Ticket: ticket,
189-
AltSignAddr: altSignAddr,
190-
VoteChanges: voteChanges,
191-
MaxVoteChanges: cfg.MaxVoteChangeRecords,
181+
Hash: hash,
182+
Found: found,
183+
Ticket: ticket,
184+
AltSignAddrData: altSignAddrData,
185+
VoteChanges: voteChanges,
186+
MaxVoteChanges: cfg.MaxVoteChangeRecords,
192187
},
193188
"WebApiCache": getCache(),
194189
"WebApiCfg": cfg,

webapi/setaltsignaddr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ func setAltSignAddr(c *gin.Context) {
111111

112112
data := &database.AltSignAddrData{
113113
AltSignAddr: altSignAddr,
114-
Req: reqBytes,
114+
Req: string(reqBytes),
115115
ReqSig: c.GetHeader("VSP-Client-Signature"),
116-
Resp: []byte(resp),
116+
Resp: resp,
117117
RespSig: respSig,
118118
}
119119

webapi/setaltsignaddr_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
maxVoteChangeRecords = 3
4343
)
4444

45+
// randBytes returns a byte slice of size n filled with random bytes.
4546
func randBytes(n int) []byte {
4647
slice := make([]byte, n)
4748
if _, err := seededRand.Read(slice); err != nil {
@@ -196,9 +197,9 @@ func TestSetAltSignAddress(t *testing.T) {
196197
if test.isExistingAltSignAddr {
197198
data := &database.AltSignAddrData{
198199
AltSignAddr: test.addr,
199-
Req: b,
200+
Req: string(b),
200201
ReqSig: reqSig,
201-
Resp: randBytes(1000),
202+
Resp: string(randBytes(1000)),
202203
RespSig: randString(96, sigCharset),
203204
}
204205
if err := db.InsertAltSignAddr(ticketHash, data); err != nil {
@@ -256,7 +257,7 @@ func TestSetAltSignAddress(t *testing.T) {
256257
continue
257258
}
258259

259-
if !bytes.Equal(b, altsig.Req) || altsig.ReqSig != reqSig {
260+
if !bytes.Equal(b, []byte(altsig.Req)) || altsig.ReqSig != reqSig {
260261
t.Fatalf("%q: expected alt sign addr data different than actual", test.name)
261262
}
262263
}

webapi/templates/ticket-search-result.html

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ <h1>Ticket</h1>
4040
</a>
4141
</td>
4242
</tr>
43-
<tr>
44-
<th>Alternate Signing Address</th>
45-
<td>
46-
<a href="{{ addressURL .AltSignAddr }}">
47-
{{ .AltSignAddr }}
48-
</a>
49-
</td>
50-
</tr>
5143
</table>
5244

5345
<h1>Fee</h1>
@@ -141,6 +133,50 @@ <h1>Vote Choices</h1>
141133
</tr>
142134
</table>
143135

136+
<h1>Alternate Signing Address</h1>
137+
138+
<table id="ticket-table" class="mt-2 mb-4 w-100">
139+
<tr>
140+
<th>Alternate Signing Address</th>
141+
<td>
142+
{{if .AltSignAddrData}}
143+
<a href="{{ addressURL .AltSignAddrData.AltSignAddr }}">
144+
{{ .AltSignAddrData.AltSignAddr }}
145+
</a>
146+
{{end}}
147+
</td>
148+
</tr>
149+
<tr>
150+
<th>
151+
AltSignAddress Change
152+
</th>
153+
<td>
154+
{{if .AltSignAddrData}}
155+
<details>
156+
<table class="my-2">
157+
<tr>
158+
<th>Request</th>
159+
<td>{{ indentJSON .AltSignAddrData.Req }}</td>
160+
</tr>
161+
<tr>
162+
<th>Request<br />Signature</th>
163+
<td>{{ .AltSignAddrData.ReqSig }}</td>
164+
</tr>
165+
<tr>
166+
<th>Response</th>
167+
<td>{{ indentJSON .AltSignAddrData.Resp }}</td>
168+
</tr>
169+
<tr>
170+
<th>Response<br />Signature</th>
171+
<td>{{ .AltSignAddrData.RespSig }}</td>
172+
</tr>
173+
</table>
174+
</details>
175+
{{end}}
176+
</td>
177+
</tr>
178+
</table>
179+
144180
{{ else }}
145181
<p>No ticket found with hash <span class="code">{{ .Hash }}</span></p>
146182
{{ end }}

0 commit comments

Comments
 (0)