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"
)
// 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 {
Connected bool
InfoError bool
DaemonConnected bool
VoteVersion uint32
Unlocked bool
Voting bool
BestBlockError bool
BestBlockHeight int64
Connected bool `json:"connected"`
InfoError bool `json:"infoerror"`
DaemonConnected bool `json:"daemonconnected"`
VoteVersion uint32 `json:"voteversion"`
Unlocked bool `json:"unlocked"`
Voting bool `json:"voting"`
BestBlockError bool `json:"bestblockerror"`
BestBlockHeight int64 `json:"bestblockheight"`
}
func walletStatus(c *gin.Context) map[string]WalletStatus {
@ -56,6 +58,12 @@ func walletStatus(c *gin.Context) map[string]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".
func adminPage(c *gin.Context) {
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(),
)
admin.GET("", adminPage)
admin.GET("/status", statusJSON)
admin.POST("/ticket", ticketSearch)
admin.GET("/backup", downloadDatabaseBackup)
admin.POST("/logout", adminLogout)