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"`
|
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)
|
||||||
|
|
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 {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
wrequest := new(WorkRequest)
|
||||||
// data is required
|
if len(r.Params) == 1 {
|
||||||
data, ok := rmap["data"]
|
rmap, ok := r.Params[0].(map[string]interface{})
|
||||||
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 {
|
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)
|
newCmd, err := NewGetWorkCmd(r.Id, wrequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue