Skip to content

Commit 1cb147c

Browse files
committed
Version number, name, and build details.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 6883d28 commit 1cb147c

25 files changed

+74
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ TAGS
88
ccan/tools/configurator/configurator
99
libsecp256k1.a
1010
libsecp256k1.la
11+
gen_*

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#! /usr/bin/make
2+
NAME=MtGox's Cold Wallet
23

34
# Needs to have oneof support: Ubuntu vivid's is too old :(
45
PROTOCC:=protoc-c
@@ -12,11 +13,11 @@ PROGRAMS := test-cli/open-channel test-cli/create-anchor-tx test-cli/open-commit
1213

1314
BITCOIN_OBJS := bitcoin/address.o bitcoin/base58.o bitcoin/pubkey.o bitcoin/script.o bitcoin/shadouble.o bitcoin/signature.o bitcoin/tx.o
1415

15-
HELPER_OBJS := lightning.pb-c.o pkt.o permute_tx.o commit_tx.o opt_bits.o close_tx.o find_p2sh_out.o protobuf_convert.o funding.o test-cli/gather_updates.o
16+
HELPER_OBJS := lightning.pb-c.o pkt.o permute_tx.o commit_tx.o opt_bits.o close_tx.o find_p2sh_out.o protobuf_convert.o funding.o test-cli/gather_updates.o version.o
1617

1718
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 ccan-crypto-ripemd160.o
1819

19-
HEADERS := $(wildcard *.h) $(wildcard bitcoin/*.h)
20+
HEADERS := $(filter-out gen_*, $(wildcard *.h)) $(wildcard bitcoin/*.h)
2021

2122
CCANDIR := ccan/
2223
CFLAGS := -g -Wall -I $(CCANDIR) -I secp256k1/include/ -DVALGRIND_HEADERS=1 $(FEATURES)
@@ -52,6 +53,12 @@ doc/deployable-lightning.pdf: doc/deployable-lightning.lyx doc/bitcoin.bib
5253
doc/deployable-lightning.tex: doc/deployable-lightning.lyx
5354
lyx -E latex $@ $<
5455

56+
gen_version.h: FORCE
57+
@(echo "#define VERSION \"`git describe --always --dirty`\"" && echo "#define VERSION_NAME \"$(NAME)\"" && echo "#define BUILD_FEATURES \"$(FEATURES)\"") > $@.new
58+
@if cmp $@.new $@ >/dev/null 2>&2; then rm -f $@.new; else mv $@.new $@; fi
59+
60+
version.o: gen_version.h
61+
5562
update-ccan:
5663
mv ccan ccan.old
5764
DIR=$$(pwd)/ccan; cd ../ccan && ./tools/create-ccan-tree -a $$DIR `cd $$DIR.old/ccan && find * -name _info | sed s,/_info,, | sort` $(CCAN_NEW)
@@ -63,7 +70,7 @@ update-ccan:
6370
$(RM) -r ccan.old
6471

6572
distclean: clean
66-
$(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h
73+
$(RM) lightning.pb-c.c lightning.pb-c.h ccan/config.h gen_version.h
6774
$(RM) doc/deployable-lightning.pdf
6875

6976
clean:

test-cli/check-commit-sig.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bitcoin/privkey.h"
1616
#include "protobuf_convert.h"
1717
#include "funding.h"
18+
#include "version.h"
1819
#include <unistd.h>
1920

2021
int main(int argc, char *argv[])
@@ -37,6 +38,7 @@ int main(int argc, char *argv[])
3738
"<open-channel-file1> <open-channel-file2> <open-anchor-file1> <commit-key1> [<commit-sig>]\n"
3839
"Check the commit sig is valid (either in open-anchor or commit-sig packet)",
3940
"Print this message.");
41+
opt_register_version();
4042

4143
opt_parse(&argc, argv, opt_log_stderr_exit);
4244

test-cli/close-channel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "protobuf_convert.h"
2121
#include "gather_updates.h"
2222
#include "opt_bits.h"
23+
#include "version.h"
2324
#include <unistd.h>
2425

2526
int main(int argc, char *argv[])
@@ -50,6 +51,7 @@ int main(int argc, char *argv[])
5051
opt_register_arg("--close-fee=<bits>",
5152
opt_set_bits, opt_show_bits, &close_fee,
5253
"100's of satoshi to pay for close tx");
54+
opt_register_version();
5355

5456
opt_parse(&argc, argv, opt_log_stderr_exit);
5557

test-cli/create-anchor-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <unistd.h>
1919
#include <time.h>
2020
#include "opt_bits.h"
21+
#include "version.h"
2122

2223
/* Bitcoin nodes are allowed to be 2 hours in the future. */
2324
#define LOCKTIME_MIN (2 * 60 * 60)
@@ -92,6 +93,7 @@ int main(int argc, char *argv[])
9293
opt_register_arg("--anchor-fee=<bits>",
9394
opt_set_bits, opt_show_bits, &anchor_fee,
9495
"100's of satoshi to pay for anchor");
96+
opt_register_version();
9597

9698
opt_parse(&argc, argv, opt_log_stderr_exit);
9799

test-cli/create-close-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "protobuf_convert.h"
1717
#include "gather_updates.h"
1818
#include "funding.h"
19+
#include "version.h"
1920
#include <unistd.h>
2021

2122
int main(int argc, char *argv[])
@@ -38,6 +39,7 @@ int main(int argc, char *argv[])
3839
"<open-channel-file1> <open-channel-file2> <open-anchor-file> <close-protobuf> <close-complete-protobuf> [update-protobuf]...\n"
3940
"Create the close transaction from the signatures",
4041
"Print this message.");
42+
opt_register_version();
4143

