Decode work in separate functions for getwork vs gbt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/cgminer.c b/cgminer.c
index ee94424..b1dc39f 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);