Convert work decode function to prepare for decoding block templates.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/cgminer.c b/cgminer.c
index 2055db6..946b654 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1358,37 +1358,46 @@ static void calc_midstate(struct work *work)
#endif
}
-static bool work_decode(const json_t *val, struct work *work)
+static bool work_decode(struct pool *pool, struct work *work, json_t *val)
{
- if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data), true))) {
+ bool ret = false;
+ json_t *res_val;
+
+ if (pool->has_gbt) {
+ work->gbt = true;
+ goto out;
+ }
+
+ res_val = json_object_get(val, "result");
+ if (unlikely(!jobj_binary(res_val, "data", work->data, sizeof(work->data), true))) {
applog(LOG_ERR, "JSON inval data");
- goto err_out;
+ goto out;
}
- if (!jobj_binary(val, "midstate", work->midstate, sizeof(work->midstate), false)) {
+ if (!jobj_binary(res_val, "midstate", work->midstate, sizeof(work->midstate), false)) {
// Calculate it ourselves
applog(LOG_DEBUG, "Calculating midstate locally");
calc_midstate(work);
}
- if (!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1), false)) {
+ if (!jobj_binary(res_val, "hash1", work->hash1, sizeof(work->hash1), false)) {
// Always the same anyway
memcpy(work->hash1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0", 64);
}
- if (unlikely(!jobj_binary(val, "target", work->target, sizeof(work->target), true))) {
+ if (unlikely(!jobj_binary(res_val, "target", work->target, sizeof(work->target), true))) {
applog(LOG_ERR, "JSON inval target");
- goto err_out;
+ goto out;
}
memset(work->hash, 0, sizeof(work->hash));
gettimeofday(&work->tv_staged, NULL);
- return true;
+ ret = true;
-err_out:
- return false;
+out:
+ return ret;
}
int dev_from_id(int thr_id)
@@ -2303,7 +2312,7 @@ static bool get_upstream_work(struct work *work, CURL *curl)
pool_stats->getwork_attempts++;
if (likely(val)) {
- rc = work_decode(json_object_get(val, "result"), work);
+ rc = work_decode(pool, work, val);
if (unlikely(!rc))
applog(LOG_DEBUG, "Failed to decode work in get_upstream_work");
} else
@@ -4477,7 +4486,7 @@ retry_stratum:
struct work *work = make_work();
bool rc;
- rc = work_decode(json_object_get(val, "result"), work);
+ rc = work_decode(pool, work, val);
if (rc) {
applog(LOG_DEBUG, "Successfully retrieved and deciphered work from pool %u %s",
pool->pool_no, pool->rpc_url);
@@ -5254,7 +5263,7 @@ static void convert_to_work(json_t *val, int rolltime, struct pool *pool, struct
work = make_work();
- rc = work_decode(json_object_get(val, "result"), work);
+ rc = work_decode(pool, work, val);
if (unlikely(!rc)) {
applog(LOG_ERR, "Could not convert longpoll data to work");
free_work(work);
diff --git a/miner.h b/miner.h
index 70cbfdf..e608c13 100644
--- a/miner.h
+++ b/miner.h
@@ -930,6 +930,8 @@ struct work {
char ntime[16];
int sdiff;
+ bool gbt;
+
unsigned int work_block;
int id;
UT_hash_handle hh;