Fix admin page load when no wallet clients connected.

This commit is contained in:
jholdstock 2020-08-03 16:17:19 +01:00 committed by David Hill
parent aa790b28aa
commit 4bcfa80dc4
2 changed files with 11 additions and 6 deletions

View File

@ -90,17 +90,15 @@ func withDcrdClient(dcrd rpc.DcrdConnect) gin.HandlerFunc {
}
}
// withWalletClients middleware adds a voting wallet clients to the request
// context for downstream handlers to make use of.
// withWalletClients middleware attempts to add voting wallet clients to the
// request context for downstream handlers to make use of. Downstream handlers
// must handle the case where no wallet clients are connected.
func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
return func(c *gin.Context) {
clients, failedConnections := wallets.Clients(c, cfg.NetParams)
if len(clients) == 0 {
log.Error("Could not connect to any wallets")
sendError(errInternalError, c)
return
}
if len(failedConnections) > 0 {
} else if len(failedConnections) > 0 {
log.Errorf("Failed to connect to %d wallet(s), proceeding with only %d",
len(failedConnections), len(clients))
}

View File

@ -17,6 +17,13 @@ func setVoteChoices(c *gin.Context) {
knownTicket := c.MustGet("KnownTicket").(bool)
walletClients := c.MustGet("WalletClients").([]*rpc.WalletRPC)
// If we cannot set the vote choices on at least one voting wallet right
// now, don't update the database, just return an error.
if len(walletClients) == 0 {
sendError(errInternalError, c)
return
}
if !knownTicket {
log.Warnf("%s: Unknown ticket (clientIP=%s)", funcName, c.ClientIP())
sendError(errUnknownTicket, c)