vspd/webapi/vspinfo.go
Jamie Holdstock 9867f78385
Add network proportion to homepage and /vspinfo (and revoked proportion) (#264)
* Add network proportion to homepage and /vspinfo.

Proportion is calculated using the number of tickets  currently registered with the VSP, divided by the total size of the network ticket pool as reported by `getblockheader`.

The value will only ever be an estimate because:

- it's possible for a single ticket to be added to multiple VSPs.
- vspd does not distinguish between immature and live tickets, whereas `getblockheader` only reports live tickets.
- `getblockheader` is reporting the size of the ticket pool as of the previous block, not the current block.

* xaur suggestions

* Show missed ticket %, not just the raw number.
2021-06-08 08:47:07 -05:00

32 lines
877 B
Go

// Copyright (c) 2020 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/version"
"github.com/gin-gonic/gin"
)
// vspInfo is the handler for "GET /api/v3/vspinfo".
func vspInfo(c *gin.Context) {
cachedStats := getVSPStats()
sendJSONResponse(vspInfoResponse{
APIVersions: []int64{3},
Timestamp: time.Now().Unix(),
PubKey: signPubKey,
FeePercentage: cfg.VSPFee,
Network: cfg.NetParams.Name,
VspClosed: cfg.VspClosed,
VspdVersion: version.String(),
Voting: cachedStats.Voting,
Voted: cachedStats.Voted,
Revoked: cachedStats.Revoked,
BlockHeight: cachedStats.BlockHeight,
NetworkProportion: cachedStats.NetworkProportion,
}, c)
}