Browse Source

Decode the generator response and store the variables in the stratifier

master
Con Kolivas 11 years ago
parent
commit
b65c555d87
  1. 2
      src/bitcoin.h
  2. 1
      src/libckpool.c
  3. 83
      src/stratifier.c

2
src/bitcoin.h

@ -21,8 +21,8 @@ struct gbtbase {
char nbit[12]; char nbit[12];
int coinbasevalue; int coinbasevalue;
int height; int height;
char *txn_data;
int transactions; int transactions;
char *txn_data;
int merkles; int merkles;
char merklehash[16][68]; char merklehash[16][68];
json_t *json; json_t *json;

1
src/libckpool.c

@ -828,6 +828,7 @@ out:
return val; return val;
} }
/* Align a size_t to 4 byte boundaries for fussy arches */ /* Align a size_t to 4 byte boundaries for fussy arches */
void align_len(size_t *len) void align_len(size_t *len)
{ {

83
src/stratifier.c

@ -17,13 +17,94 @@
#include "libckpool.h" #include "libckpool.h"
#include "bitcoin.h" #include "bitcoin.h"
struct workbase {
/* GBT/shared variables */
char target[68];
double diff;
uint32_t version;
uint32_t curtime;
char prevhash[68];
char ntime[12];
char bbversion[12];
char nbit[12];
int coinbasevalue;
int height;
int transactions;
char *txn_data;
int merkles;
char merklehash[16][68];
/* Work variables */
};
typedef struct workbase workbase_t;
/* No error checking with these, make sure we know they're valid already! */
static inline void json_strcpy(char *buf, json_t *val, const char *key)
{
strcpy(buf, json_string_value(json_object_get(val, key)));
}
static inline void json_dblcpy(double *dbl, json_t *val, const char *key)
{
*dbl = json_real_value(json_object_get(val, key));
}
static inline void json_uintcpy(uint32_t *u32, json_t *val, const char *key)
{
*u32 = (uint32_t)json_integer_value(json_object_get(val, key));
}
static inline void json_intcpy(int *i, json_t *val, const char *key)
{
*i = json_integer_value(json_object_get(val, key));
}
static inline void json_strdup(char **buf, json_t *val, const char *key)
{
*buf = strdup(json_string_value(json_object_get(val, key)));
}
/* This function assumes it will only receive a valid json gbt base template
* since checking should have been done earlier, and creates the base template
* for generating work templates. */
static void update_base(ckpool_t *ckp) static void update_base(ckpool_t *ckp)
{ {
workbase_t wb;
json_t *val;
char *buf; char *buf;
memset(&wb, 0, sizeof(wb));
buf = send_recv_proc(&ckp->generator, "getbase"); buf = send_recv_proc(&ckp->generator, "getbase");
/* Do something with this buffer here */ if (unlikely(!buf)) {
LOGWARNING("Failed to get base from generator in update_base");
return;
}
val = json_loads(buf, 0, NULL);
dealloc(buf); dealloc(buf);
json_strcpy(wb.target, val, "target");
json_dblcpy(&wb.diff, val, "diff");
json_uintcpy(&wb.version, val, "version");
json_uintcpy(&wb.curtime, val, "curtime");
json_strcpy(wb.prevhash, val, "prevhash");
json_strcpy(wb.ntime, val, "ntime");
json_strcpy(wb.bbversion, val, "bbversion");
json_intcpy(&wb.coinbasevalue, val, "coinbasevalue");
json_intcpy(&wb.height, val, "height");
json_intcpy(&wb.transactions, val, "transactions");
if (wb.transactions)
json_strdup(&wb.txn_data, val, "txn_data");
json_intcpy(&wb.merkles, val, "merkles");
if (wb.merkles) {
json_t *arr;
int i;
arr = json_object_get(val, "merklehash");
for (i = 0; i < wb.merkles; i++)
strcpy(&wb.merklehash[i][0], json_string_value(json_array_get(arr, i)));
}
json_decref(val);
} }
static int strat_loop(ckpool_t *ckp, proc_instance_t *pi) static int strat_loop(ckpool_t *ckp, proc_instance_t *pi)

Loading…
Cancel
Save