Remove unused functions not covered by unit tests

This commit is contained in:
practicalswift 2018-03-26 21:37:35 +02:00 committed by Rusty Russell
parent b914062465
commit 6269a4c55d
19 changed files with 1 additions and 357 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
@ -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;
@ -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);

View File

@ -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);

View File

@ -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)
@ -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

View File

@ -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);
@ -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,

View File

@ -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)
{

View File

@ -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);

View File

@ -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)

View File

@ -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);
@ -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);
}

View File

@ -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 */

View File

@ -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;
@ -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);
@ -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)
{

View File

@ -55,11 +55,6 @@ const jsmntok_t *json_get_member(const char *buffer, const jsmntok_t tok[],
/* Get index'th array member. */
const jsmntok_t *json_get_arr(const jsmntok_t tok[], size_t index);
/* Guide is a string with . for members, [] around indexes. */
const jsmntok_t *json_delve(const char *buffer,
const jsmntok_t *tok,
const char *guide);
/* If input is complete and valid, return tokens. */
jsmntok_t *json_parse_input(const char *input, int len, bool *valid);
@ -91,9 +86,6 @@ void json_add_escaped_string(struct json_result *result,
void json_add_literal(struct json_result *result, const char *fieldname,
const char *literal, int len);
/* '"fieldname" : value' or 'value' if fieldname is NULL */
void json_add_snum(struct json_result *result, const char *fieldname,
int value);
/* '"fieldname" : value' or 'value' if fieldname is NULL */
void json_add_double(struct json_result *result, const char *fieldname,
double value);
/* '"fieldname" : value' or 'value' if fieldname is NULL */
@ -105,8 +97,6 @@ void json_add_u64(struct json_result *result, const char *fieldname,
/* '"fieldname" : true|false' or 'true|false' if fieldname is NULL */
void json_add_bool(struct json_result *result, const char *fieldname,
bool value);
/* '"fieldname" : null' or 'null' if fieldname is NULL */
void json_add_null(struct json_result *result, const char *fieldname);
/* '"fieldname" : "0189abcdef..."' or "0189abcdef..." if fieldname is NULL */
void json_add_hex(struct json_result *result, const char *fieldname,
const void *data, size_t len);

View File

@ -80,24 +80,3 @@ void opt_show_time(char buf[OPT_SHOW_LEN], const struct timerel *t)
} else
sprintf(buf, "%lus", t->ts.tv_sec);
}
char *opt_set_timeabs(const char *arg, struct timeabs *t)
{
long double d;
assert(arg != NULL);
if (sscanf(arg, "%Lf", &d) != 1)
return tal_fmt(NULL, "'%s' is not a time", arg);
t->ts.tv_sec = d;
t->ts.tv_nsec = (d - t->ts.tv_sec) * 1000000000;
return NULL;
}
void opt_show_timeabs(char buf[OPT_SHOW_LEN], const struct timeabs *t)
{
long double d = t->ts.tv_sec;
d = d * 1000000000 + t->ts.tv_nsec;
sprintf(buf, "%.9Lf", d);
}

View File

@ -7,7 +7,4 @@
char *opt_set_time(const char *arg, struct timerel *t);
void opt_show_time(char buf[OPT_SHOW_LEN], const struct timerel *t);
char *opt_set_timeabs(const char *arg, struct timeabs *t);
void opt_show_timeabs(char buf[OPT_SHOW_LEN], const struct timeabs *t);
#endif /* LIGHTNING_LIGHTNINGD_OPT_TIME_H */

View File

@ -522,29 +522,6 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
return peer;
}
bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
struct peer *peer)
{
bool ok;
sqlite3_stmt *stmt = db_prepare(w->db, "SELECT id, node_id, address FROM peers WHERE node_id=?;");
sqlite3_bind_pubkey(stmt, 1, nodeid);
ok = stmt != NULL && sqlite3_step(stmt) == SQLITE_ROW;
if (ok) {
peer->dbid = sqlite3_column_int64(stmt, 0);
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
const unsigned char *addrstr = sqlite3_column_text(stmt, 2);
if (addrstr)
parse_wireaddr((const char*)addrstr, &peer->addr, DEFAULT_PORT, NULL);
} else {
/* Make sure we mark this as a new peer */
peer->dbid = 0;
}
sqlite3_finalize(stmt);
return ok;
}
static secp256k1_ecdsa_signature *
wallet_htlc_sigs_load(const tal_t *ctx, struct wallet *w, u64 channelid)
{
@ -1718,26 +1695,6 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
return payment;
}
struct secret *wallet_payment_get_secrets(const tal_t *ctx,
struct wallet *wallet,
const struct sha256 *payment_hash)
{
sqlite3_stmt *stmt;
struct secret *path_secrets = NULL;
stmt = db_prepare(wallet->db,
"SELECT path_secrets "
"FROM payments "
"WHERE payment_hash = ?");
sqlite3_bind_sha256(stmt, 1, payment_hash);
if (sqlite3_step(stmt) == SQLITE_ROW) {
path_secrets = sqlite3_column_secrets(ctx, stmt, 0);
}
sqlite3_finalize(stmt);
return path_secrets;
}
void wallet_payment_set_status(struct wallet *wallet,
const struct sha256 *payment_hash,
const enum wallet_payment_status newstatus,

View File

@ -271,19 +271,6 @@ void wallet_peer_delete(struct wallet *w, u64 peer_dbid);
bool wallet_channel_config_load(struct wallet *w, const u64 id,
struct channel_config *cc);
/**
* wallet_peer_by_nodeid -- Given a node_id/pubkey, load the peer from DB
*
* @w: the wallet to load from
* @nodeid: the node_id to search for
* @peer(out): the destination where to store the peer
*
* Returns true on success, or false if we were unable to find a peer
* with the given node_id.
*/
bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
struct peer *peer);
/**
* wlalet_channels_load_active -- Load persisted active channels into the peers
*
@ -732,15 +719,6 @@ void wallet_payment_set_status(struct wallet *wallet,
const enum wallet_payment_status newstatus,
const struct preimage *preimage);
/**
* wallet_payment_get_secrets - Get the secrets array for a given `payment_hash`
*
* Returns a tal_array: can return NULL for old dbs.
*/
struct secret *wallet_payment_get_secrets(const tal_t *ctx,
struct wallet *wallet,
const struct sha256 *payment_hash);
/**
* wallet_payment_get_failinfo - Get failure information for a given
* `payment_hash`.

View File

@ -63,12 +63,6 @@ bool is_msg_for_gossipd(const u8 *cursor)
return false;
}
/* Return true if it's an unknown message. cursor is a tal ptr. */
bool is_unknown_msg(const u8 *cursor)
{
return unknown_type(fromwire_peektype(cursor));
}
/* Return true if it's an unknown ODD message. cursor is a tal ptr. */
bool is_unknown_msg_discardable(const u8 *cursor)
{

View File

@ -12,8 +12,6 @@
* that type is even.
*/
/* Return true if it's an unknown message. cursor is a tal ptr. */
bool is_unknown_msg(const u8 *cursor);
/* Return true if it's an unknown ODD message. cursor is a tal ptr. */
bool is_unknown_msg_discardable(const u8 *cursor);
/* Return true if it's a message for gossipd. */