4244
opt_parse(&argc, argv, opt_log_stderr_exit);
4345

test-cli/create-commit-spend-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "protobuf_convert.h"
2121
#include "test-cli/gather_updates.h"
2222
#include "funding.h"
23+
#include "version.h"
2324
#include <unistd.h>
2425

2526
int main(int argc, char *argv[])
@@ -49,6 +50,7 @@ int main(int argc, char *argv[])
4950
opt_register_arg("--fee=<bits>",
5051
opt_set_bits, opt_show_bits, &fee,
5152
"100's of satoshi to pay in transaction fee");
53+
opt_register_version();
5254

5355
opt_parse(&argc, argv, opt_log_stderr_exit);
5456

test-cli/create-commit-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "protobuf_convert.h"
1818
#include "gather_updates.h"
1919
#include "funding.h"
20+
#include "version.h"
2021
#include <unistd.h>
2122

2223
/* FIXME: this code doesn't work if we're not the ones proposing the delta */
@@ -40,6 +41,7 @@ int main(int argc, char *argv[])
4041
"<open-channel-file1> <open-channel-file2> <open-anchor-file> <commit-privkey> [<updates>]\n"
4142
"Create the signature needed for the commit transaction",
4243
"Print this message.");
44+
opt_register_version();
4345

4446
opt_parse(&argc, argv, opt_log_stderr_exit);
4547

test-cli/create-htlc-spend-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "bitcoin/privkey.h"
1717
#include "protobuf_convert.h"
1818
#include "find_p2sh_out.h"
19+
#include "version.h"
1920
#include <unistd.h>
2021

2122
int main(int argc, char *argv[])
@@ -48,6 +49,7 @@ int main(int argc, char *argv[])
4849
"Create a transaction which spends commit-tx's htlc output, and sends it P2SH to outpubkey\n"
4950
"It relies on timeout, unless --rvalue or --commit-preimage is specified",
5051
"Print this message.");
52+
opt_register_version();
5153

5254
opt_parse(&argc, argv, opt_log_stderr_exit);
5355

test-cli/create-steal-tx.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "bitcoin/pubkey.h"
1515
#include "bitcoin/privkey.h"
1616
#include "protobuf_convert.h"
17+
#include "version.h"
1718
#include <unistd.h>
1819

1920
int main(int argc, char *argv[])
@@ -37,6 +38,7 @@ int main(int argc, char *argv[])
3738
"<commit-tx> <revocation-preimage> <final-privkey> <open-channel-file1> <open-channel-file2> <outpubkey>\n"
3839
"Create a transaction which spends commit-tx's revocable output, and sends it P2SH to outpubkey",
3940
"Print this message.");
41+
opt_register_version();
4042

4143
opt_parse(&argc, argv, opt_log_stderr_exit);
4244

