Exporting this struct is a step towards breaking up the Start func into
a New func and Run func, enabling calling code to use:
api := webapi.New()
api.Run()
WebAPI is a more suitable name than server because it matches the
package name, and also it helps to distinguish WebAPI from the HTTP
server it uses internally (ie. webapi.server rather than server.server).
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// Copyright (c) 2020-2023 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 (
|
|
"time"
|
|
|
|
"github.com/decred/vspd/internal/version"
|
|
"github.com/decred/vspd/types/v2"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// vspInfo is the handler for "GET /api/v3/vspinfo".
|
|
func (w *WebAPI) vspInfo(c *gin.Context) {
|
|
cachedStats := w.cache.getData()
|
|
w.sendJSONResponse(types.VspInfoResponse{
|
|
APIVersions: []int64{3},
|
|
Timestamp: time.Now().Unix(),
|
|
PubKey: w.signPubKey,
|
|
FeePercentage: w.cfg.VSPFee,
|
|
Network: w.cfg.Network.Name,
|
|
VspClosed: w.cfg.VspClosed,
|
|
VspClosedMsg: w.cfg.VspClosedMsg,
|
|
VspdVersion: version.String(),
|
|
Voting: cachedStats.Voting,
|
|
Voted: cachedStats.Voted,
|
|
TotalVotingWallets: cachedStats.TotalVotingWallets,
|
|
VotingWalletsOnline: cachedStats.VotingWalletsOnline,
|
|
Revoked: cachedStats.Expired + cachedStats.Missed,
|
|
Expired: cachedStats.Expired,
|
|
Missed: cachedStats.Missed,
|
|
BlockHeight: cachedStats.BlockHeight,
|
|
NetworkProportion: cachedStats.NetworkProportion,
|
|
}, c)
|
|
}
|