lightningd: deprecate invoice expiry suffixes.

Makes types harder, and I've never personally used them.

Changelog-Deprecated: JSON-RPC: `invoice` `expiry` no longer allowed to be a string with suffix, use an integer number of seconds.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-04-01 14:42:45 +10:30
parent bf4d9e30d2
commit 9784fa816f
3 changed files with 7 additions and 31 deletions

View file

@ -33,10 +33,8 @@ viewable by any node you send this invoice to (unless *deschashonly* is
true as described below). It must be UTF-8, and cannot use *\\u* JSON
escape codes.
The *expiry* is optionally the time the invoice is valid for; without a
suffix it is interpreted as seconds, otherwise suffixes *s*, *m*, *h*,
*d*, *w* indicate seconds, minutes, hours, days and weeks respectively.
If no value is provided the default of 604800 (1w) is used.
The *expiry* is optionally the time the invoice is valid for, in seconds.
If no value is provided the default of 604800 (1 week) is used.
The *fallbacks* array is one or more fallback addresses to include in
the invoice (in order from most-preferred to least): note that these

View file

@ -1035,6 +1035,9 @@ static struct command_result *param_time(struct command *cmd, const char *name,
{ 'd', 24*60*60 },
{ 'w', 7*24*60*60 } };
if (!deprecated_apis)
return param_u64(cmd, name, buffer, tok, secs);
mul = 1;
if (timetok.end == timetok.start)
s = '\0';
@ -1059,7 +1062,7 @@ static struct command_result *param_time(struct command *cmd, const char *name,
}
return command_fail_badparam(cmd, name, buffer, tok,
"should be a number with optional {s,m,h,d,w} suffix");
"should be a number");
}
static struct command_result *param_chanhints(struct command *cmd,

View file

@ -437,37 +437,12 @@ def test_invoice_expiry(node_factory, executor):
# all invoices are expired and should be deleted
assert len(l2.rpc.listinvoices()['invoices']) == 0
# Test expiry suffixes.
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_s', description='description', expiry='1s')['bolt11']
inv = l2.rpc.invoice(msatoshi=123000, label='inv_s', description='description', expiry=1)['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_s')['invoices'])['expires_at']
assert expiry >= start + 1 and expiry <= end + 1
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_m', description='description', expiry='1m')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_m')['invoices'])['expires_at']
assert expiry >= start + 60 and expiry <= end + 60
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_h', description='description', expiry='1h')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_h')['invoices'])['expires_at']
assert expiry >= start + 3600 and expiry <= end + 3600
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_d', description='description', expiry='1d')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_d')['invoices'])['expires_at']
assert expiry >= start + 24 * 3600 and expiry <= end + 24 * 3600
start = int(time.time())
inv = l2.rpc.invoice(msatoshi=123000, label='inv_w', description='description', expiry='1w')['bolt11']
end = int(time.time())
expiry = only_one(l2.rpc.listinvoices('inv_w')['invoices'])['expires_at']
assert expiry >= start + 7 * 24 * 3600 and expiry <= end + 7 * 24 * 3600
@pytest.mark.developer("Too slow without --dev-fast-gossip")
def test_waitinvoice(node_factory, executor):