diff --git a/.gitignore b/.gitignore
index 94e0baf48..7f272cdd6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,7 +16,7 @@ libsodium.la
libwallycore.a
libwallycore.la
gen_*
-daemon/lightning-cli
+lightning-cli/lightning-cli
tools/check-bolt
coverage
ccan/config.h
diff --git a/Makefile b/Makefile
index 9e71d9ac1..e36863bb0 100644
--- a/Makefile
+++ b/Makefile
@@ -189,6 +189,7 @@ include bitcoin/Makefile
include wire/Makefile
include wallet/Makefile
include lightningd/Makefile
+include cli/Makefile
# Git doesn't maintain timestamps, so we only regen if git says we should.
CHANGED_FROM_GIT = [ x"`git log $@ | head -n1`" != x"`git log $< | head -n1`" -o x"`git diff $<`" != x"" ]
@@ -205,7 +206,7 @@ test-protocol: test/test_protocol
check: test-protocol
$(MAKE) pytest
-pytest: daemon/lightning-cli lightningd-all
+pytest: cli/lightning-cli lightningd-all
PYTHONPATH=contrib/pylightning python3 tests/test_lightningd.py -f
# Keep includes in alpha order.
@@ -319,7 +320,7 @@ maintainer-clean: distclean
@echo 'This command is intended for maintainers to use; it'
@echo 'deletes files that may need special tools to rebuild.'
-clean: daemon-clean wire-clean
+clean: wire-clean
$(MAKE) -C secp256k1/ clean || true
$(RM) libsecp256k1.{a,la}
$(RM) libsodium.{a,la}
@@ -331,8 +332,6 @@ clean: daemon-clean wire-clean
find . -name '*gcda' -delete
find . -name '*gcno' -delete
-include daemon/Makefile
-
update-mocks/%: %
@set -e; BASE=/tmp/mocktmp.$$$$.`echo $* | tr / _`; trap "rm -f $$BASE.*" EXIT; \
START=`fgrep -n '/* AUTOGENERATED MOCKS START */' $< | cut -d: -f1`;\
diff --git a/README.md b/README.md
index 627d470bf..07b0b4a22 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ First you need to transfer some funds to `lightningd` so that it can open a chan
```
# Returns an address
-daemon/lightning-cli newaddr
+cli/lightning-cli newaddr
# Returns a transaction id
bitcoin-cli -testnet sendtoaddress
@@ -79,12 +79,12 @@ Once `lightningd` has funds, we can connect to a node and open a channel.
Let's assume the remote node is accepting connections at `:` and has the node ID ``:
```
-daemon/lightning-cli connect
-daemon/lightning-cli fundchannel
+cli/lightning-cli connect
+cli/lightning-cli fundchannel
```
This opens a connection and, on top of that connection, then opens a channel.
-You can check the status of the channel using `daemon/lightning-cli getpeers`.
+You can check the status of the channel using `cli/lightning-cli getpeers`.
The funding transaction needs to confirm in order for the channel to be usable, so wait a few minutes, and once that is complete it `getpeers` should say that the status is in _Normal operation_.
### Receiving and receiving payments
@@ -93,7 +93,7 @@ Payments in Lightning are invoice based.
The recipient creates an invoice with the expected `` in millisatoshi and a ``:
```
-daemon/lightning-cli invoice
+cli/lightning-cli invoice
```
This returns a random value called `rhash` that is part of the invoice.
@@ -103,8 +103,8 @@ The sender needs to compute a route to the recipient, and use that route to actu
The route contains the path that the payment will take throught the Lightning Network and the respective funds that each node will forward.
```
-route=$(daemon/lightning-cli getroute 1 | jq --raw-output .route -)
-daemon/lightning-cli sendpay $route
+route=$(cli/lightning-cli getroute 1 | jq --raw-output .route -)
+cli/lightning-cli sendpay $route
```
Notice that in the first step we stored the route in a variable and reused it in the second step.
@@ -123,4 +123,4 @@ JSON-RPC interface is documented in the following manual pages:
* [getroute](doc/lightning-getroute.7.txt)
* [sendpay](doc/lightning-sendpay.7.txt)
-For simple access to the JSON-RPC interface you can use the `daemon/lightning-cli` tool, or the [python API client](contrib/pylightning).
+For simple access to the JSON-RPC interface you can use the `cli/lightning-cli` tool, or the [python API client](contrib/pylightning).
diff --git a/bitcoin/short_channel_id.c b/bitcoin/short_channel_id.c
index 92e0e4719..d02e0a368 100644
--- a/bitcoin/short_channel_id.c
+++ b/bitcoin/short_channel_id.c
@@ -21,7 +21,7 @@ bool short_channel_id_from_str(const char *str, size_t strlen,
return matches == 3;
}
-char *short_channel_id_to_str(tal_t *ctx, const struct short_channel_id *scid)
+char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid)
{
return tal_fmt(ctx, "%d:%d:%d", scid->blocknum, scid->txnum, scid->outnum);
}
diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h
index cb0118883..ecc2dc250 100644
--- a/bitcoin/short_channel_id.h
+++ b/bitcoin/short_channel_id.h
@@ -23,6 +23,6 @@ bool short_channel_id_from_str(const char *str, size_t strlen,
bool short_channel_id_eq(const struct short_channel_id *a,
const struct short_channel_id *b);
-char *short_channel_id_to_str(tal_t *ctx, const struct short_channel_id *scid);
+char *short_channel_id_to_str(const tal_t *ctx, const struct short_channel_id *scid);
#endif /* LIGHTNING_BITCOIN_SHORT_CHANNEL_ID_H */
diff --git a/cli/Makefile b/cli/Makefile
new file mode 100644
index 000000000..00fb72a08
--- /dev/null
+++ b/cli/Makefile
@@ -0,0 +1,37 @@
+LIGHTNING_CLI_SRC := cli/lightning-cli.c
+LIGHTNING_CLI_OBJS := $(LIGHTNING_CLI_SRC:.c=.o)
+
+JSMN_OBJS := daemon/jsmn.o
+JSMN_HEADERS := daemon/jsmn/jsmn.h
+
+LIGHTNING_CLI_COMMON_OBJS := \
+ common/configdir.o \
+ common/json.o \
+ common/version.o
+
+lightning-cli-all: cli/lightning-cli
+
+$(LIGHTNINGD_OPENING_OBJS): $(LIGHTNINGD_HEADERS)
+
+# Git submodules are seriously broken.
+daemon/jsmn/jsmn.h:
+ git submodule update daemon/jsmn/
+ [ -f $@ ] || git submodule update --init daemon/jsmn/
+
+# If we tell Make that the above builds both, it runs it twice in
+# parallel. So we lie :(
+daemon/jsmn/jsmn.c: daemon/jsmn/jsmn.h
+ [ -f $@ ]
+
+daemon/jsmn.o: daemon/jsmn/jsmn.c
+ $(COMPILE.c) -DJSMN_STRICT=1 $(OUTPUT_OPTION) $<
+
+$(LIGHTNING_CLI_OBJS) $(JSMN_OBJS): $(JSMN_HEADERS) $(COMMON_HEADERS) $(CCAN_HEADERS)
+
+cli/lightning-cli: $(LIGHTNING_CLI_OBJS) $(LIGHTNING_CLI_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
+
+clean: lightning-cli-clean
+
+lightning-cli-clean:
+ $(RM) $(LIGHTNING-CLI_LIB_OBJS) $(DAEMON_JSMN_OBJS)
+
diff --git a/daemon/lightning-cli.c b/cli/lightning-cli.c
similarity index 98%
rename from daemon/lightning-cli.c
rename to cli/lightning-cli.c
index de6cfd6ca..584ba7dae 100644
--- a/daemon/lightning-cli.c
+++ b/cli/lightning-cli.c
@@ -1,14 +1,14 @@
/*
* Helper to submit via JSON-RPC and get back response.
*/
-#include "configdir.h"
-#include "json.h"
-#include "version.h"
#include
#include
#include
#include
#include
+#include
+#include
+#include
#include
#include
#include
diff --git a/common/Makefile b/common/Makefile
index 7d0b27634..c40cb91fb 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -1,26 +1,37 @@
COMMON_SRC := \
common/close_tx.c \
+ common/configdir.c \
common/derive_basepoints.c \
common/funding_tx.c \
common/htlc_tx.c \
+ common/htlc_state.c \
common/initial_channel.c \
common/initial_commit_tx.c \
+ common/json.c \
common/permute_tx.c \
+ common/pseudorand.c \
+ common/timeout.c \
common/type_to_string.c \
common/utils.c \
common/version.c \
common/withdraw_tx.c
-COMMON_HEADERS := $(COMMON_SRC:.c=.h) common/overflows.h
+COMMON_HEADERS_NOGEN := $(COMMON_SRC:.c=.h) common/overflows.h common/htlc.h
+COMMON_HEADERS_GEN := common/gen_htlc_state_names.h
+
+COMMON_HEADERS := $(COMMON_HEADERS_GEN) $(COMMON_HEADERS_NOGEN)
COMMON_OBJS := $(COMMON_SRC:.c=.o)
+common/gen_htlc_state_names.h: common/htlc_state.h ccan/ccan/cdump/tools/cdump-enumstr
+ ccan/ccan/cdump/tools/cdump-enumstr common/htlc_state.h > $@
+
check-makefile: check-common-makefile
check-common-makefile:
- @if [ x"`LC_ALL=C ls common/*.h | grep -v ^gen_`" != x"`echo $(COMMON_HEADERS) | tr ' ' '\n' | LC_ALL=C sort`" ]; then echo COMMON_HEADERS incorrect; exit 1; fi
+ @if [ x"`LC_ALL=C ls common/*.h | grep -v ^common/gen_`" != x"`echo $(COMMON_HEADERS_NOGEN) | tr ' ' '\n' | LC_ALL=C sort`" ]; then echo COMMON_HEADERS_NOGEN incorrect; exit 1; fi
check-source-bolt: $(COMMON_SRC:%=bolt-check/%) $(COMMON_HEADERS:%=bolt-check/%)
check-whitespace: $(COMMON_SRC:%=check-whitespace/%) $(COMMON_HEADERS:%=check-whitespace/%)
check-source: $(COMMON_SRC:%=check-src-include-order/%) \
- $(COMMON_HEADERS:%=check-hdr-include-order/%)
+ $(COMMON_HEADERS_NOGEN:%=check-hdr-include-order/%)
diff --git a/daemon/configdir.c b/common/configdir.c
similarity index 97%
rename from daemon/configdir.c
rename to common/configdir.c
index 8bfa5c973..9345dabfe 100644
--- a/daemon/configdir.c
+++ b/common/configdir.c
@@ -1,5 +1,4 @@
#include "configdir.h"
-#include "log.h"
#include
#include
#include
diff --git a/daemon/configdir.h b/common/configdir.h
similarity index 100%
rename from daemon/configdir.h
rename to common/configdir.h
diff --git a/daemon/htlc.h b/common/htlc.h
similarity index 99%
rename from daemon/htlc.h
rename to common/htlc.h
index 2e7c409d0..5e80b137d 100644
--- a/daemon/htlc.h
+++ b/common/htlc.h
@@ -3,7 +3,6 @@
#include "config.h"
#include "bitcoin/locktime.h"
#include "htlc_state.h"
-#include "pseudorand.h"
#include
#include
#include
diff --git a/daemon/htlc_state.c b/common/htlc_state.c
similarity index 99%
rename from daemon/htlc_state.c
rename to common/htlc_state.c
index 42d3bfbef..9e8c6a3e5 100644
--- a/daemon/htlc_state.c
+++ b/common/htlc_state.c
@@ -1,6 +1,6 @@
-#include "htlc.h"
- #include "gen_htlc_state_names.h"
#include
+#include
+ #include "gen_htlc_state_names.h"
const char *htlc_state_name(enum htlc_state s)
{
diff --git a/daemon/htlc_state.h b/common/htlc_state.h
similarity index 100%
rename from daemon/htlc_state.h
rename to common/htlc_state.h
diff --git a/common/htlc_tx.h b/common/htlc_tx.h
index 3766dfa38..5ebb3aa3a 100644
--- a/common/htlc_tx.h
+++ b/common/htlc_tx.h
@@ -1,7 +1,7 @@
#ifndef LIGHTNING_LIGHTNINGD_HTLC_TX_H
#define LIGHTNING_LIGHTNINGD_HTLC_TX_H
#include "config.h"
-#include
+#include
struct keyset;
struct preimage;
diff --git a/common/initial_channel.h b/common/initial_channel.h
index 886058a86..13526e11e 100644
--- a/common/initial_channel.h
+++ b/common/initial_channel.h
@@ -8,7 +8,7 @@
#include
#include
#include
-#include
+#include
#include
#include
diff --git a/common/initial_commit_tx.h b/common/initial_commit_tx.h
index 75f04cec8..982a3d5aa 100644
--- a/common/initial_commit_tx.h
+++ b/common/initial_commit_tx.h
@@ -3,7 +3,7 @@
#define LIGHTNING_COMMON_INITIAL_COMMIT_TX_H
#include "config.h"
#include
-#include
+#include
#include
struct keyset;
diff --git a/daemon/json.c b/common/json.c
similarity index 89%
rename from daemon/json.c
rename to common/json.c
index cfeec9d78..0995af3ff 100644
--- a/daemon/json.c
+++ b/common/json.c
@@ -1,6 +1,5 @@
/* JSON core and helpers */
#include "json.h"
-#include
#include
#include
#include
@@ -436,43 +435,6 @@ void json_add_hex(struct json_result *result, const char *fieldname,
json_add_string(result, fieldname, hex);
}
-void json_add_pubkey(struct json_result *response,
- const char *fieldname,
- const struct pubkey *key)
-{
- u8 der[PUBKEY_DER_LEN];
-
- pubkey_to_der(der, key);
- json_add_hex(response, fieldname, der, sizeof(der));
-}
-
-void json_add_short_channel_id(struct json_result *response,
- const char *fieldname,
- const struct short_channel_id *id)
-{
- char *str = tal_fmt(response, "%d:%d:%d", id->blocknum, id->txnum, id->outnum);
- json_add_string(response, fieldname, str);
-}
-
-void json_add_address(struct json_result *response, const char *fieldname,
- const struct ipaddr *addr)
-{
- json_object_start(response, fieldname);
- char *addrstr = tal_arr(response, char, INET6_ADDRSTRLEN);
- if (addr->type == ADDR_TYPE_IPV4) {
- inet_ntop(AF_INET, addr->addr, addrstr, INET_ADDRSTRLEN);
- json_add_string(response, "type", "ipv4");
- json_add_string(response, "address", addrstr);
- json_add_num(response, "port", addr->port);
- } else if (addr->type == ADDR_TYPE_IPV6) {
- inet_ntop(AF_INET6, addr->addr, addrstr, INET6_ADDRSTRLEN);
- json_add_string(response, "type", "ipv6");
- json_add_string(response, "address", addrstr);
- json_add_num(response, "port", addr->port);
- }
- json_object_end(response);
-}
-
void json_add_object(struct json_result *result, ...)
{
va_list ap;
diff --git a/daemon/json.h b/common/json.h
similarity index 87%
rename from daemon/json.h
rename to common/json.h
index b8371aff4..3a28fa22a 100644
--- a/daemon/json.h
+++ b/common/json.h
@@ -3,15 +3,16 @@
#include "config.h"
#include
#include
-#include
#include
#include
#include
#define JSMN_STRICT 1
-# include "jsmn/jsmn.h"
+# include "daemon/jsmn/jsmn.h"
+struct ipaddr;
struct json_result;
+struct short_channel_id;
/* Include " if it's a string. */
const char *json_tok_contents(const char *buffer, const jsmntok_t *t);
@@ -102,20 +103,6 @@ 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);
-/* '"fieldname" : "0289abcdef..."' or "0289abcdef..." if fieldname is NULL */
-void json_add_pubkey(struct json_result *response,
- const char *fieldname,
- const struct pubkey *key);
-
-/* '"fieldname" : "1234/5/6"' */
-void json_add_short_channel_id(struct json_result *response,
- const char *fieldname,
- const struct short_channel_id *id);
-
-/* JSON serialize a network address for a node */
-void json_add_address(struct json_result *response, const char *fieldname,
- const struct ipaddr *addr);
-
void json_add_object(struct json_result *result, ...);
const char *json_result_string(const struct json_result *result);
diff --git a/daemon/pseudorand.c b/common/pseudorand.c
similarity index 100%
rename from daemon/pseudorand.c
rename to common/pseudorand.c
diff --git a/daemon/pseudorand.h b/common/pseudorand.h
similarity index 100%
rename from daemon/pseudorand.h
rename to common/pseudorand.h
diff --git a/daemon/timeout.c b/common/timeout.c
similarity index 97%
rename from daemon/timeout.c
rename to common/timeout.c
index b9e438aee..ca1ca636a 100644
--- a/daemon/timeout.c
+++ b/common/timeout.c
@@ -1,4 +1,3 @@
-#include "lightningd.h"
#include "timeout.h"
#include
diff --git a/daemon/timeout.h b/common/timeout.h
similarity index 100%
rename from daemon/timeout.h
rename to common/timeout.h
diff --git a/common/type_to_string.c b/common/type_to_string.c
index 6426084b3..f61da7244 100644
--- a/common/type_to_string.c
+++ b/common/type_to_string.c
@@ -1,10 +1,6 @@
-#include "bitcoin/locktime.h"
-#include "bitcoin/pubkey.h"
-#include "bitcoin/tx.h"
-#include "daemon/htlc.h"
-#include "type_to_string.h"
-#include "utils.h"
#include
+#include
+#include
#include
/* We need at least one, and this is in CCAN so register it here. */
diff --git a/common/type_to_string.h b/common/type_to_string.h
index d72a71664..c2d5989db 100644
--- a/common/type_to_string.h
+++ b/common/type_to_string.h
@@ -3,6 +3,7 @@
#include "config.h"
#include "utils.h"
#include
+#include
#include
/* This must match the type_to_string_ cases. */
diff --git a/contrib/lightning-open-channel b/contrib/lightning-open-channel
index d4cac9bde..e678744c0 100755
--- a/contrib/lightning-open-channel
+++ b/contrib/lightning-open-channel
@@ -9,10 +9,10 @@ HOST="$1"
PORT="$2"
AMOUNT="$3"
-NEWADDR=`daemon/lightning-cli newaddr | sed -n 's/{ "address" : "\(.*\)" }/\1/p'`
+NEWADDR=`cli/lightning-cli newaddr | sed -n 's/{ "address" : "\(.*\)" }/\1/p'`
TXID=`bitcoin-cli -testnet sendtoaddress $NEWADDR $AMOUNT`
RAWTX=`bitcoin-cli -testnet getrawtransaction $TXID`
echo "Connecting to $HOST port $PORT with $AMOUNT (minus fee) in address $NEWADDR tx $TXID"
echo "(Note: this will block until we get sufficient confirmations!)"
-exec daemon/lightning-cli connect "$HOST" "$PORT" $RAWTX
+exec cli/lightning-cli connect "$HOST" "$PORT" $RAWTX
diff --git a/contrib/lightning-pay b/contrib/lightning-pay
index fed8438a9..7400aeada 100755
--- a/contrib/lightning-pay
+++ b/contrib/lightning-pay
@@ -9,7 +9,7 @@ DEST="$1"
AMOUNT="$2"
PHASH="$3"
-if ROUTE=`daemon/lightning-cli getroute $DEST $AMOUNT 1`; then
+if ROUTE=`cli/lightning-cli getroute $DEST $AMOUNT 1`; then
# Strip down to raw array.
ROUTE=`echo $ROUTE | sed 's/^{ "route" : \(.*\) }$/\1/'`
# Get first amount.
@@ -18,7 +18,7 @@ if ROUTE=`daemon/lightning-cli getroute $DEST $AMOUNT 1`; then
read REPLY
case $REPLY in
""|y*|Y)
- daemon/lightning-cli sendpay "$ROUTE" "$PHASH"
+ cli/lightning-cli sendpay "$ROUTE" "$PHASH"
exit
;;
*)
diff --git a/daemon/Makefile b/daemon/Makefile
index 97500ca55..ce48f4c28 100644
--- a/daemon/Makefile
+++ b/daemon/Makefile
@@ -34,11 +34,8 @@ DAEMON_SRC := \
DAEMON_OBJS := $(DAEMON_SRC:.c=.o)
-DAEMON_CLI_SRC := daemon/lightning-cli.c
-DAEMON_CLI_OBJS := $(DAEMON_CLI_SRC:.c=.o)
-
DAEMON_JSMN_OBJS := daemon/jsmn.o
-DAEMON_JSMN_HEADERS := daemon/jsmn/jsmn.h
+DAEMON_JSMN_HEADERS := daemon/jsmn/jsmn.hb
DAEMON_GEN_HEADERS := \
daemon/gen_htlc_state_names.h
@@ -64,9 +61,6 @@ DAEMON_HEADERS := \
daemon/timeout.h \
daemon/watch.h
-daemon/gen_htlc_state_names.h: daemon/htlc_state.h ccan/ccan/cdump/tools/cdump-enumstr
- ccan/ccan/cdump/tools/cdump-enumstr daemon/htlc_state.h > $@
-
daemon/gen_feechange_state_names.h: daemon/feechange_state.h ccan/ccan/cdump/tools/cdump-enumstr
ccan/ccan/cdump/tools/cdump-enumstr daemon/feechange_state.h > $@
@@ -91,19 +85,6 @@ check-source-bolt: $(DAEMON_SRC:%=bolt-check/%) $(DAEMON_HEADERS:%=bolt-check/%)
check-whitespace: $(DAEMON_SRC:%=check-whitespace/%) $(DAEMON_HEADERS:%=check-whitespace/%) check-whitespace/daemon/Makefile
-# Git submodules are seriously broken.
-daemon/jsmn/jsmn.h:
- git submodule update daemon/jsmn/
- [ -f $@ ] || git submodule update --init daemon/jsmn/
-
-# If we tell Make that the above builds both, it runs it twice in
-# parallel. So we lie :(
-daemon/jsmn/jsmn.c: daemon/jsmn/jsmn.h
- [ -f $@ ]
-
-daemon/jsmn.o: daemon/jsmn/jsmn.c
- $(COMPILE.c) -DJSMN_STRICT=1 $(OUTPUT_OPTION) $<
-
daemon/lightning-cli: $(DAEMON_CLI_OBJS) $(DAEMON_LIB_OBJS) $(DAEMON_JSMN_OBJS) $(CORE_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) libsecp256k1.a libsodium.a
daemon-clean:
diff --git a/daemon/lightningd.h b/daemon/lightningd.h
deleted file mode 100644
index 354e236ed..000000000
--- a/daemon/lightningd.h
+++ /dev/null
@@ -1,135 +0,0 @@
-#ifndef LIGHTNING_DAEMON_LIGHTNING_H
-#define LIGHTNING_DAEMON_LIGHTNING_H
-#include "config.h"
-#include "bitcoin/pubkey.h"
-#include "watch.h"
-#include
-#include
-#include
-#include
-#include
-
-/* Various adjustable things. */
-struct config {
- /* How long do we want them to lock up their funds? (blocks) */
- u32 locktime_blocks;
-
- /* How long do we let them lock up our funds? (blocks) */
- u32 locktime_max;
-
- /* How many blocks before we expect to see anchor?. */
- u32 anchor_onchain_wait;
-
- /* How many confirms until we consider an anchor "settled". */
- u32 anchor_confirms;
-
- /* How long will we accept them waiting? */
- u32 anchor_confirms_max;
-
- /* How many blocks until we stop watching a close commit? */
- u32 forever_confirms;
-
- /* Maximum percent of fee rate we'll accept. */
- u32 commitment_fee_max_percent;
-
- /* Minimum percent of fee rate we'll accept. */
- u32 commitment_fee_min_percent;
-
- /* Percent of fee rate we'll use. */
- u32 commitment_fee_percent;
-
- /* Minimum/maximum time for an expiring HTLC (blocks). */
- u32 min_htlc_expiry, max_htlc_expiry;
-
- /* How many blocks before upstream HTLC expiry do we panic and dump? */
- u32 deadline_blocks;
-
- /* Fee rates. */
- u32 fee_base;
- s32 fee_per_satoshi;
-
- /* How long between polling bitcoind. */
- struct timerel poll_time;
-
- /* How long between changing commit and sending COMMIT message. */
- struct timerel commit_time;
-
- /* Whether to enable IRC peer discovery. */
- bool use_irc;
-
- /* Whether to ignore database version. */
- bool db_version_ignore;
-
- /* IPv4 or IPv6 address to announce to the network */
- struct ipaddr ipaddr;
-};
-
-/* Here's where the global variables hide! */
-struct lightningd_state {
- /* Where all our logging goes. */
- struct log_book *log_book;
- struct log *base_log;
- FILE *logf;
-
- /* Our config dir, and rpc file */
- char *config_dir;
- char *rpc_filename;
-
- /* Port we're listening on */
- u16 portnum;
-
- /* We're on testnet. */
- bool testnet;
-
- /* Configuration settings. */
- struct config config;
-
- /* The database where we keep our stuff. */
- struct db *db;
-
- /* Any pending timers. */
- struct timers timers;
-
- /* Cached block topology. */
- struct chain_topology *topology;
-
- /* Our peers. */
- struct list_head peers;
-
- /* Addresses to contact peers. */
- struct list_head addresses;
-
- /* Any outstanding "pay" commands. */
- struct list_head pay_commands;
-
- /* Our private key */
- struct privkey *privkey;
-
- /* This is us. */
- struct pubkey id;
-
- /* Our tame bitcoind. */
- struct bitcoind *bitcoind;
-
- /* Wallet addresses we maintain. */
- struct list_head wallet;
-
- /* Maintained by invoices.c */
- struct invoices *invoices;
-
- /* Routing information */
- struct routing_state *rstate;
-
- /* For testing: don't fail if we can't route. */
- bool dev_never_routefail;
-
- /* Re-exec hack for testing. */
- char **reexec;
-
- /* IP/hostname to be announced for incoming connections */
- char *external_ip;
-
- /* Announce timer. */
- struct oneshot *announce;
-};
-#endif /* LIGHTNING_DAEMON_LIGHTNING_H */
diff --git a/lightningd/Makefile b/lightningd/Makefile
index 413dd0fd4..f43ef9584 100644
--- a/lightningd/Makefile
+++ b/lightningd/Makefile
@@ -10,37 +10,16 @@ lightningd-all: $(LIGHTNINGD_BINS)
default: lightningd-all
-LIGHTNINGD_OLD_SRC := \
- daemon/bitcoind.c \
- daemon/broadcast.c \
- daemon/chaintopology.c \
- daemon/configdir.c \
- daemon/dns.c \
- daemon/invoice.c \
- daemon/json.c \
- daemon/jsonrpc.c \
- daemon/log.c \
- daemon/netaddr.c \
- daemon/options.c \
- daemon/opt_time.c \
- daemon/pseudorand.c \
- daemon/routing.c \
- daemon/watch.c
-LIGHTNINGD_OLD_OBJS := $(LIGHTNINGD_OLD_SRC:.c=.o)
-LIGHTNINGD_OLD_HEADERS := $(LIGHTNINGD_OLD_SRC:.c=.h)
-
-LIGHTNINGD_OLD_LIB_SRC := \
- daemon/htlc_state.c \
- daemon/pseudorand.c \
- daemon/timeout.c
-LIGHTNINGD_OLD_LIB_OBJS := $(LIGHTNINGD_OLD_LIB_SRC:.c=.o)
-LIGHTNINGD_OLD_LIB_HEADERS := $(LIGHTNINGD_OLD_LIB_SRC:.c=.h)
-
# Common source we use.
LIGHTNINGD_COMMON_OBJS := \
+ common/configdir.o \
common/derive_basepoints.o \
common/funding_tx.o \
+ common/htlc_state.o \
+ common/json.o \
common/permute_tx.o \
+ common/pseudorand.o \
+ common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/version.o \
@@ -70,47 +49,51 @@ LIGHTNINGD_LIB_OBJS := $(LIGHTNINGD_LIB_SRC:.c=.o)
LIGHTNINGD_LIB_HEADERS := $(LIGHTNINGD_LIB_SRC:.c=.h)
LIGHTNINGD_SRC := \
+ lightningd/bitcoind.c \
lightningd/build_utxos.c \
- lightningd/dev_ping.c \
+ lightningd/chaintopology.c \
+ lightningd/dns.c \
lightningd/gossip_control.c \
- lightningd/htlc_end.c \
lightningd/hsm_control.c \
+ lightningd/htlc_end.c \
+ lightningd/invoice.c \
+ lightningd/jsonrpc.c \
lightningd/lightningd.c \
+ lightningd/log.c \
+ lightningd/netaddr.c \
lightningd/new_connection.c \
+ lightningd/opt_time.c \
+ lightningd/options.c \
lightningd/pay.c \
lightningd/peer_control.c \
lightningd/peer_htlcs.c \
- lightningd/subd.c
+ lightningd/subd.c \
+ lightningd/watch.c
-LIGHTNINGD_OBJS := $(LIGHTNINGD_SRC:.c=.o)
+# Source files without corresponding headers
+LIGHTNINGD_SRC_NOHDR := \
+ lightningd/dev_ping.c \
+
+LIGHTNINGD_OBJS := $(LIGHTNINGD_SRC:.c=.o) $(LIGHTNINGD_SRC_NOHDR:.c=.o)
LIGHTNINGD_JSMN_OBJS := daemon/jsmn.o
LIGHTNINGD_JSMN_HEADERS := daemon/jsmn/jsmn.h
# We accumulate all lightningd/ headers in these three:
LIGHTNINGD_HEADERS_NOGEN = \
- lightningd/build_utxos.h \
- lightningd/gossip_control.h \
- lightningd/hsm_control.h \
- lightningd/htlc_end.h \
- lightningd/lightningd.h \
- lightningd/new_connection.h \
- lightningd/pay.h \
- lightningd/peer_control.h \
- lightningd/peer_htlcs.h \
+ $(LIGHTNINGD_SRC:.c=.h) \
lightningd/peer_state.h \
- lightningd/subd.h \
- $(LIGHTNINGD_OLD_LIB_HEADERS) \
$(LIGHTNINGD_LIB_HEADERS) \
$(WIRE_HEADERS) \
$(BITCOIN_HEADERS) \
- $(COMMON_HEADERS) \
- $(DAEMON_HEADERS) \
+ $(COMMON_HEADERS_NOGEN) \
$(WALLET_LIB_HEADERS)
# Generated headers
LIGHTNINGD_HEADERS_GEN = \
lightningd/gen_peer_state_names.h \
+ lightningd/gen_peer_state_names.h \
+ $(COMMON_HEADERS_GEN) \
$(WIRE_GEN_HEADERS) \
$(GEN_HEADERS)
@@ -139,7 +122,7 @@ $(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS): $(LIGHTNINGD_HEADERS)
lightningd/gen_peer_state_names.h: lightningd/peer_state.h ccan/ccan/cdump/tools/cdump-enumstr
ccan/ccan/cdump/tools/cdump-enumstr lightningd/peer_state.h > $@
-check-source: $(LIGHTNINGD_SRC:%=check-src-include-order/%)
+check-source: $(LIGHTNINGD_SRC:%=check-src-include-order/%) $(LIGHTNINGD_SRC_NOHDR:%=check-src-include-order/%)
check-source: $(LIGHTNINGD_LIB_SRC:%=check-src-include-order/%)
check-source: $(LIGHTNINGD_CLI_SRC:%=check-src-include-order/%)
check-source: $(LIGHTNINGD_HEADERS_NOGEN:%=check-hdr-include-order/%)
@@ -151,7 +134,7 @@ check-makefile: check-lightningd-makefile
check-lightningd-makefile:
@for f in lightningd/*.h lightningd/*/*.h; do if ! echo $(LIGHTNINGD_HEADERS_NOGEN) $(LIGHTNINGD_HEADERS_GEN) "" | grep -q "$$f "; then echo $$f not mentioned in LIGHTNINGD_HEADERS_NOGEN or LIGHTNINGD_HEADERS_GEN >&2; exit 1; fi; done
-lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_OLD_OBJS) $(LIGHTNINGD_OLD_LIB_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CONTROL_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) libsecp256k1.a libsodium.a libwallycore.a
+lightningd/lightningd: $(LIGHTNINGD_OBJS) $(LIGHTNINGD_LIB_OBJS) $(LIGHTNINGD_COMMON_OBJS) $(LIGHTNINGD_JSMN_OBJS) $(BITCOIN_OBJS) $(WIRE_OBJS) $(WIRE_ONION_OBJS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(LIGHTNINGD_HSM_CONTROL_OBJS) $(LIGHTNINGD_HANDSHAKE_CONTROL_OBJS) $(LIGHTNINGD_GOSSIP_CONTROL_OBJS) $(LIBBASE58_OBJS) $(LIGHTNINGD_OPENING_CONTROL_OBJS) $(LIGHTNINGD_CHANNEL_CONTROL_OBJS) $(LIGHTNINGD_CLOSING_CONTROL_OBJS) $(LIGHTNINGD_ONCHAIN_CONTROL_OBJS) $(WALLET_LIB_OBJS) libsecp256k1.a libsodium.a libwallycore.a
clean: lightningd-clean
diff --git a/daemon/bitcoind.c b/lightningd/bitcoind.c
similarity index 99%
rename from daemon/bitcoind.c
rename to lightningd/bitcoind.c
index e1ad3b668..777148e56 100644
--- a/daemon/bitcoind.c
+++ b/lightningd/bitcoind.c
@@ -4,7 +4,6 @@
#include "bitcoin/shadouble.h"
#include "bitcoin/tx.h"
#include "bitcoind.h"
-#include "json.h"
#include "lightningd.h"
#include "log.h"
#include
@@ -16,6 +15,7 @@
#include
#include
#include
+#include
#include
#include
#include
diff --git a/daemon/bitcoind.h b/lightningd/bitcoind.h
similarity index 100%
rename from daemon/bitcoind.h
rename to lightningd/bitcoind.h
diff --git a/lightningd/build_utxos.c b/lightningd/build_utxos.c
index 134f81025..5b2cb2931 100644
--- a/lightningd/build_utxos.c
+++ b/lightningd/build_utxos.c
@@ -2,8 +2,8 @@
#include
#include
#include
-#include
#include
+#include
#include
#include
diff --git a/daemon/chaintopology.c b/lightningd/chaintopology.c
similarity index 99%
rename from daemon/chaintopology.c
rename to lightningd/chaintopology.c
index 7b5e36199..e2582ca9c 100644
--- a/daemon/chaintopology.c
+++ b/lightningd/chaintopology.c
@@ -5,13 +5,13 @@
#include "jsonrpc.h"
#include "lightningd.h"
#include "log.h"
-#include "timeout.h"
#include "watch.h"
#include
#include
#include
#include
#include
+#include
#include
#include
diff --git a/daemon/chaintopology.h b/lightningd/chaintopology.h
similarity index 99%
rename from daemon/chaintopology.h
rename to lightningd/chaintopology.h
index 863c45006..d7a754de9 100644
--- a/daemon/chaintopology.h
+++ b/lightningd/chaintopology.h
@@ -8,7 +8,7 @@
#include
#include
#include
-#include
+#include
#include
struct bitcoin_tx;
diff --git a/lightningd/channel/Makefile b/lightningd/channel/Makefile
index 4f7fe8081..dd64d2c72 100644
--- a/lightningd/channel/Makefile
+++ b/lightningd/channel/Makefile
@@ -28,10 +28,13 @@ LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o)
# Common source we use.
CHANNELD_COMMON_OBJS := \
common/derive_basepoints.o \
+ common/htlc_state.o \
common/htlc_tx.o \
common/initial_channel.o \
common/initial_commit_tx.o \
common/permute_tx.o \
+ common/pseudorand.o \
+ common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/version.o
diff --git a/lightningd/channel/channel.c b/lightningd/channel/channel.c
index a7348576a..a2023ccc1 100644
--- a/lightningd/channel/channel.c
+++ b/lightningd/channel/channel.c
@@ -13,10 +13,9 @@
#include
#include
#include
+#include
#include
#include
-#include
-#include
#include
#include
#include
@@ -26,6 +25,7 @@
#include
#include
#include
+#include
#include
#include
#include
diff --git a/lightningd/channel/channeld_htlc.h b/lightningd/channel/channeld_htlc.h
index e88fa952d..5ac8d4d1e 100644
--- a/lightningd/channel/channeld_htlc.h
+++ b/lightningd/channel/channeld_htlc.h
@@ -2,6 +2,7 @@
#define LIGHTNINGD_CHANNELD_HTLC_H
#include "config.h"
#include
+#include
#include
struct htlc {
diff --git a/lightningd/channel/commit_tx.h b/lightningd/channel/commit_tx.h
index 467d2f54d..cd8994963 100644
--- a/lightningd/channel/commit_tx.h
+++ b/lightningd/channel/commit_tx.h
@@ -2,8 +2,8 @@
#define LIGHTNING_LIGHTNINGD_COMMIT_TX_H
#include "config.h"
#include
+#include
#include
-#include
#include
struct keyset;
diff --git a/lightningd/channel/full_channel.c b/lightningd/channel/full_channel.c
index 14245f82d..c1e48d6bb 100644
--- a/lightningd/channel/full_channel.c
+++ b/lightningd/channel/full_channel.c
@@ -6,9 +6,9 @@
#include
#include
#include
+#include
#include
#include
-#include
#include
#include
#include
diff --git a/lightningd/closing/closing.c b/lightningd/closing/closing.c
index e7a2351f0..26d29e2aa 100644
--- a/lightningd/closing/closing.c
+++ b/lightningd/closing/closing.c
@@ -1,10 +1,10 @@
#include
#include
#include
+#include
#include
#include
#include
-#include
#include
#include
#include
diff --git a/lightningd/dev_ping.c b/lightningd/dev_ping.c
index 8e6078975..7feb7ef7a 100644
--- a/lightningd/dev_ping.c
+++ b/lightningd/dev_ping.c
@@ -1,10 +1,10 @@
#include
-#include
-#include
#include
#include
#include
+#include
#include
+#include
#include
#include
#include
diff --git a/daemon/dns.c b/lightningd/dns.c
similarity index 100%
rename from daemon/dns.c
rename to lightningd/dns.c
diff --git a/daemon/dns.h b/lightningd/dns.h
similarity index 100%
rename from daemon/dns.h
rename to lightningd/dns.h
diff --git a/lightningd/gossip/Makefile b/lightningd/gossip/Makefile
index 9b3188b3a..6f8f6a424 100644
--- a/lightningd/gossip/Makefile
+++ b/lightningd/gossip/Makefile
@@ -11,14 +11,10 @@ LIGHTNINGD_GOSSIP_CONTROL_HEADERS := lightningd/gossip/gen_gossip_wire.h
LIGHTNINGD_GOSSIP_CONTROL_SRC := lightningd/gossip/gen_gossip_wire.c
LIGHTNINGD_GOSSIP_CONTROL_OBJS := $(LIGHTNINGD_GOSSIP_CONTROL_SRC:.c=.o)
-# These should eventually be migrated to the lightningd directory, after
-# deprecating the legacy daemons
-LIGHTNINGD_GOSSIP_LEGACY_HEADERS := daemon/routing.h daemon/broadcast.h \
- daemon/log.h
-
# lightningd/gossip needs these:
LIGHTNINGD_GOSSIP_HEADERS := lightningd/gossip/gen_gossip_wire.h \
- $(LIGHTNINGD_GOSSIP_LEGACY_HEADERS)
+ lightningd/gossip/routing.h \
+ lightningd/gossip/broadcast.h
LIGHTNINGD_GOSSIP_SRC := lightningd/gossip/gossip.c \
$(LIGHTNINGD_GOSSIP_HEADERS:.h=.c)
LIGHTNINGD_GOSSIP_OBJS := $(LIGHTNINGD_GOSSIP_SRC:.c=.o)
@@ -32,6 +28,8 @@ LIGHTNINGD_HEADERS_GEN += $(LIGHTNINGD_GOSSIP_HEADERS)
# Common source we use.
GOSSIPD_COMMON_OBJS := \
+ common/pseudorand.o \
+ common/timeout.o \
common/type_to_string.o \
common/utils.o \
common/version.o
diff --git a/daemon/broadcast.c b/lightningd/gossip/broadcast.c
similarity index 97%
rename from daemon/broadcast.c
rename to lightningd/gossip/broadcast.c
index be530ffa3..63cc2d97c 100644
--- a/daemon/broadcast.c
+++ b/lightningd/gossip/broadcast.c
@@ -1,4 +1,4 @@
-#include "daemon/broadcast.h"
+#include
struct broadcast_state *new_broadcast_state(tal_t *ctx)
{
diff --git a/daemon/broadcast.h b/lightningd/gossip/broadcast.h
similarity index 100%
rename from daemon/broadcast.h
rename to lightningd/gossip/broadcast.h
diff --git a/lightningd/gossip/gossip.c b/lightningd/gossip/gossip.c
index b85fcda61..c31b7fdf2 100644
--- a/lightningd/gossip/gossip.c
+++ b/lightningd/gossip/gossip.c
@@ -9,19 +9,20 @@
#include
#include
#include
+#include
+#include
#include
#include
#include
-#include
-#include
-#include
#include
#include
#include
#include
#include
#include
+#include
#include
+#include
#include
#include
#include
diff --git a/daemon/routing.c b/lightningd/gossip/routing.c
similarity index 99%
rename from daemon/routing.c
rename to lightningd/gossip/routing.c
index b13a79375..fddad4860 100644
--- a/daemon/routing.c
+++ b/lightningd/gossip/routing.c
@@ -1,7 +1,4 @@
-#include "lightningd.h"
-#include "pseudorand.h"
#include "routing.h"
-#include "wire/gen_peer_wire.h"
#include
#include
#include
@@ -10,9 +7,12 @@
#include
#include
#include
+#include
#include
#include
+#include
#include
+#include
/* 365.25 * 24 * 60 / 10 */
#define BLOCKS_PER_YEAR 52596
diff --git a/daemon/routing.h b/lightningd/gossip/routing.h
similarity index 98%
rename from daemon/routing.h
rename to lightningd/gossip/routing.h
index b699318f0..a7fffdb7c 100644
--- a/daemon/routing.h
+++ b/lightningd/gossip/routing.h
@@ -1,10 +1,10 @@
#ifndef LIGHTNING_DAEMON_ROUTING_H
#define LIGHTNING_DAEMON_ROUTING_H
#include "config.h"
-#include "bitcoin/pubkey.h"
-#include "daemon/broadcast.h"
-#include "wire/wire.h"
+#include
#include
+#include
+#include
#define ROUTING_MAX_HOPS 20
#define ROUTING_FLAGS_DISABLED 2
diff --git a/lightningd/gossip_control.c b/lightningd/gossip_control.c
index 7f79268c8..a1d955ddb 100644
--- a/lightningd/gossip_control.c
+++ b/lightningd/gossip_control.c
@@ -7,12 +7,12 @@
#include
#include
#include
-#include
-#include
#include
#include
#include
#include
+#include
+#include
#include
static void gossip_finished(struct subd *gossip, int status)
diff --git a/lightningd/gossip_msg.h b/lightningd/gossip_msg.h
index 638855595..ec089e025 100644
--- a/lightningd/gossip_msg.h
+++ b/lightningd/gossip_msg.h
@@ -2,7 +2,7 @@
#define LIGHTNING_LIGHTNINGD_GOSSIP_MSG_H
#include "config.h"
#include
-#include
+#include
struct gossip_getnodes_entry {
struct pubkey nodeid;
diff --git a/lightningd/hsm_control.c b/lightningd/hsm_control.c
index bec7204fd..bc42e8933 100644
--- a/lightningd/hsm_control.c
+++ b/lightningd/hsm_control.c
@@ -6,10 +6,10 @@
#include
#include
#include
-#include
#include
#include
#include
+#include
#include
#include
#include
diff --git a/lightningd/htlc_end.c b/lightningd/htlc_end.c
index 124fb11e3..23fa95fe4 100644
--- a/lightningd/htlc_end.c
+++ b/lightningd/htlc_end.c
@@ -2,10 +2,10 @@
#include
#include
#include
-#include
-#include
-#include
+#include
+#include
#include
+#include
#include
size_t hash_htlc_key(const struct htlc_key *k)
diff --git a/lightningd/htlc_end.h b/lightningd/htlc_end.h
index 30142c153..a0dfa88b0 100644
--- a/lightningd/htlc_end.h
+++ b/lightningd/htlc_end.h
@@ -3,7 +3,7 @@
#include "config.h"
#include
#include
-#include
+#include