From aaaf38722210048e7a5e80d97872661d48de13c9 Mon Sep 17 00:00:00 2001 From: elbandi Date: Thu, 24 Apr 2014 13:05:02 +0200 Subject: [PATCH] handle mining.set_extranonce method --- util.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/util.c b/util.c index 97ad9a79..36866e5c 100644 --- a/util.c +++ b/util.c @@ -1664,6 +1664,48 @@ static bool parse_diff(struct pool *pool, json_t *val) return true; } +static bool parse_extranonce(struct pool *pool, json_t *val) +{ + char s[RBUFSIZE], *nonce1; + int n2size; + int id = json_integer_value(json_object_get(val, "id")); + json_t *params = json_object_get(val, "params"); + + if (!id) + return false; + + nonce1 = json_array_string(params, 0); + if (!nonce1) { +// applog(LOG_INFO, "Failed to get nonce1 in "); + return false; + } + n2size = json_integer_value(json_array_get(params, 1)); + if (!n2size) { +// applog(LOG_INFO, "Failed to get n2size in "); + free(nonce1); + return false; + } + + cg_wlock(&pool->data_lock); + pool->nonce1 = nonce1; + pool->n1_len = strlen(nonce1) / 2; + free(pool->nonce1bin); + pool->nonce1bin = (unsigned char *)calloc(pool->n1_len, 1); + if (unlikely(!pool->nonce1bin)) + quithere(1, "Failed to calloc pool->nonce1bin"); + hex2bin(pool->nonce1bin, pool->nonce1, pool->n1_len); + pool->n2size = n2size; + cg_wunlock(&pool->data_lock); + + sprintf(s, "{\"id\": %d, \"result\": \"true\", \"error\": null}", id); + if (!stratum_send(pool, s, strlen(s))) + return false; + + applog(LOG_NOTICE, "%s coin change requested", get_pool_name(pool)); + + return true; +} + static void __suspend_stratum(struct pool *pool) { clear_sockbuf(pool); @@ -1807,6 +1849,12 @@ bool parse_method(struct pool *pool, char *s) return ret; } + if (!strncasecmp(buf, "mining.set_extranonce", 21) && parse_extranonce(pool, val)) { + ret = true; + json_decref(val); + return ret; + } + if (!strncasecmp(buf, "client.reconnect", 16) && parse_reconnect(pool, params)) { ret = true; json_decref(val);