Getblockhash and getblock template
Fix some type wranging in unmarshal for getblocktemplate
This commit is contained in:
parent
ebc4c17162
commit
020444906b
2 changed files with 68 additions and 3 deletions
15
jsoncmd.go
15
jsoncmd.go
|
@ -1853,11 +1853,20 @@ func (cmd *GetBlockTemplateCmd) UnmarshalJSON(b []byte) error {
|
||||||
|
|
||||||
capabilities, ok := rmap["capabilities"]
|
capabilities, ok := rmap["capabilities"]
|
||||||
if ok {
|
if ok {
|
||||||
scap, ok := capabilities.([]string)
|
icap, ok := capabilities.([]interface{})
|
||||||
if !ok {
|
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)
|
optArgs = append(optArgs, trequest)
|
||||||
|
|
|
@ -304,6 +304,62 @@ var jsoncmdtests = []struct {
|
||||||
id: float64(1),
|
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",
|
name: "basic ping",
|
||||||
f: func() (Cmd, error) {
|
f: func() (Cmd, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue