Skip to content

Commit

Permalink
feat: add --coinbase-address option to allow user to choose an addres…
Browse files Browse the repository at this point in the history
…s for mined funds to be deposited
  • Loading branch information
athoscouto committed Apr 11, 2019
1 parent ed0c011 commit d97847c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
8 changes: 8 additions & 0 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ int32_t device_led[MAX_GPUS] = { -1, -1 };
int opt_led_mode = 0;
int opt_cudaschedule = -1;
static bool opt_keep_clocks = false;
char *coinbase_address;

// un-linked to cmdline scrypt options (useless)
int device_batchsize[MAX_GPUS] = { 0 };
Expand Down Expand Up @@ -385,6 +386,7 @@ Options:\n\
-c, --config=FILE load a JSON-format configuration file\n\
-V, --version display version information and exit\n\
-h, --help display this help text and exit\n\
--coinbase-addres=.. choose address for mined funds to be credited to\n\
";

static char const short_options[] =
Expand Down Expand Up @@ -479,6 +481,7 @@ struct option options[] = {
{ "diff-multiplier", 1, NULL, 'm' },
{ "diff-factor", 1, NULL, 'f' },
{ "diff", 1, NULL, 'f' }, // compat
{ "coinbase-addr", 1, NULL, 1038 },
{ 0, 0, 0, 0 }
};

Expand Down Expand Up @@ -2832,6 +2835,8 @@ static void *stratum_thread(void *userdata)
pthread_mutex_unlock(&g_work_lock);
restart_threads();

stratum.addr = coinbase_address;

if (!stratum_connect(&stratum, pool->url) ||
!stratum_subscribe(&stratum))
{
Expand Down Expand Up @@ -3072,6 +3077,9 @@ void parse_arg(int key, char *arg)
show_usage_and_exit(1);
opt_api_mcast_port = v;
break;
case 1038: /* --coinbase-addr */
coinbase_address = strdup(arg);
break;
case 'B':
opt_background = true;
break;
Expand Down
2 changes: 2 additions & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ struct stratum_ctx {
int rpc2;
int is_equihash;
int srvtime_diff;

char *addr;
};

#define POK_MAX_TXS 4
Expand Down
17 changes: 14 additions & 3 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ static bool stratum_parse_extranonce(struct stratum_ctx *sctx, json_t *params, i

bool stratum_subscribe(struct stratum_ctx *sctx)
{
char *s, *sret = NULL;
char *s, *sret = NULL, *addr;
const char *sid;
json_t *val = NULL, *res_val, *err_val;
json_error_t err;
Expand All @@ -1231,8 +1231,17 @@ bool stratum_subscribe(struct stratum_ctx *sctx)
if (sctx->rpc2) return true;

start:
s = (char*)malloc(128);
sprintf(s, "{\"jsonrpc\": \"2.0\", \"id\": \"61e39f788ae04442b97d52c6b814ebab\", \"method\": \"subscribe\", \"params\": null}");
s = (char*)malloc(256);
addr = (char*)malloc(64);
sprintf(addr, "{\"address\": \"%s\"}", sctx->addr);
sprintf(s, "\
{\
\"jsonrpc\": \"2.0\", \
\"id\": \"61e39f788ae04442b97d52c6b814ebab\", \
\"method\": \"subscribe\", \
\"params\": %s\
}",
sctx->addr == NULL ? "null" : addr);

if (!stratum_send_line(sctx, s))
goto out;
Expand Down Expand Up @@ -1264,6 +1273,7 @@ bool stratum_subscribe(struct stratum_ctx *sctx)
(err_val && !json_is_null(err_val))) {
if (opt_debug || retry) {
free(s);
free(addr);
if (err_val)
s = json_dumps(err_val, JSON_INDENT(3));
else
Expand All @@ -1289,6 +1299,7 @@ bool stratum_subscribe(struct stratum_ctx *sctx)

out:
free(s);
free(addr);
if (val)
json_decref(val);

Expand Down

0 comments on commit d97847c

Please sign in to comment.