test-cli/get-anchor-depth.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "bitcoin/signature.h"
1313
#include "commit_tx.h"
1414
#include "bitcoin/pubkey.h"
15+
#include "version.h"
1516
#include <unistd.h>
1617

1718
int main(int argc, char *argv[])
@@ -25,6 +26,7 @@ int main(int argc, char *argv[])
2526
"<open-channel-file>\n"
2627
"Prints anchor depth as contained in OpenChannel message",
2728
"Print this message.");
29+
opt_register_version();
2830

2931
opt_parse(&argc, argv, opt_log_stderr_exit);
3032

test-cli/leak-anchor-sigs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ int main(int argc, char *argv[])
1818
"<open-anchor-sig-file>\n"
1919
"Create LeakAnchorSigsAndPretendWeDidnt to stdout",
2020
"Print this message.");
21+
opt_register_version();
2122

2223
opt_parse(&argc, argv, opt_log_stderr_exit);
2324

test-cli/open-anchor.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <unistd.h>
2222
#include <time.h>
2323
#include "opt_bits.h"
24+
#include "version.h"
2425

2526
int main(int argc, char *argv[])
2627
{
@@ -44,6 +45,7 @@ int main(int argc, char *argv[])
4445
"<open-channel-file1> <open-channel-file2> <anchor-tx-file> <commit-privkey1>\n"
4546
"A test program to output open_anchor message on stdout.",
4647
"Print this message.");
48+
opt_register_version();
4749

4850
opt_parse(&argc, argv, opt_log_stderr_exit);
4951

test-cli/open-channel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <unistd.h>
1919
#include <time.h>
2020
#include "opt_bits.h"
21+
#include "version.h"
2122

2223
/* Bitcoin nodes are allowed to be 2 hours in the future. */
2324
#define LOCKTIME_MIN (2 * 60 * 60)
@@ -58,6 +59,7 @@ int main(int argc, char *argv[])
5859
opt_register_arg("--commitment-fee=<bits>",
5960
opt_set_bits, opt_show_bits, &commit_tx_fee,
6061
"100's of satoshi to pay for commitment");
62+
opt_register_version();
6163

6264
opt_parse(&argc, argv, opt_log_stderr_exit);
6365

test-cli/open-commit-sig.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "bitcoin/privkey.h"
1717
#include "protobuf_convert.h"
1818
#include "funding.h"
19+
#include "version.h"
1920
#include <unistd.h>
2021

2122
int main(int argc, char *argv[])
@@ -39,6 +40,7 @@ int main(int argc, char *argv[])
3940
"<open-channel-file1> <open-channel-file2> <open-anchor-file1> <commit-privkey>\n"
4041
"Create the signature needed for the commit transaction",
4142
"Print this message.");
43+
opt_register_version();
4244

4345
opt_parse(&argc, argv, opt_log_stderr_exit);
4446

test-cli/txid-of.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <ccan/str/hex/hex.h>
77
#include <ccan/err/err.h>
88
#include "bitcoin/tx.h"
9+
#include "version.h"
910
#include <unistd.h>
1011

1112
int main(int argc, char *argv[])
@@ -22,6 +23,7 @@ int main(int argc, char *argv[])
2223
"<tx>\n"
2324
"Print txid of the transaction in the file",
2425
"Print this message.");
26+
opt_register_version();
2527

2628
opt_parse(&argc, argv, opt_log_stderr_exit);
2729

test-cli/update-channel-accept.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "protobuf_convert.h"
1919
#include "gather_updates.h"
2020
#include "funding.h"
21+
#include "version.h"
2122
#include <unistd.h>
2223

2324
int main(int argc, char *argv[])
@@ -42,6 +43,7 @@ int main(int argc, char *argv[])
4243
"<seed> <open-channel-file1> <open-channel-file2> <open-anchor-file> <commit-privkey> <all-updates...>\n"
4344
"Accept a new update message",
4445
"Print this message.");
46+
opt_register_version();
4547

4648
opt_parse(&argc, argv, opt_log_stderr_exit);
4749

test-cli/update-channel-complete.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "protobuf_convert.h"
1919
#include "gather_updates.h"
2020
#include "funding.h"
21+
#include "version.h"
2122
#include <unistd.h>
2223

