Parse and use coinbaseaux
This commit is contained in:
24
blkmaker.c
24
blkmaker.c
@@ -50,8 +50,7 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
|
||||
|
||||
*inout_newcb = true;
|
||||
|
||||
size_t datasz = 62 + sizeof(blkheight_t) + scriptsz;
|
||||
unsigned char *data = malloc(datasz);
|
||||
unsigned char *data = malloc(168 + scriptsz);
|
||||
size_t off = 0;
|
||||
if (!data)
|
||||
return 0;
|
||||
@@ -76,6 +75,27 @@ uint64_t blkmk_init_generation3(blktemplate_t * const tmpl, const void * const s
|
||||
data[off++] = h;
|
||||
data[42] = data[41] - 1;
|
||||
|
||||
if (tmpl->aux_count)
|
||||
{
|
||||
unsigned auxsz = off++;
|
||||
data[auxsz] = 0;
|
||||
++data[41];
|
||||
|
||||
for (unsigned i = 0; i < tmpl->aux_count; ++i)
|
||||
{
|
||||
struct blkaux_t * const aux = &tmpl->auxs[i];
|
||||
if ((size_t)data[41] + aux->datasz > 100)
|
||||
{
|
||||
free(data);
|
||||
return 0;
|
||||
}
|
||||
memcpy(&data[off], tmpl->auxs[i].data, aux->datasz);
|
||||
data[41] += aux->datasz;
|
||||
data[auxsz] += aux->datasz;
|
||||
off += aux->datasz;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&data[off],
|
||||
"\xff\xff\xff\xff" // sequence
|
||||
"\x01" // output count
|
||||
|
||||
@@ -226,7 +226,26 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
return s;
|
||||
}
|
||||
|
||||
// TODO: coinbaseaux
|
||||
if ((v = json_object_get(json, "coinbaseaux")) && json_is_object(v))
|
||||
{
|
||||
tmpl->aux_count = json_object_size(v);
|
||||
tmpl->auxs = malloc(tmpl->aux_count * sizeof(*tmpl->auxs));
|
||||
unsigned i = 0;
|
||||
for (void *iter = json_object_iter(v); iter; (iter = json_object_iter_next(v, iter)), ++i)
|
||||
{
|
||||
v2 = json_object_iter_value(iter);
|
||||
s = json_string_value(v2);
|
||||
if (!s)
|
||||
continue;
|
||||
size_t sz = strlen(s) / 2;
|
||||
tmpl->auxs[i] = (struct blkaux_t){
|
||||
.auxname = strdup(json_object_iter_key(iter)),
|
||||
.data = malloc(sz),
|
||||
.datasz = sz,
|
||||
};
|
||||
my_hex2bin(tmpl->auxs[i].data, s, sz);
|
||||
}
|
||||
}
|
||||
|
||||
if ((v = json_object_get(json, "mutable")) && json_is_array(v))
|
||||
{
|
||||
|
||||
@@ -101,6 +101,12 @@ void _blktxn_free(struct blktxn_t *bt) {
|
||||
}
|
||||
#define blktxn_free _blktxn_free
|
||||
|
||||
static
|
||||
void blkaux_clean(struct blkaux_t * const aux) {
|
||||
free(aux->auxname);
|
||||
free(aux->data);
|
||||
}
|
||||
|
||||
void blktmpl_free(blktemplate_t *tmpl) {
|
||||
for (unsigned long i = 0; i < tmpl->txncount; ++i)
|
||||
blktxn_free(&tmpl->txns[i]);
|
||||
@@ -114,6 +120,9 @@ void blktmpl_free(blktemplate_t *tmpl) {
|
||||
// TODO: maybe free auxnames[0..n]? auxdata too
|
||||
free(tmpl->auxnames);
|
||||
free(tmpl->auxdata);
|
||||
for (unsigned i = 0; i < tmpl->aux_count; ++i)
|
||||
blkaux_clean(&tmpl->auxs[i]);
|
||||
free(tmpl->auxs);
|
||||
free(tmpl->workid);
|
||||
free(tmpl->lp.id);
|
||||
free(tmpl->lp.uri);
|
||||
|
||||
@@ -40,6 +40,12 @@ struct blktxn_t {
|
||||
txnhash_t *hash_;
|
||||
};
|
||||
|
||||
struct blkaux_t {
|
||||
char *auxname;
|
||||
unsigned char *data;
|
||||
uint8_t datasz;
|
||||
};
|
||||
|
||||
// BIP 23: Long Polling
|
||||
struct blktmpl_longpoll_req {
|
||||
char *id;
|
||||
@@ -100,6 +106,8 @@ typedef struct {
|
||||
|
||||
time_t _time_rcvd;
|
||||
blktime_t curtime;
|
||||
|
||||
// NOTE: These were never populated nor used, see aux_count and auxs
|
||||
char auxcount;
|
||||
char **auxnames;
|
||||
unsigned char **auxdata;
|
||||
@@ -128,6 +136,9 @@ typedef struct {
|
||||
int _mrklbranchcount;
|
||||
libblkmaker_hash_t _mrklroot;
|
||||
unsigned int next_dataid;
|
||||
|
||||
unsigned aux_count;
|
||||
struct blkaux_t *auxs;
|
||||
} blktemplate_t;
|
||||
|
||||
extern blktemplate_t *blktmpl_create();
|
||||
|
||||
Reference in New Issue
Block a user