mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 11:59:16 +01:00
invoices: routines to maintain invoice indices.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
e92d15fffd
commit
6326f500ba
4 changed files with 75 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
struct amount_msat;
|
||||
struct htlc_set;
|
||||
struct json_escape;
|
||||
struct lightningd;
|
||||
struct sha256;
|
||||
|
||||
|
|
|
@ -963,6 +963,7 @@ static struct migration dbmigrations[] = {
|
|||
{SQL("CREATE TABLE runes_blacklist (start_index BIGINT, end_index BIGINT);"), NULL},
|
||||
{SQL("ALTER TABLE channels ADD ignore_fee_limits INTEGER DEFAULT 0;"), NULL},
|
||||
{NULL, migrate_initialize_wait_indexes},
|
||||
{SQL("ALTER TABLE invoices ADD updated_index BIGINT DEFAULT 0"), NULL},
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
#include <db/exec.h>
|
||||
#include <db/utils.h>
|
||||
#include <lightningd/invoice.h>
|
||||
#include <lightningd/wait.h>
|
||||
#include <wallet/invoices.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
struct invoice_waiter {
|
||||
/* Is this waiter already triggered? */
|
||||
|
@ -665,3 +665,59 @@ struct invoice_details *invoices_get_details(const tal_t *ctx,
|
|||
tal_free(stmt);
|
||||
return details;
|
||||
}
|
||||
|
||||
static u64 invoice_index_inc(struct lightningd *ld,
|
||||
const enum invoice_status *state,
|
||||
const struct json_escape *label,
|
||||
const char *invstring,
|
||||
const char *description,
|
||||
enum wait_index idx)
|
||||
{
|
||||
const char *invstrname;
|
||||
|
||||
if (invstring && strstarts(invstring, "lni"))
|
||||
invstrname = "bolt12";
|
||||
else
|
||||
invstrname = "bolt11";
|
||||
|
||||
|
||||
return wait_index_increment(ld, WAIT_SUBSYSTEM_INVOICE, idx,
|
||||
"status", state ? invoice_status_str(*state) : NULL,
|
||||
/* We don't want to add more JSON escapes here! */
|
||||
"=label", label ? tal_fmt(tmpctx, "\"%s\"", label->s) : NULL,
|
||||
invstrname, invstring,
|
||||
"description", description,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void invoice_index_deleted(struct lightningd *ld,
|
||||
enum invoice_status state,
|
||||
const struct json_escape *label,
|
||||
const char *invstring)
|
||||
{
|
||||
assert(label);
|
||||
assert(invstring);
|
||||
invoice_index_inc(ld, &state, label, invstring, NULL, WAIT_INDEX_DELETED);
|
||||
}
|
||||
|
||||
/* Fortuntely, dbids start at 1, not 0! */
|
||||
u64 invoice_index_created(struct lightningd *ld,
|
||||
enum invoice_status state,
|
||||
const struct json_escape *label,
|
||||
const char *invstring)
|
||||
{
|
||||
assert(label);
|
||||
assert(invstring);
|
||||
|
||||
return invoice_index_inc(ld, &state, label, invstring, NULL,
|
||||
WAIT_INDEX_CREATED);
|
||||
}
|
||||
|
||||
/* FIXME: We allow missing label here! :( */
|
||||
u64 invoice_index_update_status(struct lightningd *ld,
|
||||
const struct json_escape *label,
|
||||
enum invoice_status state)
|
||||
{
|
||||
return invoice_index_inc(ld, &state, label, NULL, NULL,
|
||||
WAIT_INDEX_UPDATED);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "config.h"
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct db;
|
||||
|
@ -221,4 +222,19 @@ struct invoice_details *invoices_get_details(const tal_t *ctx,
|
|||
struct invoices *invoices,
|
||||
u64 inv_dbid);
|
||||
|
||||
/* Returns the id to use for the new invoice, and increments it. */
|
||||
u64 invoice_index_created(struct lightningd *ld,
|
||||
enum invoice_status state,
|
||||
const struct json_escape *label,
|
||||
const char *invstring);
|
||||
|
||||
/* Returns the current updated_index, and increments it. */
|
||||
u64 invoice_index_update_status(struct lightningd *ld,
|
||||
const struct json_escape *label,
|
||||
enum invoice_status state);
|
||||
|
||||
void invoice_index_deleted(struct lightningd *ld,
|
||||
enum invoice_status state,
|
||||
const struct json_escape *label,
|
||||
const char *invstring);
|
||||
#endif /* LIGHTNING_WALLET_INVOICES_H */
|
||||
|
|
Loading…
Add table
Reference in a new issue