Skip to content

Commit 2ad669a

Browse files
authoredSep 21, 2022
VSPs: Add BlockHeight & EstimatedNetworkProportion
1 parent 0c0f0bb commit 2ad669a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ dcrwebapi
44
.DS_Store
55
vendor/
66
.vscode/
7+
.idea/
78

89
# Testing, profiling, and benchmarking artifacts
910
cov.out

‎service.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ type Vsp struct {
5050
// Set by dcrwebapi each time info is successfully updated.
5151
LastUpdated int64 `json:"lastupdated"`
5252
// Retrieved from the /api/vspinfo.
53-
APIVersions []int64 `json:"apiversions"`
54-
FeePercentage float64 `json:"feepercentage"`
55-
Closed bool `json:"closed"`
56-
Voting int64 `json:"voting"`
57-
Voted int64 `json:"voted"`
58-
Revoked int64 `json:"revoked"`
59-
VspdVersion string `json:"vspdversion"`
53+
APIVersions []int64 `json:"apiversions"`
54+
FeePercentage float64 `json:"feepercentage"`
55+
Closed bool `json:"closed"`
56+
Voting int64 `json:"voting"`
57+
Voted int64 `json:"voted"`
58+
Revoked int64 `json:"revoked"`
59+
VspdVersion string `json:"vspdversion"`
60+
BlockHeight uint64 `json:"blockheight"`
61+
EstimatedNetworkProportion float64 `json:"estimatednetworkproportion"`
6062
}
6163
type vspSet map[string]Vsp
6264

@@ -65,8 +67,7 @@ type Stakepool struct {
6567
// APIEnabled defines if the api is enabled.
6668
APIEnabled bool `json:"APIEnabled"`
6769

68-
// APIVersionsSupported contains the collection of collection of API
69-
// versions supported.
70+
// APIVersionsSupported contains the collection of API versions supported.
7071
APIVersionsSupported []interface{} `json:"APIVersionsSupported"`
7172

7273
// Network defines the active network.
@@ -561,9 +562,12 @@ func vspStats(service *Service, url string) error {
561562
voted, hasVoted := info["voted"]
562563
revoked, hasRevoked := info["revoked"]
563564
version, hasVersion := info["vspdversion"]
565+
blockheight, hasBlockHeight := info["blockheight"]
566+
networkproportion, hasnetworkproportion := info["estimatednetworkproportion"]
564567

565568
hasRequiredFields := hasAPIVersions && hasFeePercentage &&
566-
hasClosed && hasVoting && hasVoted && hasRevoked && hasVersion
569+
hasClosed && hasVoting && hasVoted && hasRevoked && hasVersion &&
570+
hasBlockHeight && hasnetworkproportion
567571

568572
if !hasRequiredFields {
569573
return fmt.Errorf("%v: missing required fields: %+v", infoURL, info)
@@ -580,6 +584,8 @@ func vspStats(service *Service, url string) error {
580584
vsp.Voted = int64(voted.(float64))
581585
vsp.Revoked = int64(revoked.(float64))
582586
vsp.VspdVersion = version.(string)
587+
vsp.BlockHeight = uint64(blockheight.(float64))
588+
vsp.EstimatedNetworkProportion = networkproportion.(float64)
583589

584590
vsp.LastUpdated = time.Now().Unix()
585591

0 commit comments

Comments
 (0)