aboutsummaryrefslogtreecommitdiff
path: root/cpu-miner.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2010-11-25 04:04:30 -0500
committerJeff Garzik <jgarzik@redhat.com>2010-11-25 04:04:30 -0500
commit5d1a45294b4dcc1ca7e1e2c1243ee4904f0f53fe (patch)
tree06527d69d656d19dfd7332350bab05adf3b6762f /cpu-miner.c
parent945be82ea15854bd6ecb24e04f6157b9c2c2b040 (diff)
code movement: move submit_work() above hot path
Diffstat (limited to 'cpu-miner.c')
-rw-r--r--cpu-miner.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/cpu-miner.c b/cpu-miner.c
index 2c8149e..2b404af 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -134,6 +134,48 @@ err_out:
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)
{
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 const char *rpc_req =