-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e23e372
commit 3f45dee
Showing
6 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{{ template "header" . }} | ||
|
||
<div class="vsp-overview pt-4 pb-3 mb-3"> | ||
<div class="container"> | ||
|
||
<div class="d-flex flex-wrap"> | ||
<h1>Ticket Search</h1> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12 pt-2 pb-4"> | ||
<div class="block__content"> | ||
<section> | ||
<form action="/ticket" method="post"> | ||
<p class="my-1 orange" style="visibility:{{ if .Error }}visible{{ else }}hidden{{ end }};"> | ||
{{.Error}}</p> | ||
|
||
<div class="mb-3 col col-lg-8 pl-0"> | ||
<label for="encodedInput" class="form-label">Encoded Base64 String</label> | ||
<input type="text" name="encoded" size="64" class="form-control shadow-none" minlength="64" | ||
maxlength="500" id="encodedInput" required placeholder="Encoded string" autocomplete="off" value=""> | ||
</div> | ||
<button class="btn btn-primary d-block my-2" type="submit">Search</button> | ||
</form> | ||
|
||
{{ with .SearchResult }} | ||
{{ template "ticket-search-result" . }} | ||
{{ end }} | ||
</section> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
{{ template "footer" . }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters