mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-04 11:08:03 +01:00
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:
parent
bf4d9e30d2
commit
9784fa816f
3 changed files with 7 additions and 31 deletions
|
@ -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
|
true as described below). It must be UTF-8, and cannot use *\\u* JSON
|
||||||
escape codes.
|
escape codes.
|
||||||
|
|
||||||
The *expiry* is optionally the time the invoice is valid for; without a
|
The *expiry* is optionally the time the invoice is valid for, in seconds.
|
||||||
suffix it is interpreted as seconds, otherwise suffixes *s*, *m*, *h*,
|
If no value is provided the default of 604800 (1 week) is used.
|
||||||
*d*, *w* indicate seconds, minutes, hours, days and weeks respectively.
|
|
||||||
If no value is provided the default of 604800 (1w) is used.
|
|
||||||
|
|
||||||
The *fallbacks* array is one or more fallback addresses to include in
|
The *fallbacks* array is one or more fallback addresses to include in
|
||||||
the invoice (in order from most-preferred to least): note that these
|
the invoice (in order from most-preferred to least): note that these
|
||||||
|
|
|
@ -1035,6 +1035,9 @@ static struct command_result *param_time(struct command *cmd, const char *name,
|
||||||
{ 'd', 24*60*60 },
|
{ 'd', 24*60*60 },
|
||||||
{ 'w', 7*24*60*60 } };
|
{ 'w', 7*24*60*60 } };
|
||||||
|
|
||||||
|
if (!deprecated_apis)
|
||||||
|
return param_u64(cmd, name, buffer, tok, secs);
|
||||||
|
|
||||||
mul = 1;
|
mul = 1;
|
||||||
if (timetok.end == timetok.start)
|
if (timetok.end == timetok.start)
|
||||||
s = '\0';
|
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,
|
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,
|
static struct command_result *param_chanhints(struct command *cmd,
|
||||||
|
|
|
@ -437,37 +437,12 @@ def test_invoice_expiry(node_factory, executor):
|
||||||
# all invoices are expired and should be deleted
|
# all invoices are expired and should be deleted
|
||||||
assert len(l2.rpc.listinvoices()['invoices']) == 0
|
assert len(l2.rpc.listinvoices()['invoices']) == 0
|
||||||
|
|
||||||
# Test expiry suffixes.
|
|
||||||
start = int(time.time())
|
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())
|
end = int(time.time())
|
||||||
expiry = only_one(l2.rpc.listinvoices('inv_s')['invoices'])['expires_at']
|
expiry = only_one(l2.rpc.listinvoices('inv_s')['invoices'])['expires_at']
|
||||||
assert expiry >= start + 1 and expiry <= end + 1
|
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")
|
@pytest.mark.developer("Too slow without --dev-fast-gossip")
|
||||||
def test_waitinvoice(node_factory, executor):
|
def test_waitinvoice(node_factory, executor):
|
||||||
|
|
Loading…
Add table
Reference in a new issue