Support arbitrary-size arguments to mining.submit

Fixes #87
This commit is contained in:
pooler 2015-02-14 19:35:35 +01:00
parent 2d92d6604b
commit 4611186cb8

View file

@ -661,19 +661,22 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
if (have_stratum) {
uint32_t ntime, nonce;
char ntimestr[9], noncestr[9], *xnonce2str;
char ntimestr[9], noncestr[9], *xnonce2str, *req;
le32enc(&ntime, work->data[17]);
le32enc(&nonce, work->data[19]);
bin2hex(ntimestr, (const unsigned char *)(&ntime), 4);
bin2hex(noncestr, (const unsigned char *)(&nonce), 4);
xnonce2str = abin2hex(work->xnonce2, work->xnonce2_len);
sprintf(s,
req = malloc(256 + strlen(rpc_user) + strlen(work->job_id) + 2 * work->xnonce2_len);
sprintf(req,
"{\"method\": \"mining.submit\", \"params\": [\"%s\", \"%s\", \"%s\", \"%s\", \"%s\"], \"id\":4}",
rpc_user, work->job_id, xnonce2str, ntimestr, noncestr);
free(xnonce2str);
if (unlikely(!stratum_send_line(&stratum, s))) {
rc = stratum_send_line(&stratum, req);
free(req);
if (unlikely(!rc)) {
applog(LOG_ERR, "submit_upstream_work stratum_send_line failed");
goto out;
}