Allow getrawtransaction result to be string.

The getrawtransaction command has recently added a verbose flag which
alters the output.  The previous code made use of the "Hex" field of the
TxRawResult to return the information, but this is not consistent with the
original getrawtransaction RPC call which returns a string when verbose is
false and the TxRawResult JSON object when it is true.

This commit corrects that by allowing the result for getrawtransaction to
be either form.
This commit is contained in:
Dave Collins 2013-12-26 21:25:40 -06:00
parent e0e4c8bdb6
commit 1855c19562

View file

@ -794,10 +794,21 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) {
}
}
case "getrawtransaction":
var res TxRawResult
err = json.Unmarshal(objmap["result"], &res)
if err == nil {
result.Result = res
// getrawtransaction 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 TxRawResult
err = json.Unmarshal(objmap["result"], &res)
if err == nil {
result.Result = res
}
} else {
var res string
err = json.Unmarshal(objmap["result"], &res)
if err == nil {
result.Result = res
}
}
case "decoderawtransaction":
var res TxRawDecodeResult