Browse Source

RPC URL, username and password become arguments,

rather than compile-time constants.
nfactor-troky
Jeff Garzik 14 years ago committed by Jeff Garzik
parent
commit
23cd22a5a5
  1. 39
      cpu-miner.c

39
cpu-miner.c

@ -39,14 +39,27 @@ static const bool opt_time = true;
static int opt_n_threads = 1; static int opt_n_threads = 1;
static pthread_mutex_t stats_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t stats_mutex = PTHREAD_MUTEX_INITIALIZER;
static uint64_t hash_ctr; static uint64_t hash_ctr;
static char *rpc_url = "http://127.0.0.1:8332/";
static char *userpass = "rpcuser:rpcpass";
static struct argp_option options[] = { static struct argp_option options[] = {
{ "threads", 't', "N", 0,
"Number of miner threads (default: 1)" },
{ "debug", 'D', NULL, 0, { "debug", 'D', NULL, 0,
"Enable debug output" }, "Enable debug output" },
{ "protocol-dump", 'P', NULL, 0, { "protocol-dump", 'P', NULL, 0,
"Verbose dump of protocol-level activities" }, "Verbose dump of protocol-level activities" },
{ "threads", 't', "N", 0,
"Number of miner threads (default: 1)" },
{ "url", 1001, "URL", 0,
"URL for bitcoin JSON-RPC server "
"(default: http://127.0.0.1:8332/)" },
{ "userpass", 1002, "USER:PASS", 0,
"Username:Password pair for bitcoin JSON-RPC server "
"(default: rpcuser:rpcpass)" },
{ } { }
}; };
@ -381,9 +394,6 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
} }
} }
static const char *url = "http://127.0.0.1:8332/";
static const char *userpass = "pretzel:smooth";
static void submit_work(struct work *work) static void submit_work(struct work *work)
{ {
char *hexstr = NULL, *s = NULL; char *hexstr = NULL, *s = NULL;
@ -408,7 +418,7 @@ static void submit_work(struct work *work)
fprintf(stderr, "DBG: sending RPC call:\n%s", s); fprintf(stderr, "DBG: sending RPC call:\n%s", s);
/* issue JSON-RPC request */ /* issue JSON-RPC request */
val = json_rpc_call(url, userpass, s); val = json_rpc_call(rpc_url, userpass, s);
if (!val) { if (!val) {
fprintf(stderr, "submit_work json_rpc_call failed\n"); fprintf(stderr, "submit_work json_rpc_call failed\n");
goto out; goto out;
@ -437,7 +447,7 @@ static void *miner_thread(void *dummy)
uint32_t nonce; uint32_t nonce;
/* obtain new work from bitcoin */ /* obtain new work from bitcoin */
val = json_rpc_call(url, userpass, rpc_req); val = json_rpc_call(rpc_url, userpass, rpc_req);
if (!val) { if (!val) {
fprintf(stderr, "json_rpc_call failed\n"); fprintf(stderr, "json_rpc_call failed\n");
return NULL; return NULL;
@ -479,11 +489,24 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
break; break;
case 't': case 't':
v = atoi(arg); v = atoi(arg);
if (v < 1 || v > 9999) /* sanity check */ if (v < 1 || v > 9999) /* sanity check */
argp_usage(state); argp_usage(state);
opt_n_threads = v; opt_n_threads = v;
break; break;
case 1001: /* --url */
if (strncmp(arg, "http://", 7) &&
strncmp(arg, "https://", 8))
argp_usage(state);
rpc_url = arg;
break;
case 1002: /* --userpass */
if (!strchr(arg, ':'))
argp_usage(state);
userpass = arg;
break;
case ARGP_KEY_ARG: case ARGP_KEY_ARG:
argp_usage(state); /* too many args */ argp_usage(state); /* too many args */
break; break;

Loading…
Cancel
Save