Allow getblock result to be string or BlockResult.
The getblock command has recently added a verbose flag which alters the output. The previous code added a new field "Hex" to the BlockResult, but this is not consistent with the origin getblock RPC call which returns a string when verbose is false and the BlockResult JSON object when it is true. This commit corrects that by first removing the Hex field from the BlockResult and second allowing the result for getblock to be either form.
This commit is contained in:
parent
4cb318ac02
commit
e0e4c8bdb6
1 changed files with 18 additions and 6 deletions
16
jsonapi.go
16
jsonapi.go
|
@ -45,9 +45,10 @@ type InfoResult struct {
|
||||||
Errors string `json:"errors,omitempty"`
|
Errors string `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockResult models the data from the getblock command.
|
// BlockResult models the data from the getblock command when the verbose flag
|
||||||
|
// is set. When the verbose flag is not set, getblock return a hex-encoded
|
||||||
|
// string.
|
||||||
type BlockResult struct {
|
type BlockResult struct {
|
||||||
Hex string `json:"hex,omitempty"`
|
|
||||||
Hash string `json:"hash"`
|
Hash string `json:"hash"`
|
||||||
Confirmations uint64 `json:"confirmations"`
|
Confirmations uint64 `json:"confirmations"`
|
||||||
Size int `json:"size"`
|
Size int `json:"size"`
|
||||||
|
@ -776,11 +777,22 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
|
||||||
result.Result = res
|
result.Result = res
|
||||||
}
|
}
|
||||||
case "getblock":
|
case "getblock":
|
||||||
|
// getblock can either return a JSON object or a hex-encoded
|
||||||
|
// string depending on the verbose flag. Choose the right form
|
||||||
|
// accordingly.
|
||||||
|
if strings.Contains(string(objmap["result"]), "{") {
|
||||||
var res BlockResult
|
var res BlockResult
|
||||||
err = json.Unmarshal(objmap["result"], &res)
|
err = json.Unmarshal(objmap["result"], &res)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result.Result = res
|
result.Result = res
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
var res string
|
||||||
|
err = json.Unmarshal(objmap["result"], &res)
|
||||||
|
if err == nil {
|
||||||
|
result.Result = res
|
||||||
|
}
|
||||||
|
}
|
||||||
case "getrawtransaction":
|
case "getrawtransaction":
|
||||||
var res TxRawResult
|
var res TxRawResult
|
||||||
err = json.Unmarshal(objmap["result"], &res)
|
err = json.Unmarshal(objmap["result"], &res)
|
||||||
|
|
Loading…
Reference in a new issue