Endpoint for JSON wallet status

This commit is contained in:
jholdstock 2020-07-06 10:48:24 +01:00 committed by David Hill
parent 1c351d02ec
commit 3bbad27624
2 changed files with 18 additions and 9 deletions

View File

@ -8,16 +8,18 @@ import (
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
) )
// WalletStatus describes the current status of a single voting wallet. // WalletStatus describes the current status of a single voting wallet. This is
// used by the admin.html template, and also serialized to JSON for the
// /admin/status endpoint.
type WalletStatus struct { type WalletStatus struct {
Connected bool Connected bool `json:"connected"`
InfoError bool InfoError bool `json:"infoerror"`
DaemonConnected bool DaemonConnected bool `json:"daemonconnected"`
VoteVersion uint32 VoteVersion uint32 `json:"voteversion"`
Unlocked bool Unlocked bool `json:"unlocked"`
Voting bool Voting bool `json:"voting"`
BestBlockError bool BestBlockError bool `json:"bestblockerror"`
BestBlockHeight int64 BestBlockHeight int64 `json:"bestblockheight"`
} }
func walletStatus(c *gin.Context) map[string]WalletStatus { func walletStatus(c *gin.Context) map[string]WalletStatus {
@ -56,6 +58,12 @@ func walletStatus(c *gin.Context) map[string]WalletStatus {
return walletStatus return walletStatus
} }
// statusJSON is the handler for "GET /admin/status". It returns a JSON object
// describing the current status of voting wallets.
func statusJSON(c *gin.Context) {
c.AbortWithStatusJSON(http.StatusOK, walletStatus(c))
}
// adminPage is the handler for "GET /admin". // adminPage is the handler for "GET /admin".
func adminPage(c *gin.Context) { func adminPage(c *gin.Context) {
c.HTML(http.StatusOK, "admin.html", gin.H{ c.HTML(http.StatusOK, "admin.html", gin.H{

View File

@ -208,6 +208,7 @@ func router(debugMode bool, cookieSecret []byte, dcrd rpc.DcrdConnect, wallets r
withWalletClients(wallets), withSession(cookieStore), requireAdmin(), withWalletClients(wallets), withSession(cookieStore), requireAdmin(),
) )
admin.GET("", adminPage) admin.GET("", adminPage)
admin.GET("/status", statusJSON)
admin.POST("/ticket", ticketSearch) admin.POST("/ticket", ticketSearch)
admin.GET("/backup", downloadDatabaseBackup) admin.GET("/backup", downloadDatabaseBackup)
admin.POST("/logout", adminLogout) admin.POST("/logout", adminLogout)