Browse Source

Add support for job_id being in the params for get_transactions while maintaining backward support for job_id being embedded in the method. Convert get_txnhashes to using only params for the job_id.

master
Con Kolivas 10 years ago
parent
commit
c0aba3449f
  1. 28
      src/stratifier.c

28
src/stratifier.c

@ -173,6 +173,7 @@ static int64_t blockchange_id;
static char lasthash[68], lastswaphash[68];
struct json_params {
json_t *method;
json_t *params;
json_t *id_val;
int64_t client_id;
@ -2452,10 +2453,13 @@ static void update_client(stratum_instance_t *client, const int64_t client_id)
stratum_send_diff(client);
}
static json_params_t *create_json_params(const int64_t client_id, const json_t *params, const json_t *id_val, const char *address)
static json_params_t
*create_json_params(const int64_t client_id, json_t *method, const json_t *params,
const json_t *id_val, const char *address)
{
json_params_t *jp = ckalloc(sizeof(json_params_t));
jp->method = json_copy(method);
jp->params = json_deep_copy(params);
jp->id_val = json_deep_copy(id_val);
jp->client_id = client_id;
@ -2606,7 +2610,7 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method
}
if (cmdmatch(method, "mining.auth") && client->subscribed) {
json_params_t *jp = create_json_params(client_id, params_val, id_val, address);
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(sauthq, jp);
return;
@ -2624,7 +2628,7 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method
}
if (cmdmatch(method, "mining.submit")) {
json_params_t *jp = create_json_params(client_id, params_val, id_val, address);
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(sshareq, jp);
return;
@ -2637,7 +2641,7 @@ static void parse_method(const int64_t client_id, json_t *id_val, json_t *method
/* Covers both get_transactions and get_txnhashes */
if (cmdmatch(method, "mining.get")) {
json_params_t *jp = create_json_params(client_id, method_val, id_val, address);
json_params_t *jp = create_json_params(client_id, method_val, params_val, id_val, address);
ckmsgq_add(stxnq, jp);
return;
@ -2748,6 +2752,7 @@ static void ssend_process(ckpool_t *ckp, smsg_t *msg)
static void discard_json_params(json_params_t **jp)
{
json_decref((*jp)->method);
json_decref((*jp)->params);
json_decref((*jp)->id_val);
free(*jp);
@ -2936,7 +2941,8 @@ static json_t *txnhashes_by_jobid(int64_t id)
static void send_transactions(ckpool_t *ckp, json_params_t *jp)
{
const char *msg = json_string_value(jp->params);
const char *msg = json_string_value(jp->method),
*params = json_string_value(json_array_get(jp->params, 0));
stratum_instance_t *client;
json_t *val, *hashes;
int64_t job_id = 0;
@ -2953,7 +2959,11 @@ static void send_transactions(ckpool_t *ckp, json_params_t *jp)
/* We don't actually send the transactions as that would use
* up huge bandwidth, so we just return the number of
* transactions :) */
* transactions :) . Support both forms of encoding the
* request in method name and as a parameter. */
if (params && strlen(params) > 0)
sscanf(params, "%lx", &job_id);
else
sscanf(msg, "mining.get_transactions(%lx", &job_id);
txns = transactions_by_jobid(job_id);
if (txns != -1) {
@ -2986,7 +2996,11 @@ static void send_transactions(ckpool_t *ckp, json_params_t *jp)
goto out_send;
}
client->last_txns = now_t;
sscanf(msg, "mining.get_txnhashes(%lx", &job_id);
if (!params || !strlen(params)) {
json_set_string(val, "error", "Invalid params");
goto out_send;
}
sscanf(params, "%lx", &job_id);
hashes = txnhashes_by_jobid(job_id);
if (hashes) {
json_object_set_new_nocheck(val, "result", hashes);

Loading…
Cancel
Save