add getmininginfo to switch and move to alphabetical order.

more tests.
This commit is contained in:
Owain G. Ainsworth 2013-10-25 19:50:39 +01:00
parent 0daf04f9bd
commit 711f229487
2 changed files with 112 additions and 67 deletions

View file

@ -134,6 +134,9 @@ func ParseMarshaledCmd(b []byte) (Cmd, error) {
case "getinfo":
cmd = new(GetInfoCmd)
case "getmininginfo":
cmd = new(GetMiningInfoCmd)
case "getnettotals":
cmd = new(GetNetTotalsCmd)
@ -2181,6 +2184,66 @@ func (cmd *GetInfoCmd) UnmarshalJSON(b []byte) error {
return nil
}
// GetMiningInfoCmd is a type handling custom marshaling and
// unmarshaling of getmininginfo JSON RPC commands.
type GetMiningInfoCmd struct {
id interface{}
}
// Enforce that GetMiningInfoCmd satisifies the Cmd interface.
var _ Cmd = &GetMiningInfoCmd{}
// NewGetMiningInfoCmd creates a new GetMiningInfoCmd.
func NewGetMiningInfoCmd(id interface{}) (*GetMiningInfoCmd, error) {
return &GetMiningInfoCmd{
id: id,
}, nil
}
// Id satisfies the Cmd interface by returning the id of the command.
func (cmd *GetMiningInfoCmd) Id() interface{} {
return cmd.id
}
// Method satisfies the Cmd interface by returning the json method.
func (cmd *GetMiningInfoCmd) Method() string {
return "getmininginfo"
}
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *GetMiningInfoCmd) MarshalJSON() ([]byte, error) {
// Fill and marshal a RawCmd.
return json.Marshal(RawCmd{
Jsonrpc: "1.0",
Method: "getmininginfo",
Id: cmd.id,
Params: []interface{}{},
})
}
// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
// the Cmd interface.
func (cmd *GetMiningInfoCmd) UnmarshalJSON(b []byte) error {
// Unmashal into a RawCmd
var r RawCmd
if err := json.Unmarshal(b, &r); err != nil {
return err
}
if len(r.Params) != 0 {
return ErrWrongNumberOfParams
}
newCmd, err := NewGetMiningInfoCmd(r.Id)
if err != nil {
return err
}
*cmd = *newCmd
return nil
}
// GetNetTotalsCmd is a type handling custom marshaling and
// unmarshaling of getnettotals JSON RPC commands.
type GetNetTotalsCmd struct {
@ -2347,66 +2410,6 @@ func (cmd *GetNetworkHashPSCmd) UnmarshalJSON(b []byte) error {
return nil
}
// GetMiningInfoCmd is a type handling custom marshaling and
// unmarshaling of getmininginfo JSON RPC commands.
type GetMiningInfoCmd struct {
id interface{}
}
// Enforce that GetMiningInfoCmd satisifies the Cmd interface.
var _ Cmd = &GetMiningInfoCmd{}
// NewGetMiningInfoCmd creates a new GetMiningInfoCmd.
func NewGetMiningInfoCmd(id interface{}) (*GetMiningInfoCmd, error) {
return &GetMiningInfoCmd{
id: id,
}, nil
}
// Id satisfies the Cmd interface by returning the id of the command.
func (cmd *GetMiningInfoCmd) Id() interface{} {
return cmd.id
}
// Method satisfies the Cmd interface by returning the json method.
func (cmd *GetMiningInfoCmd) Method() string {
return "getmininginfo"
}
// MarshalJSON returns the JSON encoding of cmd. Part of the Cmd interface.
func (cmd *GetMiningInfoCmd) MarshalJSON() ([]byte, error) {
// Fill and marshal a RawCmd.
return json.Marshal(RawCmd{
Jsonrpc: "1.0",
Method: "getmininginfo",
Id: cmd.id,
Params: []interface{}{},
})
}
// UnmarshalJSON unmarshals the JSON encoding of cmd into cmd. Part of
// the Cmd interface.
func (cmd *GetMiningInfoCmd) UnmarshalJSON(b []byte) error {
// Unmashal into a RawCmd
var r RawCmd
if err := json.Unmarshal(b, &r); err != nil {
return err
}
if len(r.Params) != 0 {
return ErrWrongNumberOfParams
}
newCmd, err := NewGetMiningInfoCmd(r.Id)
if err != nil {
return err
}
*cmd = *newCmd
return nil
}
// GetNewAddressCmd is a type handling custom marshaling and
// unmarshaling of getnewaddress JSON RPC commands.
type GetNewAddressCmd struct {

View file

@ -310,7 +310,7 @@ var jsoncmdtests = []struct {
return NewGetBlockHashCmd(float64(1), 1234)
},
result: &GetBlockHashCmd{
id: float64(1),
id: float64(1),
Index: 1234,
},
},
@ -327,13 +327,13 @@ var jsoncmdtests = []struct {
name: "basic getblocktemplate + request",
f: func() (Cmd, error) {
return NewGetBlockTemplateCmd(float64(1),
&TemplateRequest{Mode:"mode",
Capabilities: []string{"one", "two", "three"}})
&TemplateRequest{Mode: "mode",
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
id: float64(1),
Request: &TemplateRequest{
Mode:"mode",
Request: &TemplateRequest{
Mode: "mode",
Capabilities: []string{
"one",
"two",
@ -347,11 +347,11 @@ var jsoncmdtests = []struct {
f: func() (Cmd, error) {
return NewGetBlockTemplateCmd(float64(1),
&TemplateRequest{
Capabilities: []string{"one", "two", "three"}})
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
id: float64(1),
Request: &TemplateRequest{
Request: &TemplateRequest{
Capabilities: []string{
"one",
"two",
@ -423,6 +423,48 @@ var jsoncmdtests = []struct {
id: float64(1),
},
},
{
name: "basic getnetworkhashps",
f: func() (Cmd, error) {
return NewGetNetworkHashPSCmd(float64(1))
},
result: &GetNetworkHashPSCmd{
id: float64(1),
Blocks: 120,
Height: -1,
},
},
{
name: "basic getnetworkhashps + blocks",
f: func() (Cmd, error) {
return NewGetNetworkHashPSCmd(float64(1), 5000)
},
result: &GetNetworkHashPSCmd{
id: float64(1),
Blocks: 5000,
Height: -1,
},
},
{
name: "basic getnetworkhashps + blocks + height",
f: func() (Cmd, error) {
return NewGetNetworkHashPSCmd(float64(1), 5000, 1000)
},
result: &GetNetworkHashPSCmd{
id: float64(1),
Blocks: 5000,
Height: 1000,
},
},
{
name: "basic getmininginfo",
f: func() (Cmd, error) {
return NewGetMiningInfoCmd(float64(1))
},
result: &GetMiningInfoCmd{
id: float64(1),
},
},
{
name: "basic ping",
f: func() (Cmd, error) {