Skip to content

Commit

Permalink
Remove unused functions not covered by unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and rustyrussell committed Mar 26, 2018
1 parent b914062 commit 6269a4c
Show file tree
Hide file tree
Showing 19 changed files with 1 addition and 357 deletions.
23 changes: 0 additions & 23 deletions bitcoin/base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,6 @@ bool p2sh_from_base58(bool *test_net,
return true;
}

bool ripemd_from_base58(u8 *version,
struct ripemd160 *ripemd160,
const char *base58)
{
return from_base58(version, ripemd160, base58, strlen(base58));
}

char *key_to_base58(const tal_t *ctx, bool test_net, const struct privkey *key)
{
u8 buf[32 + 1];
char out[BASE58_KEY_MAX_LEN + 2];
u8 version = test_net ? 239 : 128;
size_t outlen = sizeof(out);

memcpy(buf, key->secret.data, sizeof(key->secret.data));
/* Mark this as a compressed key. */
buf[32] = 1;

b58_sha256_impl = my_sha256;
b58check_enc(out, &outlen, version, buf, sizeof(buf));
return tal_strdup(ctx, out);
}

bool key_from_base58(const char *base58, size_t base58_len,
bool *test_net, struct privkey *priv, struct pubkey *key)
{
Expand Down
4 changes: 0 additions & 4 deletions bitcoin/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ bool p2sh_from_base58(bool *test_net,
struct ripemd160 *p2sh,
const char *base58, size_t len);

bool ripemd_from_base58(u8 *version, struct ripemd160 *ripemd160,
const char *base58);

char *base58_with_check(char dest[BASE58_ADDR_MAX_LEN],
u8 buf[1 + sizeof(struct ripemd160) + 4]);

char *key_to_base58(const tal_t *ctx, bool test_net, const struct privkey *key);
bool key_from_base58(const char *base58, size_t base58_len,
bool *test_net, struct privkey *priv, struct pubkey *key);

Expand Down
36 changes: 0 additions & 36 deletions bitcoin/locktime.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
#define BIP68_LOCKTIME_MASK (0x0000FFFF)
#define BIP68_SECONDS_SHIFT 9

static bool abs_seconds_to_locktime(u32 seconds, u32 *locktime)
{
*locktime = seconds;
if (*locktime < SECONDS_POINT)
return false;
return true;
}

static bool abs_blocks_to_locktime(u32 blocks, u32 *locktime)
{
*locktime = blocks;
Expand All @@ -30,22 +22,6 @@ static bool abs_is_seconds(u32 locktime)
return locktime >= SECONDS_POINT;
}

bool seconds_to_rel_locktime(u32 seconds, struct rel_locktime *rel)
{
if ((seconds >> BIP68_SECONDS_SHIFT) > BIP68_LOCKTIME_MASK)
return false;
rel->locktime = BIP68_SECONDS_FLAG | (seconds >> BIP68_SECONDS_SHIFT);
return true;
}

bool blocks_to_rel_locktime(u32 blocks, struct rel_locktime *rel)
{
if (blocks > BIP68_LOCKTIME_MASK)
return false;
rel->locktime = blocks;
return true;
}

bool rel_locktime_is_seconds(const struct rel_locktime *rel)
{
return rel->locktime & BIP68_SECONDS_FLAG;
Expand All @@ -63,18 +39,6 @@ u32 rel_locktime_to_blocks(const struct rel_locktime *rel)
return rel->locktime & BIP68_LOCKTIME_MASK;
}

u32 bitcoin_nsequence(const struct rel_locktime *rel)
{
/* Can't set disable bit, or other bits except low 16 and bit 22 */
assert(!(rel->locktime & ~(BIP68_SECONDS_FLAG|BIP68_LOCKTIME_MASK)));
return rel->locktime;
}

bool seconds_to_abs_locktime(u32 seconds, struct abs_locktime *abs)
{
return abs_seconds_to_locktime(seconds, &abs->locktime);
}

bool blocks_to_abs_locktime(u32 blocks, struct abs_locktime *abs)
{
return abs_blocks_to_locktime(blocks, &abs->locktime);
Expand Down
5 changes: 0 additions & 5 deletions bitcoin/locktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@ struct rel_locktime {
u32 locktime;
};

bool seconds_to_rel_locktime(u32 seconds, struct rel_locktime *rel);
bool blocks_to_rel_locktime(u32 blocks, struct rel_locktime *rel);
bool rel_locktime_is_seconds(const struct rel_locktime *rel);
u32 rel_locktime_to_seconds(const struct rel_locktime *rel);
u32 rel_locktime_to_blocks(const struct rel_locktime *rel);

u32 bitcoin_nsequence(const struct rel_locktime *rel);

/* As used by nLocktime and OP_CHECKLOCKTIMEVERIFY (BIP65) */
struct abs_locktime {
u32 locktime;
};

bool seconds_to_abs_locktime(u32 seconds, struct abs_locktime *abs);
bool blocks_to_abs_locktime(u32 blocks, struct abs_locktime *abs);
bool abs_locktime_is_seconds(const struct abs_locktime *abs);
u32 abs_locktime_to_seconds(const struct abs_locktime *abs);
Expand Down
30 changes: 0 additions & 30 deletions bitcoin/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,6 @@ u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key)
return script;
}

