Browse Source

Create a json string based on parameters we'll be sending to the database on every work update to be submitted once it's hooked in

master
Con Kolivas 11 years ago
parent
commit
1007e20035
  1. 9
      src/bitcoin.c
  2. 1
      src/bitcoin.h
  3. 39
      src/stratifier.c

9
src/bitcoin.c

@ -88,6 +88,7 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
uchar *hashbin;
dealloc(gbt->txn_data);
dealloc(gbt->txn_hashes);
gbt->transactions = 0;
gbt->merkles = 0;
gbt->transactions = json_array_size(transaction_arr);
@ -110,6 +111,8 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
}
gbt->txn_data = ckzalloc(len + 1);
gbt->txn_hashes = ckzalloc(gbt->transactions * 65 + 1);
memset(gbt->txn_hashes, 0x20, gbt->transactions * 65); // Spaces
for (i = 0; i < gbt->transactions; i++) {
char binswap[32];
@ -140,6 +143,7 @@ static bool gbt_merkle_bins(gbtbase_t *gbt, json_t *transaction_arr)
LOGERR("Failed to hex2bin hash in gbt_merkle_bins");
return false;
}
memcpy(gbt->txn_hashes + i * 65, hash, 64);
bswap_256(hashbin + 32 + 32 * i, binswap);
}
}
@ -256,8 +260,10 @@ bool gen_gbtbase(connsock_t *cs, gbtbase_t *gbt)
gbt_merkle_bins(gbt, transaction_arr);
json_object_set_new_nocheck(gbt->json, "transactions", json_integer(gbt->transactions));
if (gbt->transactions)
if (gbt->transactions) {
json_object_set_new_nocheck(gbt->json, "txn_data", json_string_nocheck(gbt->txn_data));
json_object_set_new_nocheck(gbt->json, "txn_hashes", json_string_nocheck(gbt->txn_hashes));
}
json_object_set_new_nocheck(gbt->json, "merkles", json_integer(gbt->merkles));
if (gbt->merkles) {
array = json_array();
@ -276,6 +282,7 @@ void clear_gbtbase(gbtbase_t *gbt)
{
dealloc(gbt->flags);
dealloc(gbt->txn_data);
dealloc(gbt->txn_hashes);
json_decref(gbt->json);
gbt->json = NULL;
memset(gbt, 0, sizeof(gbtbase_t));

1
src/bitcoin.h

@ -24,6 +24,7 @@ struct gbtbase {
char *flags;
int transactions;
char *txn_data;
char *txn_hashes;
int merkles;
char merklehash[16][68];
json_t *json;

39
src/stratifier.c

@ -105,6 +105,7 @@ struct workbase {
char *flags;
int transactions;
char *txn_data;
char *txn_hashes;
int merkles;
char merklehash[16][68];
char merklebin[16][32];
@ -361,6 +362,7 @@ static void clear_workbase(workbase_t *wb)
{
free(wb->flags);
free(wb->txn_data);
free(wb->txn_hashes);
free(wb->logdir);
free(wb->coinb2bin);
free(wb->coinb2);
@ -387,6 +389,37 @@ static void purge_share_hashtable(uint64_t wb_id)
LOGINFO("Cleared %d shares from share hashtable", purged);
}
/* This message will be sent to the database once it's hooked in */
static void send_workinfo(ckpool_t *ckp, workbase_t *wb)
{
uint64_t createdate;
char *coinb1a, *s;
json_t *val;
createdate = wb->gentime.tv_sec;
createdate *= 1000000000ull;
createdate += wb->gentime.tv_nsec;
coinb1a = bin2hex(wb->coinb1a, wb->coinb1alen);
ASPRINTF(&s, "%016lx", createdate);
val = json_pack("{ss,si,ss,ss,ss,ss,ss,ss,ss,ss,ss,ss}",
"method", "workinfo",
"workinfoid", wb->id,
"poolinstance", ckp->name,
"transactiontree", wb->txn_hashes,
"prevhash", wb->prevhash,
"coinbase1a", coinb1a,
"version", wb->bbversion,
"bits", wb->nbit,
"createdate", s,
"createby", "code",
"createcode", __func__,
"createinet", "127.0.0.1");
free(coinb1a);
free(s);
json_decref(val);
}
static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
{
workbase_t *tmp, *tmpa;
@ -434,6 +467,8 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
if (*new_block)
purge_share_hashtable(wb->id);
send_workinfo(ckp, wb);
}
/* This function assumes it will only receive a valid json gbt base template
@ -474,8 +509,10 @@ static void update_base(ckpool_t *ckp)
json_intcpy(&wb->height, val, "height");
json_strdup(&wb->flags, val, "flags");
json_intcpy(&wb->transactions, val, "transactions");
if (wb->transactions)
if (wb->transactions) {
json_strdup(&wb->txn_data, val, "txn_data");
json_strdup(&wb->txn_hashes, val, "txn_hashes");
}
json_intcpy(&wb->merkles, val, "merkles");
wb->merkle_array = json_array();
if (wb->merkles) {

Loading…
Cancel
Save