[Pkg-bitcoin-commits] [libblkmaker] 01/01: Imported Upstream version 0.5.0
Dmitry Smirnov
onlyjob at moszumanska.debian.org
Thu Jan 1 03:28:48 UTC 2015
This is an automated email from the git hooks/post-receive script.
onlyjob pushed a commit to branch upstream
in repository libblkmaker.
commit ae0ca54 (upstream)
Author: Dmitry Smirnov <onlyjob at member.fsf.org>
Date: Thu Jan 1 03:27:33 2015
Imported Upstream version 0.5.0
---
ChangeLog | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++
Makefile.am | 14 ++++-
autogen.sh | 1 -
base58.c | 97 ++++-------------------------
blkmaker.c | 122 ++++++++++++++++++++++++++++++++-----
blkmaker.h | 10 ++-
blkmaker_jansson.c | 137 +++++++++++++++++++++++------------------
blkmaker_jansson.h | 11 +++-
blktemplate.c | 15 +++--
blktemplate.h | 28 ++++++---
configure.ac | 6 +-
example.c | 13 ++--
private.h | 8 +--
13 files changed, 453 insertions(+), 185 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 646954b..db9a50f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,179 @@
+2014-09-10 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bump versions for 0.5.0
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * jansson: Read time header mutation parameters
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Read tmpl->target as an optional hash (breaks ABI)
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: example: Set b58_sha256_impl
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Remove unused blktemplate_t fields (breaks ABI)
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * NULL-Merge commit '5a9a96a'
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge commit 'e86fe28'
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * NULL-Merge commit '09921de'
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.4.x'
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Keep correct ordered hash in txn->hash[1] for use internally while remaining ABI-safe
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * blktemplate.h: Add warning against allocating blktemplate_t
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.3.x' into 0.4.x
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.2.x' into 0.3.x
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.1.x' into 0.2.x
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Revert "Bugfix: Provide correctly-ordered transaction hash (using new key hash_ for backward compatibility)" (broke ABI)
+
+2014-09-02 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: enum types are not guaranteed to be large enough for a bitmask, so explicitly use uint32_t for gbt_capabilities_t/blkmutations_t bitmasks (this breaks ABI)
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch 'proposals'
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch 'aux'
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.4.x'
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.3.x' into 0.4.x
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.2.x' into 0.3.x
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: blkmk_init_generation: Fail if scriptsz is longer than we properly handle, rather than creating an invalid block
+
+2014-09-01 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Parse and use coinbaseaux
+
+2014-08-24 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * blkmaker_jansson: Support for constructing BIP 23 block proposals
+
+2014-08-29 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * base58: Remove now-unused b58digits array
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Use libbase58 for base58 decoding
+
+2014-08-29 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * configure: Require only automake 1.11, since that is sufficient
+
+2014-08-24 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Move submission block assembly code to base libblkmaker
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.4.x'
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.3.x' into 0.4.x
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.2.x' into 0.3.x
+
+2014-08-18 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: b58tobin: Correct zeromask for multiple-of-four binary buffer sizes
+
+2014-08-18 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Avoid unsafe casting
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Include extern "C" wrapper in headers so they can be used from C++ code
+
+2014-08-18 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * b58check: Check binsz is long enough for checksum
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Switch to tar.xz dist
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.4.x'
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.3.x' into 0.4.x
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.2.x' into 0.3.x
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: Include private.h in SOURCES
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Merge branch '0.1.x' into 0.2.x
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bugfix: Include documents in "make dist" output
+
+2014-08-22 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * No longer call configure from autogen.sh
+
+2014-05-26 Luke Dashjr <luke-jr+git at utopios.org>
+
+ * Bump libtool version for 0.3.3
+
2014-05-26 Luke Dashjr <luke-jr+git at utopios.org>
* Merge commit '1cbe9c3'
diff --git a/Makefile.am b/Makefile.am
index b246212..578acab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,9 +12,15 @@ libblkmaker_ at LIBBLKMAKER_API_VERSION@_la_SOURCES = \
base58.c \
blkmaker.c \
blktemplate.c \
- hex.c
+ hex.c \
+ private.h
-libblkmaker_ at LIBBLKMAKER_API_VERSION@_la_LDFLAGS = -version-info $(LIBBLKMAKER_SO_VERSION) -no-undefined
+libblkmaker_ at LIBBLKMAKER_API_VERSION@_la_CFLAGS = \
+ $(libbase58_CFLAGS)
+libblkmaker_ at LIBBLKMAKER_API_VERSION@_la_LDFLAGS = \
+ $(libbase58_LIBS) \
+ -no-undefined \
+ -version-info $(LIBBLKMAKER_SO_VERSION)
libblkmaker_includedir = $(includedir)/libblkmaker-$(LIBBLKMAKER_API_VERSION)
libblkmaker_include_HEADERS = \
@@ -40,3 +46,7 @@ pkgconfig_DATA = \
libblkmaker_jansson-$(LIBBLKMAKER_API_VERSION).pc
dist_noinst_SCRIPTS = autogen.sh
+dist_noinst_DATA = \
+ AUTHORS COPYING README \
+ example.c \
+ testinput.c
diff --git a/autogen.sh b/autogen.sh
index 666e0fc..0e2f2d1 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -9,4 +9,3 @@ if test -z "$srcdir"; then
fi
fi
autoreconf --force --install --verbose "$srcdir"
-test -n "$NOCONFIGURE" || "$srcdir/configure" "$@"
diff --git a/base58.c b/base58.c
index 6810002..ea3343f 100644
--- a/base58.c
+++ b/base58.c
@@ -15,108 +15,35 @@
#include <stdint.h>
#include <string.h>
+#include <libbase58.h>
+
#include <blkmaker.h>
#include "private.h"
-static const int8_t b58digits[] = {
- -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1,
- -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1,
- 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1,
- -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46,
- 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1,
-};
-
bool _blkmk_b58tobin(void *bin, size_t binsz, const char *b58, size_t b58sz) {
- const unsigned char *b58u = (void*)b58;
- unsigned char *binu = bin;
- size_t outisz = (binsz + 3) / 4;
- uint32_t outi[outisz];
- uint64_t t;
- uint32_t c;
- size_t i, j;
- uint8_t bytesleft = binsz % 4;
- uint32_t zeromask = ~((1 << ((bytesleft) * 8)) - 1);
-
- if (!b58sz)
- b58sz = strlen(b58);
-
- memset(outi, 0, outisz * sizeof(*outi));
-
- for (i = 0; i < b58sz; ++i)
- {
- if (b58u[i] & 0x80)
- // High-bit set on invalid digit
- return false;
- if (b58digits[b58u[i]] == -1)
- // Invalid base58 digit
- return false;
- c = b58digits[b58u[i]];
- for (j = outisz; j--; )
- {
- t = ((uint64_t)outi[j]) * 58 + c;
- c = (t & 0x3f00000000) >> 32;
- outi[j] = t & 0xffffffff;
- }
- if (c)
- // Output number too big (carry to the next int32)
- return false;
- if (outi[0] & zeromask)
- // Output number too big (last int32 filled too far)
- return false;
- }
-
- j = 0;
- switch (bytesleft) {
- case 3:
- *(binu++) = (outi[0] & 0xff0000) >> 16;
- case 2:
- *(binu++) = (outi[0] & 0xff00) >> 8;
- case 1:
- *(binu++) = (outi[0] & 0xff);
- ++j;
- default:
- break;
- }
-
- for (; j < outisz; ++j)
- {
- *((uint32_t*)binu) = htonl(outi[j]);
- binu += sizeof(uint32_t);
- }
- return true;
+ return b58tobin(bin, &binsz, b58, b58sz);
}
int _blkmk_b58check(void *bin, size_t binsz, const char *base58str) {
- unsigned char buf[32];
- unsigned char *binc = bin;
- unsigned i;
- if (!_blkmk_dblsha256(buf, bin, binsz - 4))
- return -2;
- if (memcmp(&binc[binsz - 4], buf, 4))
- return -1;
-
- // Check number of zeros is correct AFTER verifying checksum (to avoid possibility of accessing base58str beyond the end)
- for (i = 0; binc[i] == '\0' && base58str[i] == '1'; ++i)
- {} // Just finding the end of zeros, nothing to do in loop
- if (binc[i] == '\0' || base58str[i] == '1')
- return -3;
-
- return binc[0];
+ if (!b58_sha256_impl)
+ b58_sha256_impl = blkmk_sha256_impl;
+ return b58check(bin, binsz, base58str, 34);
}
size_t blkmk_address_to_script(void *out, size_t outsz, const char *addr) {
unsigned char addrbin[25];
unsigned char *cout = out;
+ const size_t b58sz = strlen(addr);
int addrver;
size_t rv;
- if (!_blkmk_b58tobin(addrbin, sizeof(addrbin), addr, 0))
+ rv = sizeof(addrbin);
+ if (!b58_sha256_impl)
+ b58_sha256_impl = blkmk_sha256_impl;
+ if (!b58tobin(addrbin, &rv, addr, b58sz))
return 0;
- addrver = _blkmk_b58check(addrbin, sizeof(addrbin), addr);
+ addrver = b58check(addrbin, sizeof(addrbin), addr, b58sz);
switch (addrver) {
case 0: // Bitcoin pubkey hash
case 111: // Testnet pubkey hash
diff --git a/blkmaker.c b/blkmaker.c
index 2a6eaf3..7bc1421 100644
--- a/blkmaker.c
+++ b/blkmaker.c
@@ -13,6 +13,12 @@
#include <time.h>
#include <unistd.h>
+#ifndef WIN32
+#include <arpa/inet.h>
+#else
+#include <winsock2.h>
+#endif
+
#include <blkmaker.h>
#include <blktemplate.h>
@@ -50,8 +56,10 @@ 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);
+ if (scriptsz >= 0xfd)
+ return 0;
+
+ unsigned char *data = malloc(168 + scriptsz);
size_t off = 0;
if (!data)
return 0;
@@ -76,6 +84,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
@@ -324,6 +353,23 @@ void blkmk_set_times(blktemplate_t *tmpl, void * const out_hdrbuf, const time_t
}
}
+bool blkmk_sample_data_(blktemplate_t * const tmpl, uint8_t * const cbuf, const unsigned int dataid) {
+ my_htole32(&cbuf[0], tmpl->version);
+ memcpy(&cbuf[4], &tmpl->prevblk, 32);
+
+ unsigned char cbtxndata[tmpl->cbtxn->datasz + sizeof(dataid)];
+ size_t cbtxndatasz = 0;
+ if (!_blkmk_extranonce(tmpl, cbtxndata, dataid, &cbtxndatasz))
+ return false;
+ if (!build_merkle_root(&cbuf[36], tmpl, cbtxndata, cbtxndatasz))
+ return false;
+
+ my_htole32(&cbuf[0x44], tmpl->curtime);
+ memcpy(&cbuf[72], &tmpl->diffbits, 4);
+
+ return true;
+}
+
size_t blkmk_get_data(blktemplate_t *tmpl, void *buf, size_t bufsz, time_t usetime, int16_t *out_expire, unsigned int *out_dataid) {
if (!(blkmk_time_left(tmpl, usetime) && blkmk_work_left(tmpl) && tmpl->cbtxn))
return 0;
@@ -332,22 +378,10 @@ size_t blkmk_get_data(blktemplate_t *tmpl, void *buf, size_t bufsz, time_t useti
unsigned char *cbuf = buf;
- my_htole32(&cbuf[0], tmpl->version);
- memcpy(&cbuf[4], &tmpl->prevblk, 32);
-
- unsigned char cbtxndata[tmpl->cbtxn->datasz + sizeof(*out_dataid)];
- size_t cbtxndatasz = 0;
*out_dataid = tmpl->next_dataid++;
- if (!_blkmk_extranonce(tmpl, cbtxndata, *out_dataid, &cbtxndatasz))
- return 0;
- if (!build_merkle_root(&cbuf[36], tmpl, cbtxndata, cbtxndatasz))
+ if (!blkmk_sample_data_(tmpl, cbuf, *out_dataid))
return 0;
-
blkmk_set_times(tmpl, &cbuf[68], usetime, out_expire, false);
- memcpy(&cbuf[72], &tmpl->diffbits, 4);
-
- // TEMPORARY HACK:
- memcpy(tmpl->_mrklroot, &cbuf[36], 32);
return 76;
}
@@ -416,3 +450,61 @@ unsigned long blkmk_work_left(const blktemplate_t *tmpl) {
return UINT_MAX - tmpl->next_dataid;
return BLKMK_UNLIMITED_WORK_COUNT;
}
+
+static
+char varintEncode(unsigned char *out, uint64_t n) {
+ if (n < 0xfd)
+ {
+ out[0] = n;
+ return 1;
+ }
+ 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;
+}
+
+char *blkmk_assemble_submission_(blktemplate_t * const tmpl, const unsigned char * const data, const unsigned int dataid, blknonce_t nonce, const 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 = malloc((offs * 2) + 1);
+ _blkmk_bin2hex(blkhex, blk, offs);
+
+ return blkhex;
+}
diff --git a/blkmaker.h b/blkmaker.h
index 4997ade..757860e 100644
--- a/blkmaker.h
+++ b/blkmaker.h
@@ -7,7 +7,11 @@
#include <blktemplate.h>
-#define BLKMAKER_VERSION (5L)
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BLKMAKER_VERSION (6L)
#define BLKMAKER_MAX_BLOCK_VERSION (2)
extern bool (*blkmk_sha256_impl)(void *hash_out, const void *data, size_t datasz);
@@ -26,4 +30,8 @@ extern unsigned long blkmk_work_left(const blktemplate_t *);
extern size_t blkmk_address_to_script(void *out, size_t outsz, const char *addr);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/blkmaker_jansson.c b/blkmaker_jansson.c
index 2144846..83e9bb2 100644
--- a/blkmaker_jansson.c
+++ b/blkmaker_jansson.c
@@ -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>
@@ -27,7 +21,7 @@
# error "Jansson 2.0 with long long support required!"
#endif
-json_t *blktmpl_request_jansson(gbt_capabilities_t caps, const char *lpid) {
+json_t *blktmpl_request_jansson(const uint32_t caps, const char * const lpid) {
json_t *req, *jcaps, *jstr, *reqf, *reqa;
if (!(req = json_object()))
return NULL;
@@ -207,6 +201,10 @@ const char *blktmpl_add_jansson(blktemplate_t *tmpl, const json_t *json, time_t
GETSTR(workid, workid);
GETNUM_O(expires);
+ GETNUM_O(maxtime);
+ GETNUM_O(maxtimeoff);
+ GETNUM_O(mintime);
+ GETNUM_O(mintimeoff);
GETSTR(longpollid, lp.id);
GETSTR(longpolluri, lp.uri);
@@ -226,7 +224,33 @@ 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, "target")) && json_is_string(v))
+ {
+ tmpl->target = malloc(sizeof(*tmpl->target));
+ if (!my_hex2bin(tmpl->target, json_string_value(v), sizeof(*tmpl->target)))
+ return "Error decoding 'target'";
+ }
if ((v = json_object_get(json, "mutable")) && json_is_array(v))
{
@@ -253,66 +277,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)
- {
- out[0] = n;
- return 1;
- }
- char L;
- if (n <= 0xffff)
- {
- out[0] = '\xfd';
- L = 3;
- }
- else
- if (n <= 0xffffffff)
- {
- out[0] = '\xfe';
- L = 5;
- }
- else
+json_t *blktmpl_propose_jansson(blktemplate_t * const tmpl, const uint32_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] = '\xff';
- L = 9;
+ if (!(ja = json_string(tmpl->workid)))
+ goto err;
+ if (json_object_set_new(jparams, "workid", ja))
+ goto err;
}
- 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;
diff --git a/blkmaker_jansson.h b/blkmaker_jansson.h
index 0345cff..08a5d6e 100644
--- a/blkmaker_jansson.h
+++ b/blkmaker_jansson.h
@@ -5,9 +5,18 @@
#include <blktemplate.h>
-extern json_t *blktmpl_request_jansson(gbt_capabilities_t extracaps, const char *lpid);
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern json_t *blktmpl_request_jansson(uint32_t extracaps, const char *lpid);
extern const char *blktmpl_add_jansson(blktemplate_t *, const json_t *, time_t time_rcvd);
+extern json_t *blktmpl_propose_jansson(blktemplate_t *, uint32_t caps, bool foreign);
extern json_t *blkmk_submit_jansson(blktemplate_t *, const unsigned char *data, unsigned int dataid, blknonce_t);
extern json_t *blkmk_submit_foreign_jansson(blktemplate_t *, const unsigned char *data, unsigned int dataid, blknonce_t);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/blktemplate.c b/blktemplate.c
index 83d8292..ce129a1 100644
--- a/blktemplate.c
+++ b/blktemplate.c
@@ -75,7 +75,7 @@ blktemplate_t *blktmpl_create() {
return tmpl;
}
-gbt_capabilities_t blktmpl_addcaps(const blktemplate_t *tmpl) {
+uint32_t blktmpl_addcaps(const blktemplate_t *tmpl) {
// TODO: make this a lot more flexible for merging
// For now, it's a simple "filled" vs "not filled"
if (tmpl->version)
@@ -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]);
@@ -111,10 +117,11 @@ void blktmpl_free(blktemplate_t *tmpl) {
free(tmpl->cbtxn);
}
free(tmpl->_mrklbranch);
- // 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->target);
free(tmpl->lp.id);
free(tmpl->lp.uri);
free(tmpl);
diff --git a/blktemplate.h b/blktemplate.h
index 8b832c5..7bed8ec 100644
--- a/blktemplate.h
+++ b/blktemplate.h
@@ -12,6 +12,10 @@
#include <stdint.h>
#include <time.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef uint32_t blkheight_t;
typedef uint32_t libblkmaker_hash_t[8];
typedef libblkmaker_hash_t blkhash_t;
@@ -36,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;
@@ -80,6 +90,7 @@ extern gbt_capabilities_t blktmpl_getcapability(const char *);
typedef gbt_capabilities_t blkmutations_t;
+// WARNING: Do not allocate this (ABI is not guaranteed to remain fixed-size)
typedef struct {
uint32_t version;
unsigned char diffbits[4];
@@ -96,9 +107,6 @@ typedef struct {
time_t _time_rcvd;
blktime_t curtime;
- char auxcount;
- char **auxnames;
- unsigned char **auxdata;
char *workid;
@@ -108,10 +116,10 @@ typedef struct {
// BIP 23: Basic Pool Extensions
int16_t expires;
- blkhash_t target;
+ blkhash_t *target;
// BIP 23: Mutations
- blkmutations_t mutations;
+ uint32_t mutations;
blktime_t maxtime;
blktime_diff_t maxtimeoff;
blktime_t mintime;
@@ -122,14 +130,20 @@ typedef struct {
// TEMPORARY HACK
libblkmaker_hash_t *_mrklbranch;
int _mrklbranchcount;
- libblkmaker_hash_t _mrklroot;
unsigned int next_dataid;
+
+ unsigned aux_count;
+ struct blkaux_t *auxs;
} blktemplate_t;
extern blktemplate_t *blktmpl_create();
-extern gbt_capabilities_t blktmpl_addcaps(const blktemplate_t *);
+extern uint32_t blktmpl_addcaps(const blktemplate_t *);
extern const struct blktmpl_longpoll_req *blktmpl_get_longpoll(blktemplate_t *);
extern bool blktmpl_get_submitold(blktemplate_t *tmpl);
extern void blktmpl_free(blktemplate_t *);
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/configure.ac b/configure.ac
index bfc5d1c..b8a6eb2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -11,7 +11,7 @@ AC_INIT(
[http://gitorious.org/bitcoin/libblkmaker])
AC_CONFIG_AUX_DIR([.])
AC_PREREQ([2.59])
-AM_INIT_AUTOMAKE([1.10 -Wall dist-bzip2 foreign])
+AM_INIT_AUTOMAKE([1.11 -Wall dist-xz foreign])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
AC_PROG_CC_C99
@@ -19,7 +19,7 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
LT_INIT([disable-static])
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
-AC_SUBST([LIBBLKMAKER_SO_VERSION], [5:0:5])
+AC_SUBST([LIBBLKMAKER_SO_VERSION], [6:0:0])
AC_SUBST([LIBBLKMAKER_API_VERSION], [0.1])
AC_CONFIG_FILES([Makefile
@@ -47,6 +47,8 @@ PKG_CHECK_MODULES([JANSSON],[jansson],[
AC_SUBST(JANSSON_CFLAGS)
AC_SUBST(JANSSON_LIBS)
+PKG_CHECK_MODULES([libbase58],[libbase58])
+
AC_CHECK_LIB([ws2_32], [strchr])
AC_OUTPUT
diff --git a/example.c b/example.c
index 7f8c1e2..595922c 100644
--- a/example.c
+++ b/example.c
@@ -12,6 +12,7 @@
#include <arpa/inet.h>
#include <gcrypt.h>
+#include <libbase58.h>
#include <blkmaker.h>
#include <blkmaker_jansson.h>
@@ -23,20 +24,23 @@ void testb58() {
int rv;
const char *iaddr = "11Baf75Ferj6A7AoN565gCQj9kGWbDMHfN9";
const char *addr = &iaddr[1];
+ const size_t addrlen = strlen(addr);
+ size_t actuallen;
char bufx[26] = {'\xff'};
char *buf = &bufx[1];
- if (!_blkmk_b58tobin(buf, 25, addr, 0))
+ actuallen = 25;
+ if (!b58tobin(buf, &actuallen, addr, addrlen))
exit(1);
if (bufx[0] != '\xff')
exit(2);
char cbuf[51];
_blkmk_bin2hex(cbuf, buf, 25);
printf("Base58 raw data: %s\n", cbuf);
- assert((rv = _blkmk_b58check(buf, 25, addr)) == 0);
+ assert((rv = b58check(buf, 25, addr, addrlen)) == 0);
printf("Base58 check: %d\n", rv);
- assert((rv = _blkmk_b58check(buf, 25, &addr[1])) < 0);
+ assert((rv = b58check(buf, 25, &addr[1], addrlen)) < 0);
printf("Base58 check (invalid/ unpadded): %d\n", rv);
- assert((rv = _blkmk_b58check(buf, 25, iaddr)) < 0);
+ assert((rv = b58check(buf, 25, iaddr, addrlen + 1)) < 0);
printf("Base58 check (invalid/extra padded): %d\n", rv);
}
@@ -59,6 +63,7 @@ int main(int argc, char**argv) {
json_error_t jsone;
const char *err;
+ b58_sha256_impl = my_sha256;
blkmk_sha256_impl = my_sha256;
testb58();
diff --git a/private.h b/private.h
index f0e437a..f149223 100644
--- a/private.h
+++ b/private.h
@@ -4,8 +4,12 @@
#include <stdbool.h>
#include <string.h>
+#include <blktemplate.h>
+
// blkmaker.c
extern bool _blkmk_dblsha256(void *hash, const void *data, size_t datasz);
+extern bool blkmk_sample_data_(blktemplate_t *, uint8_t *, unsigned int dataid);
+extern char *blkmk_assemble_submission_(blktemplate_t *, const unsigned char *data, unsigned int dataid, blknonce_t nonce, bool foreign);
// blktemplate.c
extern void _blktxn_free(struct blktxn_t *);
@@ -14,10 +18,6 @@ extern void _blktxn_free(struct blktxn_t *);
extern void _blkmk_bin2hex(char *out, const void *data, size_t datasz);
extern bool _blkmk_hex2bin(void *o, const char *x, size_t len);
-// base58.c
-extern bool _blkmk_b58tobin(void *bin, size_t binsz, const char *b58, size_t b58sz);
-extern int _blkmk_b58check(void *bin, size_t binsz, const char *b58);
-
// inline
// NOTE: This must return 0 for 0
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/libblkmaker.git
More information about the Pkg-bitcoin-commits
mailing list