Skip to content

Commit

Permalink
offers: add self-fetchinvoices for offers, and self-pay for the resul…
Browse files Browse the repository at this point in the history
…ting invoice.

Changelog-Added: offers: we can now self-fetch and self-pay BOLT12 offers and invoices.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

rustyrussell committed Jul 18, 2024
1 parent 9faffeb commit 272d313
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions plugins/establish_onion_path.c
Original file line number Diff line number Diff line change
@@ -215,6 +215,12 @@ struct command_result *establish_onion_path_(struct command *cmd,
struct connect_info *ci = tal(cmd, struct connect_info);
struct out_req *req;

/* Talking to ourselves is trivial. */
if (pubkey_eq(local_id, dst)) {
struct pubkey *path = tal_dup_arr(tmpctx, struct pubkey, local_id, 1, 0);
return success(cmd, path, arg);
}

ci->local_id = *local_id;
ci->dst = *dst;
ci->cb = success;
14 changes: 12 additions & 2 deletions plugins/pay.c
Original file line number Diff line number Diff line change
@@ -1070,8 +1070,18 @@ decrypt_done(struct command *cmd,
tal_hex(tmpctx, encdata));
}

if (tal_count(p->blindedpath->path) == 1)
return command_fail(cmd, LIGHTNINGD, "FIXME: self-pay!");
/* Was this a self-pay? Simply remove blinded path. */
if (tal_count(p->blindedpath->path) == 1) {
p->blindedpath = tal_free(p->blindedpath);
tal_free(p->pay_destination);
p->pay_destination = tal_dup(p, struct node_id, p->route_destination);
/* self-pay will want secret from inside TLV */
if (tal_bytelen(enctlv->path_id) == sizeof(*p->payment_secret)) {
p->payment_secret = tal(p, struct secret);
memcpy(p->payment_secret, enctlv->path_id, sizeof(struct secret));
}
return start_payment(cmd, p);
}

if (!enctlv->short_channel_id && !enctlv->next_node_id) {
return command_fail(cmd, PAY_UNPARSEABLE_ONION,
9 changes: 9 additions & 0 deletions tests/test_pay.py
Original file line number Diff line number Diff line change
@@ -5808,6 +5808,15 @@ def test_offer_path_self(node_factory):
l2.rpc.pay(inv)


def test_offer_selfpay(node_factory):
"""We can fetch an pay our own offer"""
l1 = node_factory.get_node(options={'experimental-offers': None})

offer = l1.rpc.offer(amount='2msat', description='test_offer_path_self')['bolt12']
inv = l1.rpc.fetchinvoice(offer)['invoice']
l1.rpc.pay(inv)


def test_decryptencrypteddata(node_factory):
l1, l2, l3 = node_factory.line_graph(3, fundchannel=False,
opts={'experimental-offers': None})

0 comments on commit 272d313

Please sign in to comment.