2324
int main(int argc, char *argv[])
@@ -40,6 +41,7 @@ int main(int argc, char *argv[])
4041
"<seed> <open-channel-file1> <open-channel-file2> <open-anchor-file> <all-previous-updates>\n"
4142
"Create a new update-complete message",
4243
"Print this message.");
44+
opt_register_version();
4345

4446
opt_parse(&argc, argv, opt_log_stderr_exit);
4547

test-cli/update-channel-htlc-complete.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "commit_tx.h"
1515
#include "bitcoin/pubkey.h"
1616
#include "find_p2sh_out.h"
17+
#include "version.h"
1718
#include <unistd.h>
1819

1920
int main(int argc, char *argv[])
@@ -29,6 +30,7 @@ int main(int argc, char *argv[])
2930
"<seed> <update-number> <r-value>\n"
3031
"Create a new HTLC complete message",
3132
"Print this message.");
33+
opt_register_version();
3234

3335
opt_parse(&argc, argv, opt_log_stderr_exit);
3436

test-cli/update-channel-htlc-remove.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "bitcoin/pubkey.h"
1616
#include "find_p2sh_out.h"
1717
#include "protobuf_convert.h"
18+
#include "version.h"
1819
#include <unistd.h>
1920

2021
int main(int argc, char *argv[])
@@ -31,6 +32,7 @@ int main(int argc, char *argv[])
3132
"<seed> <update-number> <update-pkt>\n"
3233
"Create a new HTLC remove message",
3334
"Print this message.");
35+
opt_register_version();
3436

3537
opt_parse(&argc, argv, opt_log_stderr_exit);
3638

test-cli/update-channel-htlc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "commit_tx.h"
1515
#include "bitcoin/pubkey.h"
1616
#include "find_p2sh_out.h"
17+
#include "version.h"
1718
#include <unistd.h>
1819

1920
int main(int argc, char *argv[])
@@ -32,6 +33,7 @@ int main(int argc, char *argv[])
3233
"<seed> <update-number> <satoshi> <r-value> <abs-locktime-seconds>\n"
3334
"Create a new HTLC update message",
3435
"Print this message.");
36+
opt_register_version();
3537

3638
opt_parse(&argc, argv, opt_log_stderr_exit);
3739

test-cli/update-channel-signature.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "protobuf_convert.h"
1919
#include "gather_updates.h"
2020
#include "funding.h"
21+
#include "version.h"
2122
#include <unistd.h>
2223

2324
int main(int argc, char *argv[])
@@ -42,6 +43,7 @@ int main(int argc, char *argv[])
4243
"<seed> <open-channel-file1> <open-channel-file2> <open-anchor-file> <commit-privkey> <all-previous-updates>...\n"
4344
"Create a new update-channel-signature message",
4445
"Print this message.");
46+
opt_register_version();
4547

4648
opt_parse(&argc, argv, opt_log_stderr_exit);
4749

test-cli/update-channel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "commit_tx.h"
1515
#include "bitcoin/pubkey.h"
1616
#include "find_p2sh_out.h"
17+
#include "version.h"
1718
#include <unistd.h>
1819

1920
int main(int argc, char *argv[])
@@ -37,6 +38,7 @@ int main(int argc, char *argv[])
3738
opt_register_arg("--from-them=<satoshi>",
3839
opt_set_ulonglongval_si, NULL, &from_them,
3940
"Amount to pay us (must use this or --to-them)");
41+
opt_register_version();
4042

4143
opt_parse(&argc, argv, opt_log_stderr_exit);
4244

version.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "version.h"
2+
#include "gen_version.h"
3+
#include <stdio.h>
4+
5+
char *version_and_exit(const void *unused)
6+
{
7+
printf("%s\n"
8+
"aka. %s\n"
9+
"Built with: %s\n", VERSION, VERSION_NAME, BUILD_FEATURES);
10+
exit(0);
11+
}

version.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef LIGHTNING_VERSION_H
2+
#define LIGHTNING_VERSION_H
3+
#include <ccan/opt/opt.h>
4+
5+
char *version_and_exit(const void *unused);
6+
7+
#define opt_register_version() \
8+
opt_register_noarg("--version|-V", version_and_exit, NULL, \
9+
"print version to standard output and exit")
10+
11+
#endif /* LIGHTNING_VERSION_H */

0 commit comments

Comments
 (0)