mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
wallet: Wiring in invoice persistence into JSON-RPC and master
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
a005bce155
commit
11903aed6c
@ -56,20 +56,12 @@ static struct invoice *find_invoice_by_label(const struct list_head *list,
|
||||
}
|
||||
|
||||
void invoice_add(struct invoices *invs,
|
||||
const struct preimage *r,
|
||||
u64 msatoshi,
|
||||
const char *label,
|
||||
enum invoice_status state)
|
||||
struct invoice *inv)
|
||||
{
|
||||
tal_steal(invs, inv);
|
||||
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));
|
||||
|
||||
list_add(&invs->invlist, &invoice->list);
|
||||
list_add(&invs->invlist, &inv->list);
|
||||
}
|
||||
|
||||
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 */
|
||||
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);
|
||||
|
||||
void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
|
||||
@ -117,7 +103,7 @@ void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
|
||||
list)) != NULL)
|
||||
tell_waiter(w->cmd, invoice);
|
||||
|
||||
db_resolve_invoice(ld, invoice->label);
|
||||
wallet_invoice_save(ld->wallet, invoice);
|
||||
}
|
||||
|
||||
static void json_invoice(struct command *cmd,
|
||||
@ -138,6 +124,7 @@ static void json_invoice(struct command *cmd,
|
||||
}
|
||||
|
||||
invoice = tal(cmd, struct invoice);
|
||||
invoice->id = 0;
|
||||
invoice->state = UNPAID;
|
||||
if (r) {
|
||||
if (!hex_decode(buffer + r->start, r->end - r->start,
|
||||
@ -178,11 +165,13 @@ static void json_invoice(struct command *cmd,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!db_new_invoice(cmd->ld, invoice->msatoshi, invoice->label,
|
||||
&invoice->r)) {
|
||||
if (!wallet_invoice_save(cmd->ld->wallet, invoice)) {
|
||||
printf("Could not save the invoice to the database: %s",
|
||||
cmd->ld->wallet->db->err);
|
||||
command_fail(cmd, "database error");
|
||||
return;
|
||||
}
|
||||
|
||||
/* OK, connect it to main state, respond with hash */
|
||||
tal_steal(invs, invoice);
|
||||
list_add(&invs->invlist, &invoice->list);
|
||||
|
@ -29,11 +29,8 @@ struct invoice {
|
||||
#define INVOICE_MAX_LABEL_LEN 128
|
||||
|
||||
/* From database */
|
||||
void invoice_add(struct invoices *i,
|
||||
const struct preimage *r,
|
||||
u64 msatoshi,
|
||||
const char *label,
|
||||
enum invoice_status state);
|
||||
void invoice_add(struct invoices *invs,
|
||||
struct invoice *inv);
|
||||
|
||||
void resolve_invoice(struct lightningd *ld, struct invoice *invoice);
|
||||
|
||||
|
@ -276,6 +276,11 @@ int main(int argc, char *argv[])
|
||||
/* FIXME: Load from peers. */
|
||||
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 */
|
||||
wallet_channels_load_active(ld->wallet, &ld->peers);
|
||||
|
||||
@ -325,4 +330,3 @@ int main(int argc, char *argv[])
|
||||
tal_free(log_book);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -86,6 +86,9 @@ bool wallet_htlcs_reconnect(struct wallet *wallet UNNEEDED,
|
||||
struct htlc_in_map *htlcs_in UNNEEDED,
|
||||
struct htlc_out_map *htlcs_out UNNEEDED)
|
||||
{ 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 */
|
||||
struct wallet *wallet_new(const tal_t *ctx UNNEEDED, struct log *log UNNEEDED)
|
||||
{ fprintf(stderr, "wallet_new called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user