Implement BIP 9 template request "rules" parameter

This commit is contained in:
Luke Dashjr
2016-04-27 05:53:37 +00:00
parent 4bebe501ad
commit 1e49556078
3 changed files with 31 additions and 1 deletions

View File

@@ -18,6 +18,10 @@
#include "private.h"
const char *blkmk_supported_rules[] = {
NULL
};
static inline
void my_htole32(unsigned char *buf, uint32_t n) {
buf[0] = (n >> 0) % 256;

View File

@@ -28,7 +28,8 @@
# error "Jansson 2.0 with long long support required!"
#endif
json_t *blktmpl_request_jansson(gbt_capabilities_t caps, const char *lpid) {
static
json_t *blktmpl_request_jansson2(const uint32_t caps, const char * const lpid, const char * const * const rulelist) {
json_t *req, *jcaps, *jstr, *reqf, *reqa;
if (!(req = json_object()))
return NULL;
@@ -67,6 +68,26 @@ json_t *blktmpl_request_jansson(gbt_capabilities_t caps, const char *lpid) {
if (json_object_set_new(req, "longpollid", jstr))
goto err;
}
jstr = NULL;
// Add rules list
if (!(jcaps = json_array())) {
goto err;
}
for (const char * const *currule = rulelist; *currule; ++currule) {
if (!(jstr = json_string(*currule))) {
goto err;
}
if (json_array_append_new(jcaps, jstr)) {
goto err;
}
}
jstr = NULL;
if (json_object_set_new(req, "rules", jcaps))
goto err;
jcaps = NULL;
// Put together main JSON-RPC request Object
if (!(jstr = json_string("getblocktemplate")))
goto err;
if (json_object_set_new(reqf, "method", jstr))
@@ -89,6 +110,10 @@ err:
return NULL;
}
json_t *blktmpl_request_jansson(gbt_capabilities_t caps, const char *lpid) {
return blktmpl_request_jansson2(caps, lpid, blkmk_supported_rules);
}
#define my_hex2bin _blkmk_hex2bin

View File

@@ -5,6 +5,7 @@
#include <string.h>
// blkmaker.c
extern const char *blkmk_supported_rules[];
extern bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz);
// blktemplate.c