wallet: Record issued invoices in the payments table

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2017-11-10 18:57:43 +01:00
committed by Rusty Russell
parent d1cc5f4552
commit 6ceb375650
2 changed files with 36 additions and 0 deletions

View File

@@ -104,6 +104,9 @@ void resolve_invoice(struct lightningd *ld, struct invoice *invoice)
tell_waiter(w->cmd, 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,
@@ -115,6 +118,7 @@ static void json_invoice(struct command *cmd,
struct invoices *invs = cmd->ld->invoices;
struct bolt11 *b11;
char *b11enc;
struct wallet_payment payment;
if (!json_get_params(buffer, params,
"amount", &msatoshi,
@@ -193,6 +197,20 @@ static void json_invoice(struct command *cmd,
tal_steal(invs, invoice);
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_add_hex(response, "rhash",
&invoice->rhash, sizeof(invoice->rhash));

View File

@@ -162,6 +162,7 @@ static void send_payment(struct command *cmd,
size_t i, n_hops = tal_count(route);
struct hop_data *hop_data = tal_arr(cmd, struct hop_data, 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. */
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");
}
/* 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]);
if (!peer) {
command_fail(cmd, "no connection to first peer found");