Skip to content

Commit

Permalink
Allow specifying goal options as eg, --pool-goal name:malgo=scrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-jr committed Nov 1, 2014
1 parent d046e9d commit 36391db
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
74 changes: 73 additions & 1 deletion miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,8 @@ char *set_b58addr(const char * const arg, bytes_t * const b)
return NULL;
}

static char *set_generate_addr2(struct mining_goal_info *, const char *);

static
char *set_generate_addr(char *arg)
{
Expand All @@ -1307,6 +1309,12 @@ char *set_generate_addr(char *arg)
else
goal = get_mining_goal("default");

return set_generate_addr2(goal, arg);
}

static
char *set_generate_addr2(struct mining_goal_info * const goal, const char * const arg)
{
bytes_t newscript = BYTES_INIT;
char *estr = set_b58addr(arg, &newscript);
if (estr)
Expand All @@ -1321,6 +1329,7 @@ char *set_generate_addr(char *arg)
}
bytes_assimilate(goal->generation_script, &newscript);
bytes_free(&newscript);

return NULL;
}
#endif
Expand Down Expand Up @@ -1789,16 +1798,79 @@ static char *set_cbcperc(const char *arg)
}

static
char *set_pool_goal(const char * const arg)
const char *goal_set(struct mining_goal_info * const goal, const char * const optname, const char * const newvalue, bytes_t * const replybuf, enum bfg_set_device_replytype * const out_success)
{
*out_success = SDR_ERR;
if (!(strcasecmp(optname, "malgo") && strcasecmp(optname, "algo")))
{
if (!newvalue)
return "Goal option 'malgo' requires a value (eg, SHA256d)";
if (!(strcasecmp(newvalue, "SHA256d") && strcasecmp(newvalue, "SHA256") && strcasecmp(newvalue, "SHA2")))
goal->malgo = &malgo_sha256d;
#ifdef USE_SCRYPT
else
if (!strcasecmp(newvalue, "scrypt"))
goal->malgo = &malgo_scrypt;
#endif
else
return "Unrecognised mining algorithm";
goto success;
}
#if BLKMAKER_VERSION > 1
if (match_strtok("generate-to|generate-to-addr|generate-to-address|genaddress|genaddr|gen-address|gen-addr|generate-address|generate-addr|coinbase-addr|coinbase-address|coinbase-payout|cbaddress|cbaddr|cb-address|cb-addr|payout", "|", optname))
{
if (!newvalue)
return "Missing value for 'generate-to' goal option";
const char * const emsg = set_generate_addr2(goal, newvalue);
if (emsg)
return emsg;
goto success;
}
#endif
*out_success = SDR_UNKNOWN;
return "Unknown goal option";

success:
*out_success = SDR_OK;
return NULL;
}

// May leak replybuf if returning an error
static
const char *set_goal_params(struct mining_goal_info * const goal, char *arg)
{
bytes_t replybuf = BYTES_INIT;
for (char *param, *nextptr; (param = strtok_r(arg, ",", &nextptr)); arg = NULL)
{
char *val = strchr(param, '=');
if (val)
val++[0] = '\0';
enum bfg_set_device_replytype success;
const char * const emsg = goal_set(goal, param, val, &replybuf, &success);
if (success != SDR_OK)
return emsg ?: "Error setting goal param";
}
bytes_free(&replybuf);
return NULL;
}

static
const char *set_pool_goal(const char * const arg)
{
struct pool *pool;

if (!total_pools)
return "Usage of --pool-goal before pools are defined does not make sense";

pool = pools[total_pools - 1];
char *param = strchr(arg, ':');
if (param)
param++[0] = '\0';
pool->goal = get_mining_goal(arg);

if (param)
return set_goal_params(pool->goal, param);

return NULL;
}

Expand Down
11 changes: 11 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,17 @@ bool isCalpha(const int c)
return false;
}

bool match_strtok(const char * const optlist, const char * const delim, const char * const needle)
{
const size_t optlist_sz = strlen(optlist) + 1;
char opts[optlist_sz];
memcpy(opts, optlist, optlist_sz);
for (char *el, *nextptr, *s = opts; (el = strtok_r(s, delim, &nextptr)); s = NULL)
if (!strcasecmp(el, needle))
return true;
return false;
}

static
bool _appdata_file_call(const char * const appname, const char * const filename, const appdata_file_callback_t cb, void * const userp, const char * const path)
{
Expand Down
2 changes: 2 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ bool isCspace(int c)
}
}

extern bool match_strtok(const char *optlist, const char *delim, const char *needle);

typedef bool (*appdata_file_callback_t)(const char *, void *);
extern bool appdata_file_call(const char *appname, const char *filename, appdata_file_callback_t, void *userp);
extern char *appdata_file_find_first(const char *appname, const char *filename);
Expand Down

0 comments on commit 36391db

Please sign in to comment.