From 56b16953a94d7e672c84cf1144747948557350c5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 1 Nov 2012 15:40:07 +1100 Subject: [PATCH] Decode work in separate functions for getwork vs gbt. --- cgminer.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/cgminer.c b/cgminer.c index ee944246..b1dc39f0 100644 --- a/cgminer.c +++ b/cgminer.c @@ -1357,19 +1357,11 @@ static void calc_midstate(struct work *work) #endif } -static bool work_decode(struct pool *pool, struct work *work, json_t *val) +static bool getwork_decode(json_t *res_val, struct work *work) { - json_t *res_val = json_object_get(val, "result"); - bool ret = false; - - if (pool->has_gbt) { - work->gbt = true; - goto out; - } - if (unlikely(!jobj_binary(res_val, "data", work->data, sizeof(work->data), true))) { applog(LOG_ERR, "JSON inval data"); - goto out; + return false; } if (!jobj_binary(res_val, "midstate", work->midstate, sizeof(work->midstate), false)) { @@ -1385,9 +1377,24 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val) if (unlikely(!jobj_binary(res_val, "target", work->target, sizeof(work->target), true))) { applog(LOG_ERR, "JSON inval target"); + return false; + } + return true; +} + +static bool work_decode(struct pool *pool, struct work *work, json_t *val) +{ + json_t *res_val = json_object_get(val, "result"); + bool ret = false; + + if (pool->has_gbt) { + work->gbt = true; goto out; } + if (unlikely(!getwork_decode(res_val, work))) + goto out; + memset(work->hash, 0, sizeof(work->hash)); gettimeofday(&work->tv_staged, NULL);