mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
invoices: Add delexpiredinvoice command.
This commit is contained in:
parent
8966a175ee
commit
3b0081aebb
11 changed files with 118 additions and 4 deletions
|
@ -6,6 +6,7 @@ doc-wrongdir:
|
||||||
|
|
||||||
MANPAGES := doc/lightning-cli.1 \
|
MANPAGES := doc/lightning-cli.1 \
|
||||||
doc/lightning-decodepay.7 \
|
doc/lightning-decodepay.7 \
|
||||||
|
doc/lightning-delexpiredinvoice.7 \
|
||||||
doc/lightning-delinvoice.7 \
|
doc/lightning-delinvoice.7 \
|
||||||
doc/lightning-getroute.7 \
|
doc/lightning-getroute.7 \
|
||||||
doc/lightning-invoice.7 \
|
doc/lightning-invoice.7 \
|
||||||
|
|
0
doc/lightning-delexpiredinvoice.7
Normal file
0
doc/lightning-delexpiredinvoice.7
Normal file
35
doc/lightning-delexpiredinvoice.7.txt
Normal file
35
doc/lightning-delexpiredinvoice.7.txt
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
LIGHTNING-DELEXPIREDINVOICE(7)
|
||||||
|
==============================
|
||||||
|
:doctype: manpage
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
lightning-delexpiredinvoice - Protocol for removing expired invoices.
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
--------
|
||||||
|
*delexpiredinvoice* ['maxexpirytime']
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
The *delexpiredinvoice* RPC command removes all invoices that have
|
||||||
|
expired on or before the given 'maxexpirytime'.
|
||||||
|
|
||||||
|
If 'maxexpirytime' is not specified then all expired invoices are
|
||||||
|
deleted.
|
||||||
|
|
||||||
|
RETURN VALUE
|
||||||
|
------------
|
||||||
|
On success, does nothing.
|
||||||
|
|
||||||
|
AUTHOR
|
||||||
|
------
|
||||||
|
ZmnSCPxj <ZmnSCPxj@protonmail.com> is mainly responsible.
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
lightning-delinvoice(7)
|
||||||
|
|
||||||
|
RESOURCES
|
||||||
|
---------
|
||||||
|
Main web site: https://github.com/ElementsProject/lightning
|
|
@ -2,12 +2,12 @@
|
||||||
.\" Title: lightning-delinvoice
|
.\" Title: lightning-delinvoice
|
||||||
.\" Author: [see the "AUTHOR" section]
|
.\" Author: [see the "AUTHOR" section]
|
||||||
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
|
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
|
||||||
.\" Date: 01/18/2018
|
.\" Date: 02/26/2018
|
||||||
.\" Manual: \ \&
|
.\" Manual: \ \&
|
||||||
.\" Source: \ \&
|
.\" Source: \ \&
|
||||||
.\" Language: English
|
.\" Language: English
|
||||||
.\"
|
.\"
|
||||||
.TH "LIGHTNING\-DELINVOIC" "7" "01/18/2018" "\ \&" "\ \&"
|
.TH "LIGHTNING\-DELINVOIC" "7" "02/26/2018" "\ \&" "\ \&"
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
.\" * Define some portability stuff
|
.\" * Define some portability stuff
|
||||||
.\" -----------------------------------------------------------------
|
.\" -----------------------------------------------------------------
|
||||||
|
@ -45,7 +45,7 @@ On success, an invoice description will be returned as per lightning\-listinvoic
|
||||||
Rusty Russell <rusty@rustcorp\&.com\&.au> is mainly responsible\&.
|
Rusty Russell <rusty@rustcorp\&.com\&.au> is mainly responsible\&.
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
.sp
|
.sp
|
||||||
lightning\-listinvoice(7), lightning\-waitinvoice(7), lightning\-invoice(7)\&.
|
lightning\-listinvoice(7), lightning\-waitinvoice(7), lightning\-invoice(7), lightning\-delexpiredinvoice(7)
|
||||||
.SH "RESOURCES"
|
.SH "RESOURCES"
|
||||||
.sp
|
.sp
|
||||||
Main web site: https://github\&.com/ElementsProject/lightning
|
Main web site: https://github\&.com/ElementsProject/lightning
|
||||||
|
|
|
@ -30,7 +30,8 @@ Rusty Russell <rusty@rustcorp.com.au> is mainly responsible.
|
||||||
|
|
||||||
SEE ALSO
|
SEE ALSO
|
||||||
--------
|
--------
|
||||||
lightning-listinvoice(7), lightning-waitinvoice(7), lightning-invoice(7).
|
lightning-listinvoice(7), lightning-waitinvoice(7), lightning-invoice(7),
|
||||||
|
lightning-delexpiredinvoice(7)
|
||||||
|
|
||||||
RESOURCES
|
RESOURCES
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -387,6 +387,42 @@ static const struct json_command delinvoice_command = {
|
||||||
};
|
};
|
||||||
AUTODATA(json_command, &delinvoice_command);
|
AUTODATA(json_command, &delinvoice_command);
|
||||||
|
|
||||||
|
static void json_delexpiredinvoice(struct command *cmd, const char *buffer,
|
||||||
|
const jsmntok_t *params)
|
||||||
|
{
|
||||||
|
jsmntok_t *maxexpirytimetok;
|
||||||
|
u64 maxexpirytime = time_now().ts.tv_sec;
|
||||||
|
struct json_result *result;
|
||||||
|
|
||||||
|
if (!json_get_params(cmd, buffer, params,
|
||||||
|
"?maxexpirytime", &maxexpirytimetok,
|
||||||
|
NULL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxexpirytimetok) {
|
||||||
|
if (!json_tok_u64(buffer, maxexpirytimetok, &maxexpirytime)) {
|
||||||
|
command_fail(cmd, "'%.*s' is not a valid number",
|
||||||
|
maxexpirytimetok->end - maxexpirytimetok->start,
|
||||||
|
buffer + maxexpirytimetok->start);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wallet_invoice_delete_expired(cmd->ld->wallet, maxexpirytime);
|
||||||
|
|
||||||
|
result = new_json_result(cmd);
|
||||||
|
json_object_start(result, NULL);
|
||||||
|
json_object_end(result);
|
||||||
|
command_success(cmd, result);
|
||||||
|
}
|
||||||
|
static const struct json_command delexpiredinvoice_command = {
|
||||||
|
"delexpiredinvoice",
|
||||||
|
json_delexpiredinvoice,
|
||||||
|
"Delete all expired invoices that expired as of given {maxexpirytime} (a UNIX epoch time), or all expired invoices if not specified"
|
||||||
|
};
|
||||||
|
AUTODATA(json_command, &delexpiredinvoice_command);
|
||||||
|
|
||||||
static void json_waitanyinvoice(struct command *cmd,
|
static void json_waitanyinvoice(struct command *cmd,
|
||||||
const char *buffer, const jsmntok_t *params)
|
const char *buffer, const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
|
|
|
@ -384,6 +384,19 @@ bool invoices_delete(struct invoices *invoices,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void invoices_delete_expired(struct invoices *invoices,
|
||||||
|
u64 max_expiry_time)
|
||||||
|
{
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
stmt = db_prepare(invoices->db,
|
||||||
|
"DELETE FROM invoices"
|
||||||
|
" WHERE state = ?"
|
||||||
|
" AND expiry_time <= ?;");
|
||||||
|
sqlite3_bind_int(stmt, 1, EXPIRED);
|
||||||
|
sqlite3_bind_int64(stmt, 2, max_expiry_time);
|
||||||
|
db_exec_prepared(invoices->db, stmt);
|
||||||
|
}
|
||||||
|
|
||||||
bool invoices_iterate(struct invoices *invoices,
|
bool invoices_iterate(struct invoices *invoices,
|
||||||
struct invoice_iterator *it)
|
struct invoice_iterator *it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -101,6 +101,16 @@ bool invoices_find_unpaid(struct invoices *invoices,
|
||||||
bool invoices_delete(struct invoices *invoices,
|
bool invoices_delete(struct invoices *invoices,
|
||||||
struct invoice invoice);
|
struct invoice invoice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* invoices_delete_expired - Delete all expired invoices
|
||||||
|
* with expiration time less than or equal to the given.
|
||||||
|
*
|
||||||
|
* @invoices - the invoice handler.
|
||||||
|
* @max_expiry_time - the maximum expiry time to delete.
|
||||||
|
*/
|
||||||
|
void invoices_delete_expired(struct invoices *invoices,
|
||||||
|
u64 max_expiry_time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invoices_iterate - Iterate over all existing invoices
|
* invoices_iterate - Iterate over all existing invoices
|
||||||
*
|
*
|
||||||
|
|
|
@ -113,6 +113,10 @@ bool invoices_create(struct invoices *invoices UNNEEDED,
|
||||||
bool invoices_delete(struct invoices *invoices UNNEEDED,
|
bool invoices_delete(struct invoices *invoices UNNEEDED,
|
||||||
struct invoice invoice UNNEEDED)
|
struct invoice invoice UNNEEDED)
|
||||||
{ fprintf(stderr, "invoices_delete called!\n"); abort(); }
|
{ fprintf(stderr, "invoices_delete called!\n"); abort(); }
|
||||||
|
/* Generated stub for invoices_delete_expired */
|
||||||
|
void invoices_delete_expired(struct invoices *invoices UNNEEDED,
|
||||||
|
u64 max_expiry_time UNNEEDED)
|
||||||
|
{ fprintf(stderr, "invoices_delete_expired called!\n"); abort(); }
|
||||||
/* Generated stub for invoices_find_by_label */
|
/* Generated stub for invoices_find_by_label */
|
||||||
bool invoices_find_by_label(struct invoices *invoices UNNEEDED,
|
bool invoices_find_by_label(struct invoices *invoices UNNEEDED,
|
||||||
struct invoice *pinvoice UNNEEDED,
|
struct invoice *pinvoice UNNEEDED,
|
||||||
|
|
|
@ -1395,6 +1395,10 @@ bool wallet_invoice_delete(struct wallet *wallet,
|
||||||
{
|
{
|
||||||
return invoices_delete(wallet->invoices, invoice);
|
return invoices_delete(wallet->invoices, invoice);
|
||||||
}
|
}
|
||||||
|
void wallet_invoice_delete_expired(struct wallet *wallet, u64 e)
|
||||||
|
{
|
||||||
|
invoices_delete_expired(wallet->invoices, e);
|
||||||
|
}
|
||||||
bool wallet_invoice_iterate(struct wallet *wallet,
|
bool wallet_invoice_iterate(struct wallet *wallet,
|
||||||
struct invoice_iterator *it)
|
struct invoice_iterator *it)
|
||||||
{
|
{
|
||||||
|
|
|
@ -506,6 +506,16 @@ bool wallet_invoice_find_unpaid(struct wallet *wallet,
|
||||||
bool wallet_invoice_delete(struct wallet *wallet,
|
bool wallet_invoice_delete(struct wallet *wallet,
|
||||||
struct invoice invoice);
|
struct invoice invoice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wallet_invoice_delete_expired - Delete all expired invoices
|
||||||
|
* with expiration time less than or equal to the given.
|
||||||
|
*
|
||||||
|
* @wallet - the wallet to delete invoices from.
|
||||||
|
* @max_expiry_time - the maximum expiry time to delete.
|
||||||
|
*/
|
||||||
|
void wallet_invoice_delete_expired(struct wallet *wallet,
|
||||||
|
u64 max_expiry_time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wallet_invoice_iterate - Iterate over all existing invoices
|
* wallet_invoice_iterate - Iterate over all existing invoices
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue