Merge branch 'proposals'
This commit is contained in:
@@ -10,12 +10,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
#include <blkmaker.h>
|
||||
@@ -272,66 +266,61 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
char varintEncode(unsigned char *out, uint64_t n) {
|
||||
if (n < 0xfd)
|
||||
json_t *blktmpl_propose_jansson(blktemplate_t * const tmpl, const gbt_capabilities_t caps, const bool foreign) {
|
||||
json_t *jreq = blktmpl_request_jansson(caps, NULL), *ja = NULL, *jparams;
|
||||
if (!(jreq && json_is_object(jreq)))
|
||||
goto err;
|
||||
|
||||
jparams = json_array_get(json_object_get(jreq, "params"), 0);
|
||||
if (!(jparams && json_is_object(jparams)))
|
||||
goto err;
|
||||
|
||||
if (!(ja = json_string("proposal")))
|
||||
goto err;
|
||||
if (json_object_set_new(jparams, "mode", ja))
|
||||
goto err;
|
||||
|
||||
if (tmpl->workid && !foreign)
|
||||
{
|
||||
out[0] = n;
|
||||
return 1;
|
||||
if (!(ja = json_string(tmpl->workid)))
|
||||
goto err;
|
||||
if (json_object_set_new(jparams, "workid", ja))
|
||||
goto err;
|
||||
}
|
||||
char L;
|
||||
if (n <= 0xffff)
|
||||
{
|
||||
out[0] = '\xfd';
|
||||
L = 3;
|
||||
}
|
||||
else
|
||||
if (n <= 0xffffffff)
|
||||
{
|
||||
out[0] = '\xfe';
|
||||
L = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
out[0] = '\xff';
|
||||
L = 9;
|
||||
}
|
||||
for (unsigned char i = 1; i < L; ++i)
|
||||
out[i] = (n >> ((i - 1) * 8)) % 256;
|
||||
return L;
|
||||
}
|
||||
ja = NULL;
|
||||
|
||||
unsigned int dataid = (tmpl->mutations & (BMM_CBAPPEND | BMM_CBSET) ? 1 : 0);
|
||||
|
||||
uint8_t sdata[0x4c];
|
||||
if (!blkmk_sample_data_(tmpl, sdata, dataid))
|
||||
goto err;
|
||||
char *blkhex = blkmk_assemble_submission_(tmpl, sdata, dataid, 0, foreign);
|
||||
if (!blkhex)
|
||||
goto err;
|
||||
if (!(ja = json_string(blkhex)))
|
||||
goto err;
|
||||
if (json_object_set_new(jparams, "data", ja))
|
||||
goto err;
|
||||
|
||||
return jreq;
|
||||
|
||||
#define my_bin2hex _blkmk_bin2hex
|
||||
err:
|
||||
if (jreq) json_decref(jreq);
|
||||
if (ja) json_decref(ja);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
json_t *_blkmk_submit_jansson(blktemplate_t *tmpl, const unsigned char *data, unsigned int dataid, blknonce_t nonce, bool foreign) {
|
||||
unsigned char blk[80 + 8 + 1000000];
|
||||
memcpy(blk, data, 76);
|
||||
nonce = htonl(nonce);
|
||||
memcpy(&blk[76], &nonce, 4);
|
||||
size_t offs = 80;
|
||||
|
||||
if (foreign || (!(tmpl->mutations & BMAb_TRUNCATE && !dataid)))
|
||||
{
|
||||
offs += varintEncode(&blk[offs], 1 + tmpl->txncount);
|
||||
|
||||
if (!_blkmk_extranonce(tmpl, &blk[offs], dataid, &offs))
|
||||
return NULL;
|
||||
|
||||
if (foreign || !(tmpl->mutations & BMAb_COINBASE))
|
||||
for (unsigned long i = 0; i < tmpl->txncount; ++i)
|
||||
{
|
||||
memcpy(&blk[offs], tmpl->txns[i].data, tmpl->txns[i].datasz);
|
||||
offs += tmpl->txns[i].datasz;
|
||||
}
|
||||
}
|
||||
|
||||
char blkhex[(offs * 2) + 1];
|
||||
my_bin2hex(blkhex, blk, offs);
|
||||
char *blkhex = blkmk_assemble_submission_(tmpl, data, dataid, nonce, foreign);
|
||||
if (!blkhex)
|
||||
return NULL;
|
||||
|
||||
json_t *rv = json_array(), *ja, *jb;
|
||||
jb = NULL;
|
||||
if (!(ja = json_string(blkhex)))
|
||||
ja = json_string(blkhex);
|
||||
free(blkhex);
|
||||
if (!ja)
|
||||
goto err;
|
||||
if (json_array_append_new(rv, ja))
|
||||
goto err;
|
||||
|
||||
Reference in New Issue
Block a user