Getblockhash and getblock template

Fix some type wranging in unmarshal for getblocktemplate
This commit is contained in:
Owain G. Ainsworth 2013-10-25 19:00:33 +01:00
parent ebc4c17162
commit 020444906b
2 changed files with 68 additions and 3 deletions

View file

@ -1853,11 +1853,20 @@ func (cmd *GetBlockTemplateCmd) UnmarshalJSON(b []byte) error {
capabilities, ok := rmap["capabilities"]
if ok {
scap, ok := capabilities.([]string)
icap, ok := capabilities.([]interface{})
if !ok {
return errors.New("TemplateRequest mode must be a string array")
return errors.New("TemplateRequest mode must be an array")
}
trequest.Capabilities = scap
cap := make([]string, len(icap))
for i, val := range icap {
cap[i], ok = val.(string)
if !ok {
return errors.New("TemplateRequest mode must be an aray of strings")
}
}
trequest.Capabilities = cap
}
optArgs = append(optArgs, trequest)

View file

@ -304,6 +304,62 @@ var jsoncmdtests = []struct {
id: float64(1),
},
},
{
name: "basic getblockhash",
f: func() (Cmd, error) {
return NewGetBlockHashCmd(float64(1), 1234)
},
result: &GetBlockHashCmd{
id: float64(1),
Index: 1234,
},
},
{
name: "basic getblocktemplate",
f: func() (Cmd, error) {
return NewGetBlockTemplateCmd(float64(1))
},
result: &GetBlockTemplateCmd{
id: float64(1),
},
},
{
name: "basic getblocktemplate + request",
f: func() (Cmd, error) {
return NewGetBlockTemplateCmd(float64(1),
&TemplateRequest{Mode:"mode",
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
id: float64(1),
Request: &TemplateRequest{
Mode:"mode",
Capabilities: []string{
"one",
"two",
"three",
},
},
},
},
{
name: "basic getblocktemplate + request no mode",
f: func() (Cmd, error) {
return NewGetBlockTemplateCmd(float64(1),
&TemplateRequest{
Capabilities: []string{"one", "two", "three"}})
},
result: &GetBlockTemplateCmd{
id: float64(1),
Request: &TemplateRequest{
Capabilities: []string{
"one",
"two",
"three",
},
},
},
},
{
name: "basic ping",
f: func() (Cmd, error) {