plugins/offer: handle receiving an invoice in an onion_message.

And if we have a matching `send_invoice` offer, try to pay it!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2021-01-08 05:06:47 +10:30
parent 6d1fe7e599
commit f2d2db7b4e
4 changed files with 432 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
#include <common/json_stream.h>
#include <plugins/libplugin.h>
#include <plugins/offers.h>
#include <plugins/offers_inv_hook.h>
#include <plugins/offers_invreq_hook.h>
#include <plugins/offers_offer.h>
@@ -75,7 +76,7 @@ static struct command_result *onion_message_call(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
const jsmntok_t *om, *invreqtok;
const jsmntok_t *om, *invreqtok, *invtok;
om = json_get_member(buf, params, "onion_message");
@@ -92,6 +93,14 @@ static struct command_result *onion_message_call(struct command *cmd,
"invoice_request without reply_path");
}
invtok = json_get_member(buf, om, "invoice");
if (invtok) {
const jsmntok_t *replytok;
replytok = json_get_member(buf, om, "reply_path");
return handle_invoice(cmd, buf, invtok, replytok);
}
return command_hook_success(cmd);
}