Basically, `devtools/reduce-includes.sh */*.c`. Build time from make clean (RUST=0) (includes building external libs): Before: real 0m38.944000-40.416000(40.1131+/-0.4)s user 3m6.790000-17.159000(15.0571+/-2.8)s sys 0m35.304000-37.336000(36.8942+/-0.57)s After: real 0m37.872000-39.974000(39.5466+/-0.59)s user 3m1.211000-14.968000(12.4556+/-3.9)s sys 0m35.008000-36.830000(36.4143+/-0.5)s Build time after touch config.vars (RUST=0): Before: real 0m19.831000-21.862000(21.5528+/-0.58)s user 2m15.361000-30.731000(28.4798+/-4.4)s sys 0m21.056000-22.339000(22.0346+/-0.35)s After: real 0m18.384000-21.307000(20.8605+/-0.92)s user 2m5.585000-26.843000(23.6017+/-6.7)s sys 0m19.650000-22.003000(21.4943+/-0.69)s Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
/* Converted to C by Rusty Russell, based on bitcoin source: */
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2012 The Bitcoin Developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
#include "config.h"
|
|
#include <bitcoin/address.h>
|
|
#include <bitcoin/base58.h>
|
|
#include <common/utils.h>
|
|
#include <wally_core.h>
|
|
|
|
static char *to_base58(const tal_t *ctx, u8 version,
|
|
const struct ripemd160 *rmd)
|
|
{
|
|
char *out;
|
|
size_t total_length = sizeof(*rmd) + 1;
|
|
u8 buf[total_length];
|
|
buf[0] = version;
|
|
memcpy(buf + 1, rmd, sizeof(*rmd));
|
|
|
|
tal_wally_start();
|
|
if (wally_base58_from_bytes((const unsigned char *) buf,
|
|
total_length, BASE58_FLAG_CHECKSUM, &out)
|
|
!= WALLY_OK)
|
|
out = NULL;
|
|
tal_wally_end_onto(ctx, out, char);
|
|
|
|
return out;
|
|
}
|
|
|
|
char *bitcoin_to_base58(const tal_t *ctx, const struct chainparams *chainparams,
|
|
const struct bitcoin_address *addr)
|
|
{
|
|
return to_base58(ctx, chainparams->p2pkh_version, &addr->addr);
|
|
}
|
|
|
|
char *p2sh_to_base58(const tal_t *ctx, const struct chainparams *chainparams,
|
|
const struct ripemd160 *p2sh)
|
|
{
|
|
return to_base58(ctx, chainparams->p2sh_version, p2sh);
|
|
}
|
|
|
|
static bool from_base58(u8 *version,
|
|
struct ripemd160 *rmd,
|
|
const char *base58, size_t base58_len)
|
|
{
|
|
/* Initialize to avoid memcheck complaining if decoding a short value */
|
|
u8 buf[1 + sizeof(*rmd) + 4] = { 0 };
|
|
const size_t buflen = sizeof(buf);
|
|
const uint32_t flags = BASE58_FLAG_CHECKSUM;
|
|
|
|
size_t written = 0;
|
|
int r = wally_base58_n_to_bytes(base58, base58_len, flags,
|
|
buf, buflen, &written);
|
|
if (r != WALLY_OK || written > buflen) {
|
|
return false;
|
|
}
|
|
*version = buf[0];
|
|
memcpy(rmd, buf + 1, sizeof(*rmd));
|
|
return true;
|
|
}
|
|
|
|
bool ripemd160_from_base58(u8 *version, struct ripemd160 *rmd,
|
|
const char *base58, size_t base58_len)
|
|
{
|
|
return from_base58(version, rmd, base58, base58_len);
|
|
}
|