Browse Source

wallet: Record issued invoices in the payments table

Signed-off-by: Christian Decker <decker.christian@gmail.com>
ppa-0.6.1
Christian Decker 7 years ago
committed by Rusty Russell
parent
commit
6ceb375650
  1. 18
      lightningd/invoice.c
  2. 18
      lightningd/pay.c

18
lightningd/invoice.c

@ -104,6 +104,9 @@ void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
tell_waiter(w->cmd, invoice); tell_waiter(w->cmd, invoice);
wallet_invoice_save(ld->wallet, invoice); wallet_invoice_save(ld->wallet, invoice);
/* Also mark the payment in the history table as complete */
wallet_payment_set_status(ld->wallet, &invoice->rhash, PAYMENT_COMPLETE);
} }
static void json_invoice(struct command *cmd, static void json_invoice(struct command *cmd,
@ -115,6 +118,7 @@ static void json_invoice(struct command *cmd,
struct invoices *invs = cmd->ld->invoices; struct invoices *invs = cmd->ld->invoices;
struct bolt11 *b11; struct bolt11 *b11;
char *b11enc; char *b11enc;
struct wallet_payment payment;
if (!json_get_params(buffer, params, if (!json_get_params(buffer, params,
"amount", &msatoshi, "amount", &msatoshi,
@ -193,6 +197,20 @@ static void json_invoice(struct command *cmd,
tal_steal(invs, invoice); tal_steal(invs, invoice);
list_add_tail(&invs->invlist, &invoice->list); list_add_tail(&invs->invlist, &invoice->list);
/* Store the payment so we can later show it in the history */
payment.id = 0;
payment.incoming = true;
payment.payment_hash = invoice->rhash;
payment.destination = NULL;
payment.status = PAYMENT_PENDING;
payment.msatoshi = invoice->msatoshi;
payment.timestamp = b11->timestamp;
if (!wallet_payment_add(cmd->ld->wallet, &payment)) {
command_fail(cmd, "Unable to record payment in the database.");
return;
}
json_object_start(response, NULL); json_object_start(response, NULL);
json_add_hex(response, "rhash", json_add_hex(response, "rhash",
&invoice->rhash, sizeof(invoice->rhash)); &invoice->rhash, sizeof(invoice->rhash));

18
lightningd/pay.c

@ -162,6 +162,7 @@ static void send_payment(struct command *cmd,
size_t i, n_hops = tal_count(route); size_t i, n_hops = tal_count(route);
struct hop_data *hop_data = tal_arr(cmd, struct hop_data, n_hops); struct hop_data *hop_data = tal_arr(cmd, struct hop_data, n_hops);
struct pubkey *ids = tal_arr(cmd, struct pubkey, n_hops); struct pubkey *ids = tal_arr(cmd, struct pubkey, n_hops);
struct wallet_payment payment;
/* Expiry for HTLCs is absolute. And add one to give some margin. */ /* Expiry for HTLCs is absolute. And add one to give some margin. */
base_expiry = get_block_height(cmd->ld->topology) + 1; base_expiry = get_block_height(cmd->ld->topology) + 1;
@ -219,6 +220,23 @@ static void send_payment(struct command *cmd,
log_add(cmd->ld->log, "... retrying"); log_add(cmd->ld->log, "... retrying");
} }
/* If this is a new payment, then store the payment so we can
* later show it in the history */
if (!pc) {
payment.id = 0;
payment.incoming = false;
payment.payment_hash = *rhash;
payment.destination = &ids[n_hops - 1];
payment.status = PAYMENT_PENDING;
payment.msatoshi = route[n_hops-1].amount;
payment.timestamp = time_now().ts.tv_sec;
if (!wallet_payment_add(cmd->ld->wallet, &payment)) {
command_fail(cmd, "Unable to record payment in the database.");
return;
}
}
peer = peer_by_id(cmd->ld, &ids[0]); peer = peer_by_id(cmd->ld, &ids[0]);
if (!peer) { if (!peer) {
command_fail(cmd, "no connection to first peer found"); command_fail(cmd, "no connection to first peer found");

Loading…
Cancel
Save