Browse Source

handle mining.set_extranonce method

idlebug
elbandi 11 years ago
parent
commit
aaaf387222
  1. 48
      util.c

48
util.c

@ -1664,6 +1664,48 @@ static bool parse_diff(struct pool *pool, json_t *val)
return true; 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) static void __suspend_stratum(struct pool *pool)
{ {
clear_sockbuf(pool); clear_sockbuf(pool);
@ -1807,6 +1849,12 @@ bool parse_method(struct pool *pool, char *s)
return ret; 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)) { if (!strncasecmp(buf, "client.reconnect", 16) && parse_reconnect(pool, params)) {
ret = true; ret = true;
json_decref(val); json_decref(val);

Loading…
Cancel
Save