From 5135fd32034c9cdcd32ce49248316b5778046976 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 11 Feb 2014 17:44:48 -0600 Subject: [PATCH] Allow getwork result to be a bool or JSON object. The getwork command alters the output depending on whether or not the optional data parameter was specified. It is a JSON object when no data was provided, and a boolean indicating whether a solution was found when data was provided. --- jsonapi.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/jsonapi.go b/jsonapi.go index 246cdcac..d81a2e62 100644 --- a/jsonapi.go +++ b/jsonapi.go @@ -933,10 +933,21 @@ func ReadResultCmd(cmd string, message []byte) (Reply, error) { result.Result = res } case "getwork": - var res GetWorkResult - err = json.Unmarshal(objmap["result"], &res) - if err == nil { - result.Result = res + // getwork can either return a JSON object or a boolean + // depending on whether or not data was provided. Choose the + // right form accordingly. + if strings.Contains(string(objmap["result"]), "{") { + var res GetWorkResult + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } + } else { + var res bool + err = json.Unmarshal(objmap["result"], &res) + if err == nil { + result.Result = res + } } case "validateaddress": var res ValidateAddressResult