From f4e94147a7281ec05e078ff9f3e6d65893417bad Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 24 Apr 2016 20:09:39 +0930 Subject: [PATCH] Remove unused script functions now we use witness. Signed-off-by: Rusty Russell --- bitcoin/script.c | 46 ---------------------------------------------- bitcoin/script.h | 14 -------------- bitcoin/tx.c | 15 --------------- bitcoin/tx.h | 7 ------- find_p2sh_out.c | 11 ----------- find_p2sh_out.h | 7 +------ 6 files changed, 1 insertion(+), 99 deletions(-) diff --git a/bitcoin/script.c b/bitcoin/script.c index 77fc52a1f..eced41e44 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -152,13 +152,6 @@ static u8 *stack_number(const tal_t *ctx, unsigned int num) return tal_dup_arr(ctx, u8, &val, 1, 0); } -static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig) -{ - u8 *der = stack_sig(*scriptp, sig); - add_push_bytes(scriptp, der, tal_count(der)); - tal_free(der); -} - /* FIXME: permute? */ /* Is a < b? (If equal we don't care) */ static bool key_less(const struct pubkey *a, const struct pubkey *b) @@ -420,30 +413,6 @@ u8 *p2wpkh_scriptcode(const tal_t *ctx, const struct pubkey *key) return script; } -u8 *scriptsig_p2sh_2of2(const tal_t *ctx, - const struct bitcoin_signature *sig1, - const struct bitcoin_signature *sig2, - const struct pubkey *key1, - const struct pubkey *key2) -{ - u8 *script = tal_arr(ctx, u8, 0); - u8 *redeemscript; - - /* OP_CHECKMULTISIG has an out-by-one bug, which MBZ */ - add_number(&script, 0); - /* sig order should match key order. */ - if (key_less(key1, key2)) { - add_push_sig(&script, sig1); - add_push_sig(&script, sig2); - } else { - add_push_sig(&script, sig2); - add_push_sig(&script, sig1); - } - redeemscript = bitcoin_redeem_2of2(script, key1, key2); - add_push_bytes(&script, redeemscript, tal_count(redeemscript)); - return script; -} - bool is_p2sh(const u8 *script, size_t script_len) { if (script_len != 23) @@ -493,21 +462,6 @@ u8 *bitcoin_redeem_secret_or_delay(const tal_t *ctx, return script; } -u8 *scriptsig_p2sh_secret(const tal_t *ctx, - const void *secret, size_t secret_len, - const struct bitcoin_signature *sig, - const u8 *redeemscript, - size_t redeem_len) -{ - u8 *script = tal_arr(ctx, u8, 0); - - add_push_sig(&script, sig); - add_push_bytes(&script, secret, secret_len); - add_push_bytes(&script, redeemscript, redeem_len); - - return script; -} - u8 **bitcoin_witness_secret(const tal_t *ctx, const void *secret, size_t secret_len, const struct bitcoin_signature *sig, diff --git a/bitcoin/script.h b/bitcoin/script.h index bc0f07ce8..6a918610b 100644 --- a/bitcoin/script.h +++ b/bitcoin/script.h @@ -86,20 +86,6 @@ u8 **bitcoin_witness_secret(const tal_t *ctx, const struct bitcoin_signature *sig, const u8 *witnessscript); -/* Create an input script to accept pay to pubkey */ -u8 *scriptsig_p2sh_2of2(const tal_t *ctx, - const struct bitcoin_signature *sig1, - const struct bitcoin_signature *sig2, - const struct pubkey *key1, - const struct pubkey *key2); - -/* Create an input script to solve by secret */ -u8 *scriptsig_p2sh_secret(const tal_t *ctx, - const void *secret, size_t secret_len, - const struct bitcoin_signature *sig, - const u8 *redeemscript, - size_t redeem_len); - /* Is this a pay to script hash? */ bool is_p2sh(const u8 *script, size_t script_len); diff --git a/bitcoin/tx.c b/bitcoin/tx.c index e7540d648..dffc5e039 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -293,26 +293,11 @@ u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx) return arr; } -u8 *linearize_tx_force_extended(const tal_t *ctx, - const struct bitcoin_tx *tx) -{ - u8 *arr = tal_arr(ctx, u8, 0); - add_tx(tx, add_linearize, &arr, true); - return arr; -} - static void add_measure(const void *data, size_t len, void *lenp) { *(size_t *)lenp += len; } -size_t measure_tx_len(const struct bitcoin_tx *tx) -{ - size_t len = 0; - add_tx(tx, add_measure, &len, uses_witness(tx)); - return len; -} - size_t measure_tx_cost(const struct bitcoin_tx *tx) { size_t non_witness_len = 0, witness_len = 0; diff --git a/bitcoin/tx.h b/bitcoin/tx.h index 798df29d2..858885965 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -49,13 +49,6 @@ void sha256_tx_for_sig(struct sha256_double *h, const struct bitcoin_tx *tx, /* Linear bytes of tx. */ u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx); -/* Force linearization in extended form; useful if 0 inputs. */ -u8 *linearize_tx_force_extended(const tal_t *ctx, - const struct bitcoin_tx *tx); - -/* Get length of tx in bytes. */ -size_t measure_tx_len(const struct bitcoin_tx *tx); - /* Get cost of tx in (x4 of non-witness bytecount). */ size_t measure_tx_cost(const struct bitcoin_tx *tx); diff --git a/find_p2sh_out.c b/find_p2sh_out.c index 1068a81ec..f03f04843 100644 --- a/find_p2sh_out.c +++ b/find_p2sh_out.c @@ -21,17 +21,6 @@ static u32 find_output(const struct bitcoin_tx *tx, const u8 *scriptpubkey) return i; } -u32 find_p2sh_out(const struct bitcoin_tx *tx, const u8 *redeemscript) -{ - /* This is the scriptPubKey commit tx will have */ - u8 *p2sh = scriptpubkey_p2sh(NULL, redeemscript); - u32 i; - - i = find_output(tx, p2sh); - tal_free(p2sh); - return i; -} - u32 find_p2wsh_out(const struct bitcoin_tx *tx, const u8 *witnessscript) { /* This is the scriptPubKey commit tx will have */ diff --git a/find_p2sh_out.h b/find_p2sh_out.h index bb7a9e348..04838b4cb 100644 --- a/find_p2sh_out.h +++ b/find_p2sh_out.h @@ -5,11 +5,6 @@ struct bitcoin_tx; -/* Normally we'd simply remember which output of the anchor or commit - * tx is the one which pays to this script. But for these examples, - * we have to figure it out by recreating the output and matching. */ -u32 find_p2sh_out(const struct bitcoin_tx *tx, const u8 *redeemscript); - -/* Similar routine for finding a specific p2wsh output. */ +/* Routine for finding a specific p2wsh output. */ u32 find_p2wsh_out(const struct bitcoin_tx *tx, const u8 *witnessscript); #endif /* LIGHTNING_FIND_P2SH_OUT_H */