From 981f4f1b2b7a754f5144b83abd1bc0372320beca Mon Sep 17 00:00:00 2001 From: "zhibiao.pan" Date: Thu, 31 Mar 2016 17:36:36 +0800 Subject: [PATCH 1/4] fix "missing braces around initializer" --- daemon/bitcoind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daemon/bitcoind.c b/daemon/bitcoind.c index 9536c83bdd6c..60e42293d335 100644 --- a/daemon/bitcoind.c +++ b/daemon/bitcoind.c @@ -192,7 +192,7 @@ static void process_transactions(struct bitcoin_cli *bcli) end = json_next(tokens); for (t = tokens + 1; t < end; t = json_next(t)) { - struct sha256_double txid, blkhash = { 0 }; + struct sha256_double txid, blkhash; const jsmntok_t *txidtok, *conftok, *blkindxtok, *blktok; unsigned int conf; bool is_coinbase; From d9890534d0ffd5d59e929c8e597978ab68403097 Mon Sep 17 00:00:00 2001 From: "zhibiao.pan" Date: Thu, 7 Apr 2016 19:05:20 +0800 Subject: [PATCH 2/4] bitcoind: add convert sha256 to string --- bitcoin/shadouble.c | 19 +++++++++++++++++++ bitcoin/shadouble.h | 4 ++++ daemon/bitcoind.c | 12 +++++++----- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/bitcoin/shadouble.c b/bitcoin/shadouble.c index c229b9744c02..40950ebae9ba 100644 --- a/bitcoin/shadouble.c +++ b/bitcoin/shadouble.c @@ -1,5 +1,7 @@ #include "shadouble.h" #include +#include +#include void sha256_double(struct sha256_double *shadouble, const void *p, size_t len) { @@ -12,3 +14,20 @@ void sha256_double_done(struct sha256_ctx *shactx, struct sha256_double *res) sha256_done(shactx, &res->sha); sha256(&res->sha, &res->sha, sizeof(res->sha)); } + +char *sha256_str(struct sha256 *sha) +{ + const size_t size = sizeof(struct sha256); + char *hex = tal_arr(NULL, char, size * 2 + 1); + size_t i = 0; + for (; i < size; i++) { + sprintf(hex + i*2, "%02x", sha->u.u8[size - i - 1]); + } + *(hex + size*2) = '\0'; + return hex; +} + +char *sha256_double_str(struct sha256_double *shadouble) +{ + return sha256_str(&shadouble->sha); +} \ No newline at end of file diff --git a/bitcoin/shadouble.h b/bitcoin/shadouble.h index f447df7f19a0..0ad371be5d8c 100644 --- a/bitcoin/shadouble.h +++ b/bitcoin/shadouble.h @@ -11,4 +11,8 @@ struct sha256_double { void sha256_double(struct sha256_double *shadouble, const void *p, size_t len); void sha256_double_done(struct sha256_ctx *sha256, struct sha256_double *res); + +char *sha256_str(struct sha256 *sha); +char *sha256_double_str(struct sha256_double *shadouble); + #endif /* LIGHTNING_BITCOIN_SHADOUBLE_H */ diff --git a/daemon/bitcoind.c b/daemon/bitcoind.c index 0de291060770..e9e51f7e5aa0 100644 --- a/daemon/bitcoind.c +++ b/daemon/bitcoind.c @@ -251,12 +251,14 @@ static void process_transactions(struct bitcoin_cli *bcli) bcli->output + blktok->start); } } - /* FIXME: log txid, blkid */ + + char *txid_str = sha256_double_str(&txid); + char *blkhash_str = sha256_double_str(&blkhash); log_debug(bcli->dstate->base_log, - "txid %02x%02x%02x%02x..., conf %u, coinbase %u", - txid.sha.u.u8[0], txid.sha.u.u8[1], - txid.sha.u.u8[2], txid.sha.u.u8[3], - conf, is_coinbase); + "txid %s, conf %u, coinbase %u, blkhash %s", + txid_str, conf, is_coinbase, conf ? blkhash_str : "null"); + tal_free(txid_str); + tal_free(blkhash_str); cb(bcli->dstate, &txid, conf, is_coinbase, conf ? &blkhash : NULL); From a4409e7046941486e8363fe3713f4de034e9bafc Mon Sep 17 00:00:00 2001 From: "zhibiao.pan" Date: Thu, 7 Apr 2016 19:09:56 +0800 Subject: [PATCH 3/4] docs: add install libsodium --- INSTALL.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/INSTALL.md b/INSTALL.md index 7e0b4302ea93..a9680ebe9620 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -10,6 +10,7 @@ You will need several development libraries: To Build on Ubuntu 15.10 ------------------------ Build protobuf-c dependency (>= 1.1.0): + ``` sudo apt-get install libprotoc-dev git clone https://github.com/protobuf-c/protobuf-c.git @@ -21,7 +22,20 @@ make install cd ../ ``` +Build libsodium: + +``` +wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz +tar zxvf LATEST.tar.gz +cd libsodium-1.0.10 +./configure +make && make check +make install +cd ../ +``` + Clone lightning and initialize submodules: + ``` git clone https://github.com/ElementsProject/lightning.git cd lighting From 3bd90a49509cb7da7bcc6f174930923770ec00f0 Mon Sep 17 00:00:00 2001 From: "zhibiao.pan" Date: Wed, 13 Apr 2016 20:02:12 +0800 Subject: [PATCH 4/4] add tal allocated object to be parent --- bitcoin/shadouble.c | 9 ++++----- bitcoin/shadouble.h | 5 +++-- daemon/bitcoind.c | 7 ++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/bitcoin/shadouble.c b/bitcoin/shadouble.c index 40950ebae9ba..fc1694bf9a96 100644 --- a/bitcoin/shadouble.c +++ b/bitcoin/shadouble.c @@ -1,6 +1,5 @@ #include "shadouble.h" #include -#include #include void sha256_double(struct sha256_double *shadouble, const void *p, size_t len) @@ -15,10 +14,10 @@ void sha256_double_done(struct sha256_ctx *shactx, struct sha256_double *res) sha256(&res->sha, &res->sha, sizeof(res->sha)); } -char *sha256_str(struct sha256 *sha) +char *sha256_str(const tal_t *ctx, struct sha256 *sha) { const size_t size = sizeof(struct sha256); - char *hex = tal_arr(NULL, char, size * 2 + 1); + char *hex = tal_arr(ctx, char, size * 2 + 1); size_t i = 0; for (; i < size; i++) { sprintf(hex + i*2, "%02x", sha->u.u8[size - i - 1]); @@ -27,7 +26,7 @@ char *sha256_str(struct sha256 *sha) return hex; } -char *sha256_double_str(struct sha256_double *shadouble) +char *sha256_double_str(const tal_t *ctx, struct sha256_double *shadouble) { - return sha256_str(&shadouble->sha); + return sha256_str(ctx, &shadouble->sha); } \ No newline at end of file diff --git a/bitcoin/shadouble.h b/bitcoin/shadouble.h index 0ad371be5d8c..693e231ad28d 100644 --- a/bitcoin/shadouble.h +++ b/bitcoin/shadouble.h @@ -2,6 +2,7 @@ #define LIGHTNING_BITCOIN_SHADOUBLE_H #include "config.h" #include +#include /* To explicitly distinguish between single sha and bitcoin's standard double */ struct sha256_double { @@ -12,7 +13,7 @@ void sha256_double(struct sha256_double *shadouble, const void *p, size_t len); void sha256_double_done(struct sha256_ctx *sha256, struct sha256_double *res); -char *sha256_str(struct sha256 *sha); -char *sha256_double_str(struct sha256_double *shadouble); +char *sha256_str(const tal_t *ctx, struct sha256 *sha); +char *sha256_double_str(const tal_t *ctx, struct sha256_double *shadouble); #endif /* LIGHTNING_BITCOIN_SHADOUBLE_H */ diff --git a/daemon/bitcoind.c b/daemon/bitcoind.c index e9e51f7e5aa0..c6b562465822 100644 --- a/daemon/bitcoind.c +++ b/daemon/bitcoind.c @@ -252,13 +252,10 @@ static void process_transactions(struct bitcoin_cli *bcli) } } - char *txid_str = sha256_double_str(&txid); - char *blkhash_str = sha256_double_str(&blkhash); log_debug(bcli->dstate->base_log, "txid %s, conf %u, coinbase %u, blkhash %s", - txid_str, conf, is_coinbase, conf ? blkhash_str : "null"); - tal_free(txid_str); - tal_free(blkhash_str); + sha256_double_str(bcli, &txid), conf, is_coinbase, + conf ? sha256_double_str(bcli, &blkhash) : "null"); cb(bcli->dstate, &txid, conf, is_coinbase, conf ? &blkhash : NULL);