From fc8552318a392a385841441cbc3ac174fe94563c Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 7 Jun 2015 13:51:09 +0930 Subject: [PATCH] opt_bits: parsing routines for 'bits' == 100 satoshi. Also fix open-channel usage message. Signed-off-by: Rusty Russell --- Makefile | 2 +- open-channel.c | 21 ++------------------- opt_bits.c | 20 ++++++++++++++++++++ opt_bits.h | 9 +++++++++ 4 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 opt_bits.c create mode 100644 opt_bits.h diff --git a/Makefile b/Makefile index fc3159b76..56f8473c8 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ PROTOCC:=protoc-c PROGRAMS := open-channel open-anchor-scriptsigs leak-anchor-sigs open-commit-sig check-commit-sig check-anchor-scriptsigs get-anchor-depth create-steal-tx -HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o permute_tx.o signature.o bitcoin_tx.o bitcoin_address.o anchor.o commit_tx.o pubkey.o +HELPER_OBJS := base58.o lightning.pb-c.o shadouble.o pkt.o bitcoin_script.o permute_tx.o signature.o bitcoin_tx.o bitcoin_address.o anchor.o commit_tx.o pubkey.o opt_bits.o CCAN_OBJS := ccan-crypto-sha256.o ccan-crypto-shachain.o ccan-err.o ccan-tal.o ccan-tal-str.o ccan-take.o ccan-list.o ccan-str.o ccan-opt-helpers.o ccan-opt.o ccan-opt-parse.o ccan-opt-usage.o ccan-read_write_all.o ccan-str-hex.o ccan-tal-grab_file.o ccan-noerr.o diff --git a/open-channel.c b/open-channel.c index 910b606ce..5d47fb1a4 100644 --- a/open-channel.c +++ b/open-channel.c @@ -19,28 +19,11 @@ #include "shadouble.h" #include #include +#include "opt_bits.h" /* Bitcoin nodes are allowed to be 2 hours in the future. */ #define LOCKTIME_MIN (2 * 60 * 60) -static char *opt_set_bits(const char *arg, u64 *satoshi) -{ - unsigned long long ll; - char *ret = opt_set_ulonglongval_si(arg, &ll); - if (ret) - return ret; - *satoshi = ll * 100; - if (*satoshi / 100 != ll) - return "Invalid number of bits"; - return NULL; -} - -static void opt_show_bits(char buf[OPT_SHOW_LEN], const u64 *bits) -{ - unsigned long long ll = *bits / 100; - opt_show_ulonglongval_si(buf, &ll); -} - static BitcoinInput *parse_anchor_input(const tal_t *ctx, const char *spec) { BitcoinInput *in = tal(ctx, BitcoinInput); @@ -110,7 +93,7 @@ int main(int argc, char *argv[]) locktime_seconds = LOCKTIME_MIN + 24 * 60 * 60; opt_register_noarg("--help|-h", opt_usage_and_exit, - " ///...\n" + " ///...\n" "A test program to output openchannel on stdout.", "Print this message."); opt_register_arg("--min-anchor-confirms", diff --git a/opt_bits.c b/opt_bits.c new file mode 100644 index 000000000..3ed397049 --- /dev/null +++ b/opt_bits.c @@ -0,0 +1,20 @@ +#include "opt_bits.h" + +char *opt_set_bits(const char *arg, u64 *satoshi) +{ + unsigned long long ll; + char *ret = opt_set_ulonglongval_si(arg, &ll); + if (ret) + return ret; + *satoshi = ll * 100; + if (*satoshi / 100 != ll) + return "Invalid number of bits"; + return NULL; +} + +void opt_show_bits(char buf[OPT_SHOW_LEN], const u64 *bits) +{ + unsigned long long ll = *bits / 100; + opt_show_ulonglongval_si(buf, &ll); +} + diff --git a/opt_bits.h b/opt_bits.h new file mode 100644 index 000000000..0e4e45e1e --- /dev/null +++ b/opt_bits.h @@ -0,0 +1,9 @@ +#ifndef LIGHTNING_OPT_BITS_H +#define LIGHTNING_OPT_BITS_H +#include +#include + +char *opt_set_bits(const char *arg, u64 *satoshi); +void opt_show_bits(char buf[OPT_SHOW_LEN], const u64 *bits); + +#endif /* LIGHTNING_OPT_BITS_H */