From 6750794667c2e6bb4ebbd8e8681f92c72c6b367a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 27 Jan 2016 15:00:50 +1030 Subject: [PATCH] Use #if instead of #ifdef (we already use -Wundef). This avoids embarassing typos in future. Signed-off-by: Rusty Russell --- Makefile | 20 ++++++++++++++++++-- bitcoin/locktime.c | 12 ++++++------ bitcoin/script.c | 6 +++--- bitcoin/signature.c | 10 +++++----- bitcoin/signature.h | 4 ++-- bitcoin/tx.c | 8 ++++---- protobuf_convert.c | 4 ++-- 7 files changed, 40 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 3a8b2f3dc..1ca4f1c69 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,25 @@ PROTOCC:=protoc-c CCANDIR := ccan # Alpha has checksequenceverify, segregated witness+input-amount-in-sig+confidentual-transactions, schnorr, checklocktimeverify -#FEATURES := -DHAS_CSV=1 -DALPHA_TXSTYLE=1 -DUSE_SCHNORR=1 -DHAS_CLTV=1 +ALPHA_FEATURES := \ + -DALPHA_TXSTYLE=1 \ + -DHAS_BIP68=0 \ + -DHAS_CLTV=1 \ + -DHAS_CSV=1 \ + -DSCRIPTS_USE_DER=0 \ + -DUSE_SCHNORR=1 + # Bitcoin uses DER for signatures (Add BIP68 & HAS_CSV if it's supported) -FEATURES := -DSCRIPTS_USE_DER=1 -DHAS_CLTV=1 #-DHAS_CSV=1 -DHAS_BIP68=1 +BITCOIN_FEATURES := \ + -DALPHA_TXSTYLE=0 \ + -DHAS_BIP68=0 \ + -DHAS_CLTV=1 \ + -DHAS_CSV=0 \ + -DSCRIPTS_USE_DER=1 \ + -DUSE_SCHNORR=0 + +#FEATURES := $(ALPHA_FEATURES) +FEATURES := $(BITCOIN_FEATURES) TEST_CLI_PROGRAMS := \ test-cli/check-commit-sig \ diff --git a/bitcoin/locktime.c b/bitcoin/locktime.c index 0331ce20b..05330f64f 100644 --- a/bitcoin/locktime.c +++ b/bitcoin/locktime.c @@ -32,7 +32,7 @@ static bool abs_is_seconds(u32 locktime) bool seconds_to_rel_locktime(u32 seconds, struct rel_locktime *rel) { -#ifdef HAS_BIP68 +#if HAS_BIP68 if ((seconds >> BIP68_SECONDS_SHIFT) > BIP68_LOCKTIME_MASK) return false; rel->locktime = BIP68_SECONDS_FLAG | (seconds >> BIP68_SECONDS_SHIFT); @@ -45,7 +45,7 @@ bool seconds_to_rel_locktime(u32 seconds, struct rel_locktime *rel) bool blocks_to_rel_locktime(u32 blocks, struct rel_locktime *rel) { -#ifdef HAS_BIP68 +#if HAS_BIP68 if (blocks > BIP68_LOCKTIME_MASK) return false; #endif @@ -55,7 +55,7 @@ bool blocks_to_rel_locktime(u32 blocks, struct rel_locktime *rel) bool rel_locktime_is_seconds(const struct rel_locktime *rel) { -#ifdef HAS_BIP68 +#if HAS_BIP68 return rel->locktime & BIP68_SECONDS_FLAG; #else return abs_is_seconds(rel->locktime); @@ -65,7 +65,7 @@ bool rel_locktime_is_seconds(const struct rel_locktime *rel) u32 rel_locktime_to_seconds(const struct rel_locktime *rel) { assert(rel_locktime_is_seconds(rel)); -#ifdef HAS_BIP68 +#if HAS_BIP68 return rel->locktime & BIP68_LOCKTIME_MASK; #else return rel->locktime - SECONDS_POINT; @@ -75,7 +75,7 @@ u32 rel_locktime_to_seconds(const struct rel_locktime *rel) u32 rel_locktime_to_blocks(const struct rel_locktime *rel) { assert(!rel_locktime_is_seconds(rel)); -#ifdef HAS_BIP68 +#if HAS_BIP68 return rel->locktime & BIP68_LOCKTIME_MASK; #else return rel->locktime; @@ -84,7 +84,7 @@ u32 rel_locktime_to_blocks(const struct rel_locktime *rel) u32 bitcoin_nsequence(const struct rel_locktime *rel) { -#ifdef HAS_BIP68 +#if HAS_BIP68 /* 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; diff --git a/bitcoin/script.c b/bitcoin/script.c index e2e591da9..40a7ac6aa 100644 --- a/bitcoin/script.c +++ b/bitcoin/script.c @@ -32,14 +32,14 @@ #define OP_CHECKMULTISIG 0xAE #define OP_HASH160 0xA9 -#ifdef HAS_CSV +#if HAS_CSV #define OP_CHECKSEQUENCEVERIFY 0xB2 #else /* OP_NOP, otherwise bitcoind complains */ #define OP_CHECKSEQUENCEVERIFY 0x61 #endif -#ifdef HAS_CLTV +#if HAS_CLTV #define OP_CHECKLOCKTIMEVERIFY 0xB1 #else /* OP_NOP, otherwise bitcoind complains */ @@ -107,7 +107,7 @@ static void add_push_key(u8 **scriptp, const struct pubkey *key) static void add_push_sig(u8 **scriptp, const struct bitcoin_signature *sig) { /* Bitcoin wants DER encoding. */ -#ifdef SCRIPTS_USE_DER +#if SCRIPTS_USE_DER u8 der[73]; secp256k1_context *secpctx = secp256k1_context_create(0); size_t len = signature_to_der(secpctx, der, &sig->sig); diff --git a/bitcoin/signature.c b/bitcoin/signature.c index b9851a582..50b8e3a86 100644 --- a/bitcoin/signature.c +++ b/bitcoin/signature.c @@ -2,7 +2,7 @@ #include "pubkey.h" #include "script.h" #include "secp256k1.h" -#ifdef USE_SCHNORR +#if USE_SCHNORR #include "secp256k1_schnorr.h" #endif #include "shadouble.h" @@ -83,7 +83,7 @@ void sign_hash(secp256k1_context *secpctx, { bool ok; -#ifdef USE_SCHNORR +#if USE_SCHNORR ok = secp256k1_schnorr_sign(secpctx, s->schnorr, h->sha.u.u8, @@ -148,7 +148,7 @@ bool check_signed_hash(secp256k1_context *secpctx, { int ret; -#ifdef USE_SCHNORR +#if USE_SCHNORR ret = secp256k1_schnorr_verify(secpctx, signature->schnorr, hash->sha.u.u8, &key->pubkey); #else @@ -205,7 +205,7 @@ bool check_2of2_sig(secp256k1_context *secpctx, && check_signed_hash(secpctx, &hash, &sig2->sig, key2); } -#ifndef USE_SCHNORR +#if USE_SCHNORR == 0 /* Stolen direct from bitcoin/src/script/sign.cpp: // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers @@ -294,7 +294,7 @@ size_t signature_to_der(secp256k1_context *secpctx, /* Signature must have low S value. */ bool sig_valid(const struct signature *sig) { -#ifdef USE_SCHNORR +#if USE_SCHNORR return true; #else /* FIXME! Need libsecp support. */ diff --git a/bitcoin/signature.h b/bitcoin/signature.h index 84710c4c9..a06029c65 100644 --- a/bitcoin/signature.h +++ b/bitcoin/signature.h @@ -14,7 +14,7 @@ enum sighash_type { /* ECDSA of double SHA256. */ struct signature { -#ifdef USE_SCHNORR +#if USE_SCHNORR u8 schnorr[64]; #else secp256k1_ecdsa_signature sig; @@ -63,7 +63,7 @@ bool check_2of2_sig(secp256k1_context *secpctx, /* Signature must have low S value. */ bool sig_valid(const struct signature *s); -#ifndef USE_SCHNORR +#if USE_SCHNORR == 0 /* Give DER encoding of signature: returns length used (<= 72). */ size_t signature_to_der(secp256k1_context *secpctx, u8 der[72], const struct signature *s); diff --git a/bitcoin/tx.c b/bitcoin/tx.c index c14995f79..a12630034 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -26,7 +26,7 @@ enum styles { TX_OUTPUT_AMOUNT_HASHPROOF = 64 }; -#ifdef ALPHA_TXSTYLE +#if ALPHA_TXSTYLE /* Linearizing has everything, except input amount (which is implied) */ #define LINEARIZE_STYLE (TX_AMOUNT_CT_STYLE | TX_AMOUNT_INCLUDE_CT | TX_FEE | TX_INPUT_SCRIPTSIG) @@ -253,7 +253,7 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count, tx->input[i].sequence_number = 0xFFFFFFFF; } tx->lock_time = 0; -#ifdef HAS_BIP68 +#if HAS_BIP68 tx->version = 2; #else tx->version = 1; @@ -475,7 +475,7 @@ struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex, goto fail_free_tx; } else { /* Input amounts are compulsory for alpha, to generate sigs */ -#ifdef ALPHA_TXSTYLE +#if ALPHA_TXSTYLE goto fail_free_tx; #endif } @@ -523,7 +523,7 @@ bool bitcoin_txid_to_hex(const struct sha256_double *txid, static bool write_input_amounts(int fd, const struct bitcoin_tx *tx) { /* Alpha required input amounts, so append them */ -#ifdef ALPHA_TXSTYLE +#if ALPHA_TXSTYLE size_t i; for (i = 0; i < tx->input_count; i++) { diff --git a/protobuf_convert.c b/protobuf_convert.c index 577a29fe5..0bc398955 100644 --- a/protobuf_convert.c +++ b/protobuf_convert.c @@ -11,7 +11,7 @@ Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig) assert(sig_valid(sig)); -#ifdef USE_SCHNORR +#if USE_SCHNORR memcpy(&pb->r1, sig->schnorr, 8); memcpy(&pb->r2, sig->schnorr + 8, 8); memcpy(&pb->r3, sig->schnorr + 16, 8); @@ -40,7 +40,7 @@ Signature *signature_to_proto(const tal_t *ctx, const struct signature *sig) bool proto_to_signature(const Signature *pb, struct signature *sig) { /* Kill me again. */ -#ifdef USE_SCHNORR +#if USE_SCHNORR memcpy(sig->schnorr, &pb->r1, 8); memcpy(sig->schnorr + 8, &pb->r2, 8); memcpy(sig->schnorr + 16, &pb->r3, 8);