fix getwork API

closes #12
This commit is contained in:
David Hill 2014-01-23 15:55:52 -05:00
parent 3c1bcb86ee
commit 908945ed53
2 changed files with 16 additions and 8 deletions

View file

@ -3691,7 +3691,7 @@ type WorkRequest struct {
// unmarshaling of getwork JSON RPC commands. // unmarshaling of getwork JSON RPC commands.
type GetWorkCmd struct { type GetWorkCmd struct {
id interface{} id interface{}
Request WorkRequest Request *WorkRequest
} }
// Enforce that GetWorkCmd satisifies the Cmd interface. // Enforce that GetWorkCmd satisifies the Cmd interface.
@ -3699,7 +3699,14 @@ var _ Cmd = &GetWorkCmd{}
// NewGetWorkCmd creates a new GetWorkCmd. Optionally a // NewGetWorkCmd creates a new GetWorkCmd. Optionally a
// pointer to a TemplateRequest may be provided. // pointer to a TemplateRequest may be provided.
func NewGetWorkCmd(id interface{}, request WorkRequest) (*GetWorkCmd, error) { func NewGetWorkCmd(id interface{}, optArgs ...*WorkRequest) (*GetWorkCmd, error) {
var request *WorkRequest
if len(optArgs) > 0 {
if len(optArgs) > 1 {
return nil, ErrTooManyOptArgs
}
request = optArgs[0]
}
return &GetWorkCmd{ return &GetWorkCmd{
id: id, id: id,
Request: request, Request: request,
@ -3727,9 +3734,10 @@ func (cmd *GetWorkCmd) MarshalJSON() ([]byte, error) {
Jsonrpc: "1.0", Jsonrpc: "1.0",
Method: "getwork", Method: "getwork",
Id: cmd.id, Id: cmd.id,
Params: []interface{}{ Params: []interface{}{},
cmd.Request, }
}, if cmd.Request != nil {
raw.Params = append(raw.Params, cmd.Request)
} }
return json.Marshal(raw) return json.Marshal(raw)
@ -3786,7 +3794,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
} }

View file

@ -736,7 +736,7 @@ var jsoncmdtests = []struct {
cmd: "getwork", cmd: "getwork",
f: func() (Cmd, error) { f: func() (Cmd, error) {
return NewGetWorkCmd(testId, return NewGetWorkCmd(testId,
WorkRequest{ &WorkRequest{
Data: "some data", Data: "some data",
Target: "our target", Target: "our target",
Algorithm: "algo", Algorithm: "algo",
@ -744,7 +744,7 @@ var jsoncmdtests = []struct {
}, },
result: &GetWorkCmd{ result: &GetWorkCmd{
id: testId, id: testId,
Request: WorkRequest{ Request: &WorkRequest{
Data: "some data", Data: "some data",
Target: "our target", Target: "our target",
Algorithm: "algo", Algorithm: "algo",