Add getwork result infrastructure. Make the work request optional.
This commit is contained in:
parent
908945ed53
commit
4a93564b04
2 changed files with 50 additions and 37 deletions
14
jsonapi.go
14
jsonapi.go
|
@ -173,6 +173,14 @@ type GetMiningInfoResult struct {
|
|||
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.
|
||||
type ValidateAddressResult struct {
|
||||
IsValid bool `json:"isvalid"`
|
||||
|
@ -872,6 +880,12 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
|
|||
if err == nil {
|
||||
result.Result = res
|
||||
}
|
||||
case "getwork":
|
||||
var res GetWorkResult
|
||||
err = json.Unmarshal(objmap["result"], &res)
|
||||
if err == nil {
|
||||
result.Result = res
|
||||
}
|
||||
case "validateaddress":
|
||||
var res ValidateAddressResult
|
||||
err = json.Unmarshal(objmap["result"], &res)
|
||||
|
|
73
jsoncmd.go
73
jsoncmd.go
|
@ -3751,49 +3751,48 @@ func (cmd *GetWorkCmd) UnmarshalJSON(b []byte) error {
|
|||
if err := json.Unmarshal(b, &r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(r.Params) != 1 {
|
||||
if len(r.Params) > 1 {
|
||||
return ErrWrongNumberOfParams
|
||||
}
|
||||
|
||||
rmap, ok := r.Params[0].(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("first optional parameter template request must be an object")
|
||||
}
|
||||
|
||||
wrequest := new(WorkRequest)
|
||||
// data is required
|
||||
data, ok := rmap["data"]
|
||||
if !ok {
|
||||
return errors.New("WorkRequest data must be present")
|
||||
}
|
||||
sdata, ok := data.(string)
|
||||
if !ok {
|
||||
return errors.New("WorkRequest data must be a string")
|
||||
}
|
||||
wrequest.Data = sdata
|
||||
|
||||
// target is required
|
||||
target, ok := rmap["target"]
|
||||
if !ok {
|
||||
return errors.New("WorkRequest target must be present")
|
||||
}
|
||||
starget, ok := target.(string)
|
||||
if !ok {
|
||||
return errors.New("WorkRequest target must be a string")
|
||||
}
|
||||
wrequest.Target = starget
|
||||
|
||||
// algorithm is optional
|
||||
algo, ok := rmap["algorithm"]
|
||||
if ok {
|
||||
salgo, ok := algo.(string)
|
||||
if len(r.Params) == 1 {
|
||||
rmap, ok := r.Params[0].(map[string]interface{})
|
||||
if !ok {
|
||||
return errors.New("WorkRequest algorithm must be a string")
|
||||
return errors.New("first optional parameter template request must be an object")
|
||||
}
|
||||
wrequest.Algorithm = salgo
|
||||
}
|
||||
|
||||
// data is required
|
||||
data, ok := rmap["data"]
|
||||
if !ok {
|
||||
return errors.New("WorkRequest data must be present")
|
||||
}
|
||||
sdata, ok := data.(string)
|
||||
if !ok {
|
||||
return errors.New("WorkRequest data must be a string")
|
||||
}
|
||||
wrequest.Data = sdata
|
||||
|
||||
// target is required
|
||||
target, ok := rmap["target"]
|
||||
if !ok {
|
||||
return errors.New("WorkRequest target must be present")
|
||||
}
|
||||
starget, ok := target.(string)
|
||||
if !ok {
|
||||
return errors.New("WorkRequest target must be a string")
|
||||
}
|
||||
wrequest.Target = starget
|
||||
|
||||
// algorithm is optional
|
||||
algo, ok := rmap["algorithm"]
|
||||
if ok {
|
||||
salgo, ok := algo.(string)
|
||||
if !ok {
|
||||
return errors.New("WorkRequest algorithm must be a string")
|
||||
}
|
||||
wrequest.Algorithm = salgo
|
||||
}
|
||||
}
|
||||
newCmd, err := NewGetWorkCmd(r.Id, wrequest)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue