plugins/offers: neaten fetchinvoice integration.

We already parse some fields, so hand them directly rather than
having fetchinvoice behave as if it's a raw hook.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-07-17 12:53:24 +09:30 committed by Vincenzo Palazzo
parent a782ea75b5
commit d664d52342
3 changed files with 39 additions and 37 deletions

View File

@ -333,34 +333,21 @@ badinv:
return command_hook_success(cmd);
}
struct command_result *recv_modern_onion_message(struct command *cmd,
const char *buf,
const jsmntok_t *params)
struct command_result *handle_invoice_onion_message(struct command *cmd,
const char *buf,
const jsmntok_t *om,
const struct secret *pathsecret)
{
const jsmntok_t *om, *secrettok;
struct sent *sent;
struct secret pathsecret;
struct command_result *err;
om = json_get_member(buf, params, "onion_message");
secrettok = json_get_member(buf, om, "pathsecret");
if (!secrettok)
sent = find_sent_by_secret(pathsecret);
if (!sent)
return NULL;
json_to_secret(buf, secrettok, &pathsecret);
sent = find_sent_by_secret(&pathsecret);
if (!sent) {
plugin_log(cmd->plugin, LOG_DBG,
"No match for modern onion %.*s",
json_tok_full_len(om),
json_tok_full(buf, om));
return NULL;
}
plugin_log(cmd->plugin, LOG_DBG, "Received modern onion message: %.*s",
json_tok_full_len(params),
json_tok_full(buf, params));
plugin_log(cmd->plugin, LOG_DBG, "Received onion message reply for invoice_request: %.*s",
json_tok_full_len(om),
json_tok_full(buf, om));
err = handle_error(cmd, sent, buf, om);
if (err)

View File

@ -17,9 +17,13 @@ struct command_result *json_dev_rawrequest(struct command *cmd,
const char *buffer,
const jsmntok_t *params);
struct command_result *recv_modern_onion_message(struct command *cmd,
const char *buf,
const jsmntok_t *params);
/* Returns NULL if this wasn't one of ours. */
struct command_result *handle_invoice_onion_message(struct command *cmd,
const char *buf,
const jsmntok_t *om,
const struct secret *pathsecret);
/* invoice_payment hook */
struct command_result *invoice_payment(struct command *cmd,
const char *buf,
const jsmntok_t *params);

View File

@ -157,23 +157,34 @@ send_onion_reply(struct command *cmd,
return send_outreq(cmd->plugin, req);
}
static struct command_result *onion_message_modern_call(struct command *cmd,
const char *buf,
const jsmntok_t *params)
static struct command_result *onion_message_recv(struct command *cmd,
const char *buf,
const jsmntok_t *params)
{
const jsmntok_t *om, *replytok, *invreqtok, *invtok;
const jsmntok_t *om, *secrettok, *replytok, *invreqtok, *invtok;
struct blinded_path *reply_path = NULL;
struct command_result *res;
struct secret *secret;
if (!offers_enabled)
return command_hook_success(cmd);
/* FIXME: unify parsing! */
res = recv_modern_onion_message(cmd, buf, params);
if (res)
return res;
om = json_get_member(buf, params, "onion_message");
secrettok = json_get_member(buf, om, "pathsecret");
if (secrettok) {
secret = tal(tmpctx, struct secret);
json_to_secret(buf, secrettok, secret);
} else
secret = NULL;
/* Might be reply for fetchinvoice (which always has a secret,
* so we can tell it's a response). */
if (secret) {
struct command_result *res;
res = handle_invoice_onion_message(cmd, buf, om, secret);
if (res)
return res;
}
replytok = json_get_member(buf, om, "reply_blindedpath");
if (replytok) {
reply_path = json_to_blinded_path(cmd, buf, replytok);
@ -208,11 +219,11 @@ static struct command_result *onion_message_modern_call(struct command *cmd,
static const struct plugin_hook hooks[] = {
{
"onion_message_recv",
onion_message_modern_call
onion_message_recv
},
{
"onion_message_recv_secret",
onion_message_modern_call
onion_message_recv
},
{
"invoice_payment",