From 1855c19562490e95a92ac74e90fe899ef30cd2ad Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Thu, 26 Dec 2013 21:25:40 -0600 Subject: [PATCH] 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. --- jsonapi.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/jsonapi.go b/jsonapi.go index d32c454d1..62a1da51e 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -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