The number of transactions is variable so make merkle a variable length dynamically allocated array and track how many there are for stratum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
diff --git a/miner.h b/miner.h
index 79cf550..9efbedc 100644
--- a/miner.h
+++ b/miner.h
@@ -759,13 +759,13 @@ struct stratum_work {
char *prev_hash;
char *coinbase1;
char *coinbase2;
- char *merkle1;
- char *merkle2;
+ char **merkle;
char *bbversion;
char *nbit;
char *ntime;
bool clean;
+ int merkles;
int diff;
};
diff --git a/util.c b/util.c
index de2ff19..75f8e6b 100644
--- a/util.c
+++ b/util.c
@@ -958,8 +958,8 @@ static char *json_array_string(json_t *val, unsigned int entry)
static bool parse_notify(struct pool *pool, json_t *val)
{
- char *job_id, *prev_hash, *coinbase1, *coinbase2, *merkle1, *merkle2,
- *bbversion, *nbit, *ntime;
+ char *job_id, *prev_hash, *coinbase1, *coinbase2, *bbversion, *nbit, *ntime;
+ int merkles, i;
json_t *arr;
bool clean;
@@ -967,19 +967,18 @@ static bool parse_notify(struct pool *pool, json_t *val)
if (!arr || !json_is_array(arr))
return false;
+ merkles = json_array_size(arr);
+
job_id = json_array_string(val, 0);
prev_hash = json_array_string(val, 1);
coinbase1 = json_array_string(val, 2);
coinbase2 = json_array_string(val, 3);
- merkle1 = json_array_string(arr, 0);
- merkle2 = json_array_string(arr, 1);
bbversion = json_array_string(val, 5);
nbit = json_array_string(val, 6);
ntime = json_array_string(val, 7);
clean = json_is_true(json_array_get(val, 8));
- if (!job_id || !prev_hash || !coinbase1 || !coinbase2 || !merkle1 ||
- !merkle2 || !bbversion || !nbit || !ntime) {
+ if (!job_id || !prev_hash || !coinbase1 || !coinbase2 || !bbversion || !nbit || !ntime) {
/* Annoying but we must not leak memory */
if (job_id)
free(job_id);
@@ -989,10 +988,6 @@ static bool parse_notify(struct pool *pool, json_t *val)
free(coinbase1);
if (coinbase2)
free(coinbase2);
- if (merkle1)
- free(merkle1);
- if (merkle2)
- free(merkle2);
if (bbversion)
free(bbversion);
if (nbit)
@@ -1007,12 +1002,18 @@ static bool parse_notify(struct pool *pool, json_t *val)
pool->swork.prev_hash = prev_hash;
pool->swork.coinbase1 = coinbase1;
pool->swork.coinbase2 = coinbase2;
- pool->swork.merkle1 = merkle1;
- pool->swork.merkle2 = merkle2;
pool->swork.bbversion = bbversion;
pool->swork.nbit = nbit;
pool->swork.ntime = ntime;
pool->swork.clean = clean;
+ for (i = 0; i < pool->swork.merkles; i++)
+ free(pool->swork.merkle[i]);
+ if (merkles) {
+ pool->swork.merkle = realloc(pool->swork.merkle, sizeof(char *) * merkles + 1);
+ for (i = 0; i < merkles; i++)
+ pool->swork.merkle[i] = json_array_string(arr, i);
+ }
+ pool->swork.merkles = merkles;
mutex_unlock(&pool->pool_lock);
if (opt_protocol) {
@@ -1020,8 +1021,8 @@ static bool parse_notify(struct pool *pool, json_t *val)
applog(LOG_DEBUG, "prev_hash: %s", prev_hash);
applog(LOG_DEBUG, "coinbase1: %s", coinbase1);
applog(LOG_DEBUG, "coinbase2: %s", coinbase2);
- applog(LOG_DEBUG, "merkle1: %s", merkle1);
- applog(LOG_DEBUG, "merkle2: %s", merkle2);
+ for (i = 0; i < merkles; i++)
+ applog(LOG_DEBUG, "merkle%d: %s", i, pool->swork.merkle[i]);
applog(LOG_DEBUG, "bbversion: %s", bbversion);
applog(LOG_DEBUG, "nbit: %s", nbit);
applog(LOG_DEBUG, "ntime: %s", ntime);