Skip to content

Commit

Permalink
Add GetStakeDifficultyResult so we can have current and next returned
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlyp committed Apr 28, 2016
1 parent 4328736 commit 8207e4d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions dcrjson/dcrdextresults.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

package dcrjson

// GetStakeDifficultyResult models the data returned from the
// getstakedifficulty command.
type GetStakeDifficultyResult struct {
CurrentStakeDifficulty float64 `json:"current"`
NextStakeDifficulty float64 `json:"next"`
}

// LiveTicketsResult models the data returned from the livetickets
// command.
type LiveTicketsResult struct {
Expand Down
15 changes: 13 additions & 2 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -3606,9 +3606,20 @@ func handleGetStakeDifficulty(s *rpcServer, cmd interface{}, closeChan <-chan st
Message: "Error getting stake difficulty: " + err.Error(),
}
}
sDiff := dcrutil.Amount(blockHeader.SBits)
currentSdiff := dcrutil.Amount(blockHeader.SBits)

return sDiff.ToCoin(), nil
nextSdiff, err := s.server.blockManager.CalcNextRequiredStakeDifficulty()
if err != nil {
return nil, err
}
nextSdiffAmount := dcrutil.Amount(nextSdiff)

sDiffResult := &dcrjson.GetStakeDifficultyResult{
CurrentStakeDifficulty: currentSdiff.ToCoin(),
NextStakeDifficulty: nextSdiffAmount.ToCoin(),
}

return sDiffResult, nil
}

// handleGetTicketPoolValue implements the getticketpoolvalue command.
Expand Down
7 changes: 4 additions & 3 deletions rpcserverhelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ var helpDescsEnUS = map[string]string{
"getdifficulty--result0": "The difficulty",

// GetStakeDifficultyCmd help.
"getstakedifficulty--synopsis": "Returns the proof-of-stake difficulty.",
"getstakedifficulty--result0": "The stake difficulty",
"getstakedifficulty--synopsis": "Returns the proof-of-stake difficulty.",
"getstakedifficultyresult-current": "The current top block's stake difficulty",
"getstakedifficultyresult-next": "The calculated stake difficulty of the next block",

// GetGenerateCmd help.
"getgenerate--synopsis": "Returns if the server is set to generate coins (mine) or not.",
Expand Down Expand Up @@ -736,7 +737,7 @@ var rpcResultTypes = map[string][]interface{}{
"getconnectioncount": []interface{}{(*int32)(nil)},
"getcurrentnet": []interface{}{(*uint32)(nil)},
"getdifficulty": []interface{}{(*float64)(nil)},
"getstakedifficulty": []interface{}{(*float64)(nil)},
"getstakedifficulty": []interface{}{(*dcrjson.GetStakeDifficultyResult)(nil)},
"getgenerate": []interface{}{(*bool)(nil)},
"gethashespersec": []interface{}{(*float64)(nil)},
"getinfo": []interface{}{(*dcrjson.InfoChainResult)(nil)},
Expand Down

0 comments on commit 8207e4d

Please sign in to comment.