Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoice: add ctlv option. #4320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
invoice: add ctlv option.
This is required if we want to create a "bouncer" plugin (in my copious free time!)

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `invoice` now takes an optional `cltv` parameter.
  • Loading branch information
rustyrussell committed Jan 8, 2021
commit c261f64326ecf76c99818d5dbb6489b5851be165
5 changes: 3 additions & 2 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ def help(self, command=None):
}
return self.call("help", payload)

def invoice(self, msatoshi, label, description, expiry=None, fallbacks=None, preimage=None, exposeprivatechannels=None):
def invoice(self, msatoshi, label, description, expiry=None, fallbacks=None, preimage=None, exposeprivatechannels=None, cltv=None):
"""
Create an invoice for {msatoshi} with {label} and {description} with
optional {expiry} seconds (default 1 week).
Expand All @@ -884,7 +884,8 @@ def invoice(self, msatoshi, label, description, expiry=None, fallbacks=None, pre
"expiry": expiry,
"fallbacks": fallbacks,
"preimage": preimage,
"exposeprivatechannels": exposeprivatechannels
"exposeprivatechannels": exposeprivatechannels,
"cltv": cltv,
}
return self.call("invoice", payload)

Expand Down
8 changes: 6 additions & 2 deletions doc/lightning-invoice.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion doc/lightning-invoice.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SYNOPSIS
--------

**invoice** *msatoshi* *label* *description* \[*expiry*\]
\[*fallbacks*\] \[*preimage*\] \[*exposeprivatechannels*\]
\[*fallbacks*\] \[*preimage*\] \[*exposeprivatechannels*\] \[*cltv*\]

DESCRIPTION
-----------
Expand Down Expand Up @@ -65,6 +65,9 @@ other public channel). The selection uses some randomness to prevent
probing, but favors channels that become more balanced after the
payment.

If specified, *cltv* sets the *min_final_cltv_expiry* for the invoice.
Otherwise, it's set to the parameter **cltv-final**.

RETURN VALUE
------------

Expand Down
5 changes: 4 additions & 1 deletion lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,7 @@ static struct command_result *json_invoice(struct command *cmd,
struct sha256 rhash;
struct secret payment_secret;
struct preimage *preimage;
u32 *cltv;
#if DEVELOPER
const jsmntok_t *routes;
#endif
Expand All @@ -1022,6 +1023,8 @@ static struct command_result *json_invoice(struct command *cmd,
p_opt("preimage", param_preimage, &preimage),
p_opt("exposeprivatechannels", param_chanhints,
&info->chanhints),
p_opt_def("cltv", param_number, &cltv,
cmd->ld->config.cltv_final),
#if DEVELOPER
p_opt("dev-routes", param_array, &routes),
#endif
Expand Down Expand Up @@ -1081,7 +1084,7 @@ static struct command_result *json_invoice(struct command *cmd,
info->b11->timestamp = time_now().ts.tv_sec;
info->b11->payment_hash = rhash;
info->b11->receiver_id = cmd->ld->id;
info->b11->min_final_cltv_expiry = cmd->ld->config.cltv_final;
info->b11->min_final_cltv_expiry = *cltv;
info->b11->expiry = *expiry;
info->b11->description = tal_steal(info->b11, desc_val);
info->b11->description_hash = NULL;
Expand Down
6 changes: 6 additions & 0 deletions tests/test_invoices.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def test_invoice(node_factory, chainparams):
assert b11['fallbacks'][0]['type'] == 'P2WPKH'
assert b11['fallbacks'][1]['addr'] == addr2
assert b11['fallbacks'][1]['type'] == 'P2SH'
assert b11['min_final_cltv_expiry'] == 5
# There's no incoming channel, so no routeboost
assert 'routes' not in b11
assert 'warning_capacity' in inv
Expand Down Expand Up @@ -58,6 +59,11 @@ def test_invoice(node_factory, chainparams):
l2.rpc.invoice(4294967295 + 1, 'inv3', '?')
l2.rpc.invoice(4294967295, 'inv3', '?')

# Test cltv option.
inv = l1.rpc.invoice(123000, 'label3', 'description', '3700', cltv=99)
b11 = l1.rpc.decodepay(inv['bolt11'])
assert b11['min_final_cltv_expiry'] == 99


def test_invoice_zeroval(node_factory):
"""A zero value invoice is unpayable, did you mean 'any'?"""
Expand Down