-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathticket.go
More file actions
71 lines (60 loc) · 1.96 KB
/
Copy pathticket.go
File metadata and controls
71 lines (60 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package webapi
import (
"net/http"
"github.com/decred/vspd/database"
"github.com/gin-gonic/gin"
)
// ticketPage is the handler for "GET /ticket"
func (s *Server) ticketPage(c *gin.Context) {
c.HTML(http.StatusOK, "ticket.html", gin.H{
"WebApiCache": s.cache.getData(),
"WebApiCfg": s.cfg,
})
}
// ticketErrPage returns error message to the ticket page.
func (s *Server) ticketErrPage(c *gin.Context, status int, message string) {
c.HTML(status, "ticket.html", gin.H{
"WebApiCache": s.cache.getData(),
"WebApiCfg": s.cfg,
"Error": message,
})
}
// manualTicketSearch is the handler for "POST /ticket".
func (s *Server) manualTicketSearch(c *gin.Context) {
// Get values which have been added to context by middleware.
err := c.MustGet(errorKey)
if err != nil {
apiErr := err.(apiError)
s.ticketErrPage(c, apiErr.httpStatus(), apiErr.String())
return
}
ticket := c.MustGet(ticketKey).(database.Ticket)
knownTicket := c.MustGet(knownTicketKey).(bool)
voteChanges, err := s.db.GetVoteChanges(ticket.Hash)
if err != nil {
s.log.Errorf("db.GetVoteChanges error (ticket=%s): %v", ticket.Hash, err)
s.ticketErrPage(c, http.StatusBadRequest, "Error getting vote changes from database")
return
}
altSignAddrData, err := s.db.AltSignAddrData(ticket.Hash)
if err != nil {
s.log.Errorf("db.AltSignAddrData error (ticket=%s): %v", ticket.Hash, err)
s.ticketErrPage(c, http.StatusBadRequest, "Error getting alternate signature from database")
return
}
c.HTML(http.StatusOK, "ticket.html", gin.H{
"SearchResult": searchResult{
Hash: ticket.Hash,
Found: knownTicket,
Ticket: ticket,
AltSignAddrData: altSignAddrData,
VoteChanges: voteChanges,
MaxVoteChanges: s.cfg.MaxVoteChangeRecords,
},
"WebApiCache": s.cache.getData(),
"WebApiCfg": s.cfg,
})
}