/* Create an input which spends the p2sh-p2wpkh. */
void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
struct bitcoin_tx_input *input,
const secp256k1_ecdsa_signature *sig,
const struct pubkey *key)
{
input->script = bitcoin_scriptsig_p2sh_p2wpkh(ctx, key);
input->witness = bitcoin_witness_p2wpkh(ctx, sig, key);
}

u8 **bitcoin_witness_p2wpkh(const tal_t *ctx,
const secp256k1_ecdsa_signature *sig,
const struct pubkey *key)
Expand Down Expand Up @@ -495,26 +485,6 @@ u8 *bitcoin_wscript_to_local(const tal_t *ctx, u16 to_self_delay,
return script;
}

u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
const secp256k1_ecdsa_signature *revocation_sig,
const u8 *wscript)
{
/* BOLT #3:
*
* If a revoked commitment transaction is published, the other party
* can spend this output immediately with the following witness:
*
* <revocation_sig> 1
*/
u8 **witness = tal_arr(ctx, u8 *, 3);

witness[0] = stack_sig(witness, revocation_sig);
witness[1] = stack_number(witness, 1);
witness[2] = tal_dup_arr(witness, u8, wscript, tal_len(wscript), 0);

return witness;
}

/* BOLT #3:
*
* #### Offered HTLC Outputs
Expand Down
9 changes: 0 additions & 9 deletions bitcoin/script.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ u8 *bitcoin_redeem_p2pkh(const tal_t *ctx, const struct pubkey *pubkey,
/* Create the redeemscript for a P2SH + P2WPKH. */
u8 *bitcoin_redeem_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key);

/* Create a witness which spends the P2SH + P2WPKH. */
void bitcoin_witness_p2sh_p2wpkh(const tal_t *ctx,
struct bitcoin_tx_input *input,
const secp256k1_ecdsa_signature *sig,
const struct pubkey *key);

/* Create scriptsig for p2sh-p2wpkh */
u8 *bitcoin_scriptsig_p2sh_p2wpkh(const tal_t *ctx, const struct pubkey *key);

Expand Down Expand Up @@ -87,9 +81,6 @@ u8 *bitcoin_wscript_to_local(const tal_t *ctx,
u16 to_self_delay,
const struct pubkey *revocation_pubkey,
const struct pubkey *local_delayedkey);
u8 **bitcoin_to_local_spend_revocation(const tal_t *ctx,
const secp256k1_ecdsa_signature *revocation_sig,
const u8 *wscript);

/* BOLT #3 offered/accepted HTLC outputs */
u8 *bitcoin_wscript_htlc_offer(const tal_t *ctx,
Expand Down
10 changes: 0 additions & 10 deletions bitcoin/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,6 @@ bool signature_from_der(const u8 *der, size_t len, secp256k1_ecdsa_signature *si
sig, der, len);
}

/* Signature must have low S value. */
bool sig_valid(const secp256k1_ecdsa_signature *sig)
{
secp256k1_ecdsa_signature tmp;

if (secp256k1_ecdsa_signature_normalize(secp256k1_ctx, &tmp, sig) == 0)
return true;
return false;
}

static char *signature_to_hexstr(const tal_t *ctx,
const secp256k1_ecdsa_signature *sig)
{
Expand Down
3 changes: 0 additions & 3 deletions bitcoin/signature.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ bool check_tx_sig(struct bitcoin_tx *tx, size_t input_num,
const struct pubkey *key,
const secp256k1_ecdsa_signature *sig);

/* Signature must have low S value. */
bool sig_valid(const secp256k1_ecdsa_signature *sig);

/* Give DER encoding of signature: returns length used (<= 72). */
size_t signature_to_der(u8 der[72], const secp256k1_ecdsa_signature *s);

Expand Down
5 changes: 0 additions & 5 deletions cli/lightning-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ static void tal_freefn(void *ptr)
}

struct netaddr;
char *netaddr_name(const tal_t *ctx, const struct netaddr *a);
char *netaddr_name(const tal_t *ctx UNUSED, const struct netaddr *a UNUSED)
{
return NULL;
}

/* Returns number of tokens digested */
static size_t human_readable(const char *buffer, const jsmntok_t *t, char term)
Expand Down
60 changes: 0 additions & 60 deletions common/bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,6 @@ struct bolt11 *bolt11_decode(const tal_t *ctx, const char *str,
return b11;
}

static size_t num_u5(size_t num_u8)
{
return (num_u8 * 8 + 7) / 5;
}

