diff --git a/dcrjson/dcrdresults.go b/dcrjson/dcrdresults.go index f71d3682..1c2f7138 100644 --- a/dcrjson/dcrdresults.go +++ b/dcrjson/dcrdresults.go @@ -12,7 +12,7 @@ type GetStakeDifficultyResult struct { NextStakeDifficulty float64 `json:"next"` } -// VersionCount models a generic version:count tupple. +// VersionCount models a generic version:count tuple. type VersionCount struct { Version uint32 `json:"version"` Count uint32 `json:"count"` @@ -60,7 +60,7 @@ type Choice struct { Progress float64 `json:"progress"` } -// Agenda models an individual agenda including it's choices. +// Agenda models an individual agenda including its choices. type Agenda struct { Id string `json:"id"` Description string `json:"description"` diff --git a/rpcserver.go b/rpcserver.go index 16c8541d..92b18e6a 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3864,7 +3864,7 @@ func convertVersionMap(m map[int]int) []dcrjson.VersionCount { // handleGetStakeVersionInfo implements the getstakeversioninfo command. func handleGetStakeVersionInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (interface{}, error) { - count := int32(0) + count := int32(1) c, ok := cmd.(*dcrjson.GetStakeVersionInfoCmd) if !ok { return nil, internalRPCError("Invalid command", @@ -3872,9 +3872,10 @@ func handleGetStakeVersionInfo(s *rpcServer, cmd interface{}, closeChan <-chan s } if c.Count != nil { count = *c.Count - } - if count == 0 { - count = 1 + if count <= 0 { + return nil, internalRPCError("Invalid count", + "handleGetStakeVersionInfo") + } } snapshot := s.chain.BestSnapshot() @@ -3891,17 +3892,17 @@ func handleGetStakeVersionInfo(s *rpcServer, cmd interface{}, closeChan <-chan s endHeight := s.chain.CalcWantHeight(interval, snapshot.Height) + 1 hash := snapshot.Hash - adjust := int32(1) // we are off by one on the initial iteration. + adjust := int32(1) // We are off by one on the initial iteration. for i := int32(0); i < count; i++ { numBlocks := int32(startHeight - endHeight) if numBlocks <= 0 { // Just return what we got. - return result, nil + break } sv, err := s.chain.GetStakeVersions(hash, numBlocks+adjust) if err != nil { - // Just return what we got. - return result, nil + return nil, internalRPCError(err.Error(), + "handleGetStakeVersionInfo") } posVersions := make(map[int]int) @@ -3928,8 +3929,8 @@ func handleGetStakeVersionInfo(s *rpcServer, cmd interface{}, closeChan <-chan s // Get prior block hash. hash, err = s.chain.BlockHashByHeight(startHeight - 1) if err != nil { - // Just return what we got. - return result, nil + return nil, internalRPCError(err.Error(), + "handleGetStakeVersionInfo") } } diff --git a/rpcserverhelp.go b/rpcserverhelp.go index 3dc99086..9fc19089 100644 --- a/rpcserverhelp.go +++ b/rpcserverhelp.go @@ -409,7 +409,7 @@ var helpDescsEnUS = map[string]string{ "getstakedifficultyresult-next": "The calculated stake difficulty of the next block", // GetStakeVersionInfoCmd help. - "getstakeversioninfo--synopsis": "Returns the stake versions statistics.", + "getstakeversioninfo--synopsis": "Returns stake version statistics for one or more stake version intervals.", "getstakeversioninfo-count": "Number of intervals to return.", "getstakeversioninforesult-currentheight": "Top of the chain height.", "getstakeversioninforesult-hash": "Top of the chain hash.",