Skip to content

Commit

Permalink
fix getwork API
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi committed Jan 23, 2014
1 parent 3c1bcb8 commit 908945e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions jsoncmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3691,15 +3691,22 @@ type WorkRequest struct {
// unmarshaling of getwork JSON RPC commands.
type GetWorkCmd struct {
id interface{}
Request WorkRequest
Request *WorkRequest
}

// Enforce that GetWorkCmd satisifies the Cmd interface.
var _ Cmd = &GetWorkCmd{}

// NewGetWorkCmd creates a new GetWorkCmd. Optionally a
// 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{
id: id,
Request: request,
Expand Down Expand Up @@ -3727,9 +3734,10 @@ func (cmd *GetWorkCmd) MarshalJSON() ([]byte, error) {
Jsonrpc: "1.0",
Method: "getwork",
Id: cmd.id,
Params: []interface{}{
cmd.Request,
},
Params: []interface{}{},
}
if cmd.Request != nil {
raw.Params = append(raw.Params, cmd.Request)
}

return json.Marshal(raw)
Expand Down Expand Up @@ -3786,7 +3794,7 @@ func (cmd *GetWorkCmd) UnmarshalJSON(b []byte) error {
wrequest.Algorithm = salgo
}

newCmd, err := NewGetWorkCmd(r.Id, *wrequest)
newCmd, err := NewGetWorkCmd(r.Id, wrequest)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions jsoncmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,15 +736,15 @@ var jsoncmdtests = []struct {
cmd: "getwork",
f: func() (Cmd, error) {
return NewGetWorkCmd(testId,
WorkRequest{
&WorkRequest{
Data: "some data",
Target: "our target",
Algorithm: "algo",
})
},
result: &GetWorkCmd{
id: testId,
Request: WorkRequest{
Request: &WorkRequest{
Data: "some data",
Target: "our target",
Algorithm: "algo",
Expand Down

0 comments on commit 908945e

Please sign in to comment.