Browse Source

wallet: Wiring in invoice persistence into JSON-RPC and master

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
11903aed6c
  1. 29
      lightningd/invoice.c
  2. 7
      lightningd/invoice.h
  3. 6
      lightningd/lightningd.c
  4. 3
      lightningd/test/run-find_my_path.c

29
lightningd/invoice.c

@ -56,20 +56,12 @@ static struct invoice *find_invoice_by_label(const struct list_head *list,
} }
void invoice_add(struct invoices *invs, void invoice_add(struct invoices *invs,
const struct preimage *r, struct invoice *inv)
u64 msatoshi,
const char *label,
enum invoice_status state)
{ {
tal_steal(invs, inv);
struct invoice *invoice = tal(invs, struct invoice); struct invoice *invoice = tal(invs, struct invoice);
invoice->msatoshi = msatoshi;
invoice->r = *r;
invoice->state = state;
invoice->label = tal_strdup(invoice, label);
sha256(&invoice->rhash, invoice->r.r, sizeof(invoice->r.r)); sha256(&invoice->rhash, invoice->r.r, sizeof(invoice->r.r));
list_add(&invs->invlist, &inv->list);
list_add(&invs->invlist, &invoice->list);
} }
struct invoices *invoices_init(const tal_t *ctx) struct invoices *invoices_init(const tal_t *ctx)
@ -96,12 +88,6 @@ static void tell_waiter(struct command *cmd, const struct invoice *paid)
} }
/* UNIFICATION FIXME */ /* UNIFICATION FIXME */
void db_resolve_invoice(struct lightningd *ld,
const char *label);
bool db_new_invoice(struct lightningd *ld,
u64 msatoshi,
const char *label,
const struct preimage *r);
bool db_remove_invoice(struct lightningd *ld, const char *label); bool db_remove_invoice(struct lightningd *ld, const char *label);
void resolve_invoice(struct lightningd *ld, struct invoice *invoice) void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
@ -117,7 +103,7 @@ void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
list)) != NULL) list)) != NULL)
tell_waiter(w->cmd, invoice); tell_waiter(w->cmd, invoice);
db_resolve_invoice(ld, invoice->label); wallet_invoice_save(ld->wallet, invoice);
} }
static void json_invoice(struct command *cmd, static void json_invoice(struct command *cmd,
@ -138,6 +124,7 @@ static void json_invoice(struct command *cmd,
} }
invoice = tal(cmd, struct invoice); invoice = tal(cmd, struct invoice);
invoice->id = 0;
invoice->state = UNPAID; invoice->state = UNPAID;
if (r) { if (r) {
if (!hex_decode(buffer + r->start, r->end - r->start, if (!hex_decode(buffer + r->start, r->end - r->start,
@ -178,11 +165,13 @@ static void json_invoice(struct command *cmd,
return; return;
} }
if (!db_new_invoice(cmd->ld, invoice->msatoshi, invoice->label, if (!wallet_invoice_save(cmd->ld->wallet, invoice)) {
&invoice->r)) { printf("Could not save the invoice to the database: %s",
cmd->ld->wallet->db->err);
command_fail(cmd, "database error"); command_fail(cmd, "database error");
return; return;
} }
/* OK, connect it to main state, respond with hash */ /* OK, connect it to main state, respond with hash */
tal_steal(invs, invoice); tal_steal(invs, invoice);
list_add(&invs->invlist, &invoice->list); list_add(&invs->invlist, &invoice->list);

7
lightningd/invoice.h

@ -29,11 +29,8 @@ struct invoice {
#define INVOICE_MAX_LABEL_LEN 128 #define INVOICE_MAX_LABEL_LEN 128
/* From database */ /* From database */
void invoice_add(struct invoices *i, void invoice_add(struct invoices *invs,
const struct preimage *r, struct invoice *inv);
u64 msatoshi,
const char *label,
enum invoice_status state);
void resolve_invoice(struct lightningd *ld, struct invoice *invoice); void resolve_invoice(struct lightningd *ld, struct invoice *invoice);

6
lightningd/lightningd.c

@ -276,6 +276,11 @@ int main(int argc, char *argv[])
/* FIXME: Load from peers. */ /* FIXME: Load from peers. */
0); 0);
/* Load invoices from the database */
if (!wallet_invoices_load(ld->wallet, ld->invoices)) {
err(1, "Could not load invoices from the database");
}
/* Load peers from database */ /* Load peers from database */
wallet_channels_load_active(ld->wallet, &ld->peers); wallet_channels_load_active(ld->wallet, &ld->peers);
@ -325,4 +330,3 @@ int main(int argc, char *argv[])
tal_free(log_book); tal_free(log_book);
return 0; return 0;
} }

3
lightningd/test/run-find_my_path.c

@ -86,6 +86,9 @@ bool wallet_htlcs_reconnect(struct wallet *wallet UNNEEDED,
struct htlc_in_map *htlcs_in UNNEEDED, struct htlc_in_map *htlcs_in UNNEEDED,
struct htlc_out_map *htlcs_out UNNEEDED) struct htlc_out_map *htlcs_out UNNEEDED)
{ fprintf(stderr, "wallet_htlcs_reconnect called!\n"); abort(); } { fprintf(stderr, "wallet_htlcs_reconnect called!\n"); abort(); }
/* Generated stub for wallet_invoices_load */
bool wallet_invoices_load(struct wallet *wallet UNNEEDED, struct invoices *invs UNNEEDED)
{ fprintf(stderr, "wallet_invoices_load called!\n"); abort(); }
/* Generated stub for wallet_new */ /* 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)
{ fprintf(stderr, "wallet_new called!\n"); abort(); } { fprintf(stderr, "wallet_new called!\n"); abort(); }

Loading…
Cancel
Save