From 1e6747c28e81bd6603d2c6383ad765380864d77f Mon Sep 17 00:00:00 2001 From: ZmnSCPxj Date: Mon, 22 Jan 2018 23:53:21 +0000 Subject: [PATCH] wallet: Pass in timers object during construction. In preparation for expiration. --- lightningd/lightningd.c | 2 +- lightningd/test/run-find_my_path.c | 3 ++- wallet/invoices.c | 7 ++++++- wallet/invoices.h | 5 ++++- wallet/wallet.c | 5 +++-- wallet/wallet.h | 4 +++- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lightningd/lightningd.c b/lightningd/lightningd.c index 25a3fca51..c24cbc665 100644 --- a/lightningd/lightningd.c +++ b/lightningd/lightningd.c @@ -281,7 +281,7 @@ int main(int argc, char *argv[]) test_daemons(ld); /* Initialize wallet, now that we are in the correct directory */ - ld->wallet = wallet_new(ld, ld->log); + ld->wallet = wallet_new(ld, ld->log, &ld->timers); ld->owned_txfilter = txfilter_new(ld); /* Set up HSM. */ diff --git a/lightningd/test/run-find_my_path.c b/lightningd/test/run-find_my_path.c index 3cd66830a..e795b64c4 100644 --- a/lightningd/test/run-find_my_path.c +++ b/lightningd/test/run-find_my_path.c @@ -112,7 +112,8 @@ bool wallet_htlcs_reconnect(struct wallet *wallet UNNEEDED, bool wallet_invoice_load(struct wallet *wallet UNNEEDED) { fprintf(stderr, "wallet_invoice_load called!\n"); abort(); } /* Generated stub for wallet_new */ -struct wallet *wallet_new(const tal_t *ctx UNNEEDED, struct log *log UNNEEDED) +struct wallet *wallet_new(const tal_t *ctx UNNEEDED, + struct log *log UNNEEDED, struct timers *timers UNNEEDED) { fprintf(stderr, "wallet_new called!\n"); abort(); } /* AUTOGENERATED MOCKS END */ diff --git a/wallet/invoices.c b/wallet/invoices.c index 5703f102c..a0162b2b7 100644 --- a/wallet/invoices.c +++ b/wallet/invoices.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,8 @@ struct invoices { struct db *db; /* The log to report to. */ struct log *log; + /* The timers object to use for expirations. */ + struct timers *timers; /* The invoice list. */ struct list_head invlist; /* Waiters waiting for any new invoice to be paid. */ @@ -71,12 +74,14 @@ static bool wallet_stmt2invoice(sqlite3_stmt *stmt, struct invoice *inv) struct invoices *invoices_new(const tal_t *ctx, struct db *db, - struct log *log) + struct log *log, + struct timers *timers) { struct invoices *invs = tal(ctx, struct invoices); invs->db = db; invs->log = log; + invs->timers = timers; list_head_init(&invs->invlist); list_head_init(&invs->waitany_waiters); diff --git a/wallet/invoices.h b/wallet/invoices.h index caa54104e..57f84818b 100644 --- a/wallet/invoices.h +++ b/wallet/invoices.h @@ -10,6 +10,7 @@ struct invoice; struct invoices; struct log; struct sha256; +struct timers; /** * invoices_new - Constructor for a new invoice handler @@ -17,10 +18,12 @@ struct sha256; * @ctx - the owner of the invoice handler. * @db - the database connection to use for saving invoice. * @log - the log to report to. + * @timers - the timers object to use for expirations. */ struct invoices *invoices_new(const tal_t *ctx, struct db *db, - struct log *log); + struct log *log, + struct timers *timers); /** * invoices_load - Second-stage constructor for invoice handler. diff --git a/wallet/wallet.c b/wallet/wallet.c index b9e983b32..4d5065a44 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -16,13 +16,14 @@ #define DIRECTION_INCOMING 0 #define DIRECTION_OUTGOING 1 -struct wallet *wallet_new(const tal_t *ctx, struct log *log) +struct wallet *wallet_new(const tal_t *ctx, + struct log *log, struct timers *timers) { struct wallet *wallet = tal(ctx, struct wallet); wallet->db = db_setup(wallet, log); wallet->log = log; wallet->bip32_base = NULL; - wallet->invoices = invoices_new(wallet, wallet->db, log); + wallet->invoices = invoices_new(wallet, wallet->db, log, timers); list_head_init(&wallet->unstored_payments); return wallet; } diff --git a/wallet/wallet.h b/wallet/wallet.h index 837a776ce..82b6d0ac5 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -17,6 +17,7 @@ struct invoices; struct lightningd; struct pubkey; +struct timers; struct wallet { struct db *db; @@ -105,7 +106,8 @@ struct wallet_payment { * This is guaranteed to either return a valid wallet, or abort with * `fatal` if it cannot be initialized. */ -struct wallet *wallet_new(const tal_t *ctx, struct log *log); +struct wallet *wallet_new(const tal_t *ctx, + struct log *log, struct timers *timers); /** * wallet_add_utxo - Register a UTXO which we (partially) own