1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-22 12:34:27 +00:00

code movement: move submit_work() above hot path

This commit is contained in:
Jeff Garzik 2010-11-25 04:04:30 -05:00 committed by Jeff Garzik
parent 945be82ea1
commit 5d1a45294b

View File

@ -134,6 +134,48 @@ err_out:
return false; return false;
} }
static void submit_work(struct work *work)
{
char *hexstr = NULL, *s = NULL;
json_t *val, *res;
printf("PROOF OF WORK FOUND? submitting...\n");
/* build hex string */
hexstr = bin2hex(work->data, sizeof(work->data));
if (!hexstr)
goto out;
/* build JSON-RPC request */
if (asprintf(&s,
"{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}\r\n",
hexstr) < 0) {
fprintf(stderr, "asprintf failed\n");
goto out;
}
if (opt_debug)
fprintf(stderr, "DBG: sending RPC call:\n%s", s);
/* issue JSON-RPC request */
val = json_rpc_call(rpc_url, userpass, s);
if (!val) {
fprintf(stderr, "submit_work json_rpc_call failed\n");
goto out;
}
res = json_object_get(val, "result");
printf("PROOF OF WORK RESULT: %s\n",
json_is_true(res) ? "true (yay!!!)" : "false (booooo)");
json_decref(val);
out:
free(s);
free(hexstr);
}
static void inc_stats(uint64_t n_hashes) static void inc_stats(uint64_t n_hashes)
{ {
pthread_mutex_lock(&stats_mutex); pthread_mutex_lock(&stats_mutex);
@ -198,48 +240,6 @@ static bool scanhash(unsigned char *midstate, unsigned char *data,
} }
} }
static void submit_work(struct work *work)
{
char *hexstr = NULL, *s = NULL;
json_t *val, *res;
printf("PROOF OF WORK FOUND? submitting...\n");
/* build hex string */
hexstr = bin2hex(work->data, sizeof(work->data));
if (!hexstr)
goto out;
/* build JSON-RPC request */
if (asprintf(&s,
"{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}\r\n",
hexstr) < 0) {
fprintf(stderr, "asprintf failed\n");
goto out;
}
if (opt_debug)
fprintf(stderr, "DBG: sending RPC call:\n%s", s);
/* issue JSON-RPC request */
val = json_rpc_call(rpc_url, userpass, s);
if (!val) {
fprintf(stderr, "submit_work json_rpc_call failed\n");
goto out;
}
res = json_object_get(val, "result");
printf("PROOF OF WORK RESULT: %s\n",
json_is_true(res) ? "true (yay!!!)" : "false (booooo)");
json_decref(val);
out:
free(s);
free(hexstr);
}
static void *miner_thread(void *dummy) static void *miner_thread(void *dummy)
{ {
static const char *rpc_req = static const char *rpc_req =