static u8 get_bit(const u8 *src, size_t bitoff)
{
return ((src[bitoff / 8] >> (7 - (bitoff % 8))) & 1);
Expand Down Expand Up @@ -986,58 +981,3 @@ char *bolt11_encode_(const tal_t *ctx,

return output;
}

static PRINTF_FMT(2,3) void *bad(const char *abortstr, const char *fmt, ...)
{
if (abortstr) {
va_list ap;

va_start(ap, fmt);
fprintf(stderr, "%s: ", abortstr);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
abort();
}
return NULL;
}

struct bolt11 *bolt11_out_check(const struct bolt11 *b11, const char *abortstr)
{
struct bolt11_field *extra;

/* BOLT #2:
*
* For channels with `chain_hash` identifying the Bitcoin blockchain,
* the sending node MUST set the 4 most significant bytes of
* `amount_msat` to zero.
*/
if (*b11->msatoshi >= 1ULL << 32)
return bad(abortstr, "msatoshi %"PRIu64" too large",
*b11->msatoshi);

if (!b11->description && !b11->description_hash)
return bad(abortstr, "No description or description_hash");

if (b11->description && b11->description_hash)
return bad(abortstr, "Both description or description_hash");

if (b11->description && num_u5(strlen(b11->description)) > 1024)
return bad(abortstr, "Description too long");

/* FIXME: Check fallback is known type. */
if (b11->fallback && tal_count(b11->fallback) == 0)
return bad(abortstr, "Empty fallback");

if (!list_check(&b11->extra_fields, abortstr))
return bad(abortstr, "Invalid extras list");

list_for_each(&b11->extra_fields, extra, list) {
if (bech32_charset_rev[(unsigned char)extra->tag] < 0)
return bad(abortstr, "Invalid extra type %c (0x%02x)",
extra->tag, extra->tag);

if (tal_len(extra->data) >= 1024)
return bad(abortstr, "Extra %c too long", extra->tag);
}
return cast_const(struct bolt11 *, b11);
}
16 changes: 0 additions & 16 deletions common/bolt11.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,4 @@ char *bolt11_encode_(const tal_t *ctx,
secp256k1_ecdsa_recoverable_signature *rsig), \
(arg))

/**
* bolt11_out_check - check a bolt11 struct for validity and consistency
* @bolt11: the bolt11
* @abortstr: the location to print on aborting, or NULL.
*
* Note this does not apply to bolt11's we decoded, which may not be spec
* compliant.
*
* If @abortstr is non-NULL, that will be printed in a diagnostic if the bolt11
* is invalid, and the function will abort.
*
* Returns @bolt11 if all OK, NULL if not (it can never return NULL if
* @abortstr is set).
*/
struct bolt11 *bolt11_out_check(const struct bolt11 *bolt11,
const char *abortstr);
#endif /* LIGHTNING_COMMON_BOLT11_H */
50 changes: 1 addition & 49 deletions common/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,44 +187,6 @@ const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index)
return NULL;
}

/* Guide is a string with . for members, [] around indexes. */
const jsmntok_t *json_delve(const char *buffer,
const jsmntok_t *tok,
const char *guide)
{
while (*guide) {
const char *key;
size_t len = strcspn(guide+1, ".[]");

key = tal_strndup(NULL, guide+1, len);
switch (guide[0]) {
case '.':
if (tok->type != JSMN_OBJECT)
return tal_free(key);
tok = json_get_member(buffer, tok, key);
if (!tok)
return tal_free(key);
break;
case '[':
if (tok->type != JSMN_ARRAY)
return tal_free(key);
tok = json_get_arr(tok, atol(key));
if (!tok)
return tal_free(key);
/* Must be terminated */
assert(guide[1+strlen(key)] == ']');
len++;
break;
default:
abort();
}
tal_free(key);
guide += len + 1;
}

return tok;
}

jsmntok_t *json_parse_input(const char *input, int len, bool *valid)
{
jsmn_parser parser;
Expand Down Expand Up @@ -382,11 +344,7 @@ void json_add_num(struct json_result *result, const char *fieldname, unsigned in
json_start_member(result, fieldname);
result_append_fmt(result, "%u", value);
}
void json_add_snum(struct json_result *result, const char *fieldname, int value)
{
json_start_member(result, fieldname);
result_append_fmt(result, "%d", value);
}

void json_add_double(struct json_result *result, const char *fieldname, double value)
{
json_start_member(result, fieldname);
Expand Down Expand Up @@ -422,12 +380,6 @@ void json_add_bool(struct json_result *result, const char *fieldname, bool value
result_append(result, value ? "true" : "false");
}

void json_add_null(struct json_result *result, const char *fieldname)
{
json_start_member(result, fieldname);
result_append(result, "null");
}

void json_add_hex(struct json_result *result, const char *fieldname,
const void *data, size_t len)
{
Expand Down
Loading

0 comments on commit 6269a4c

Please sign in to comment.