Add getwork result infrastructure. Make the work request optional.

This commit is contained in:
David Hill 2014-01-23 17:30:44 -05:00
parent 908945ed53
commit 4a93564b04
2 changed files with 50 additions and 37 deletions

View file

@ -173,6 +173,14 @@ type GetMiningInfoResult struct {
HashesPerSec float64 `json:"hashespersec"` HashesPerSec float64 `json:"hashespersec"`
} }
// GetWorkResult models the data from the getwork command.
type GetWorkResult struct {
Data string `json:"data"`
Hash1 string `json:"hash1"`
Midstate string `json:"midstate"`
Target string `json:"target"`
}
// ValidateAddressResult models the data from the validateaddress command. // ValidateAddressResult models the data from the validateaddress command.
type ValidateAddressResult struct { type ValidateAddressResult struct {
IsValid bool `json:"isvalid"` IsValid bool `json:"isvalid"`
@ -872,6 +880,12 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
if err == nil { if err == nil {
result.Result = res result.Result = res
} }
case "getwork":
var res GetWorkResult
err = json.Unmarshal(objmap["result"], &res)
if err == nil {
result.Result = res
}
case "validateaddress": case "validateaddress":
var res ValidateAddressResult var res ValidateAddressResult
err = json.Unmarshal(objmap["result"], &res) err = json.Unmarshal(objmap["result"], &res)

View file

@ -3751,17 +3751,16 @@ func (cmd *GetWorkCmd) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &r); err != nil { if err := json.Unmarshal(b, &r); err != nil {
return err return err
} }
if len(r.Params) > 1 {
if len(r.Params) != 1 {
return ErrWrongNumberOfParams return ErrWrongNumberOfParams
} }
wrequest := new(WorkRequest)
if len(r.Params) == 1 {
rmap, ok := r.Params[0].(map[string]interface{}) rmap, ok := r.Params[0].(map[string]interface{})
if !ok { if !ok {
return errors.New("first optional parameter template request must be an object") return errors.New("first optional parameter template request must be an object")
} }
wrequest := new(WorkRequest)
// data is required // data is required
data, ok := rmap["data"] data, ok := rmap["data"]
if !ok { if !ok {
@ -3793,7 +3792,7 @@ func (cmd *GetWorkCmd) UnmarshalJSON(b []byte) error {
} }
wrequest.Algorithm = salgo wrequest.Algorithm = salgo
} }
}
newCmd, err := NewGetWorkCmd(r.Id, wrequest) newCmd, err := NewGetWorkCmd(r.Id, wrequest)
if err != nil { if err != nil {
return err return err