mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 01:43:36 +01:00
offers: add self-fetchinvoices for offers, and self-pay for the resulting 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>
This commit is contained in:
parent
9faffeb2e6
commit
272d313e05
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user