plugin/offers: add inject_onionmessage helper.

This will obsolete the existing calls to RPC "sendonionmessage", but
we transition by introducing it separately.  It's designed to work with
the common/onion_message routines and "injectonionmessage".

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 eee7344bf2
commit 8c81d6a0b9
3 changed files with 60 additions and 1 deletions

View File

@ -208,7 +208,7 @@ $(PLUGIN_KEYSEND_OBJS): $(PLUGIN_PAY_LIB_HEADER)
plugins/spenderp: bitcoin/block.o bitcoin/preimage.o bitcoin/psbt.o common/psbt_open.o common/json_channel_type.o common/channel_type.o common/features.o wire/peer_wiregen.o $(PLUGIN_SPENDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS)
plugins/offers: $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/addr.o common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o common/blindedpath.o common/invoice_path_id.o common/blinding.o common/hmac.o common/json_blinded_path.o common/gossmap.o common/fp16.o $(JSMN_OBJS) common/dijkstra.o common/route.o common/gossmods_listpeerchannels.o
plugins/offers: $(PLUGIN_OFFERS_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) common/addr.o common/bolt12.o common/bolt12_merkle.o common/bolt11_json.o common/iso4217.o $(WIRE_OBJS) $(WIRE_BOLT12_OBJS) bitcoin/block.o common/channel_id.o bitcoin/preimage.o common/blindedpath.o common/invoice_path_id.o common/blinding.o common/hmac.o common/json_blinded_path.o common/gossmap.o common/fp16.o $(JSMN_OBJS) common/dijkstra.o common/route.o common/gossmods_listpeerchannels.o common/onion_message.o
plugins/funder: bitcoin/psbt.o common/psbt_open.o $(PLUGIN_FUNDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS)

View File

@ -17,6 +17,7 @@
#include <common/json_param.h>
#include <common/json_stream.h>
#include <common/memleak.h>
#include <common/onion_message.h>
#include <errno.h>
#include <plugins/fetchinvoice.h>
#include <plugins/offers.h>
@ -109,6 +110,35 @@ bool convert_to_scidd(struct command *cmd,
return true;
}
struct command_result *
inject_onionmessage_(struct command *cmd,
const struct onion_message *omsg,
struct command_result *(*cb)(struct command *command,
const char *buf,
const jsmntok_t *result,
void *arg),
struct command_result *(*errcb)(struct command *command,
const char *buf,
const jsmntok_t *result,
void *arg),
void *arg)
{
struct out_req *req;
req = jsonrpc_request_start(cmd->plugin, cmd, "injectonionmessage",
cb, errcb, arg);
json_add_pubkey(req->js, "blinding", &omsg->first_blinding);
json_array_start(req->js, "hops");
for (size_t i = 0; i < tal_count(omsg->hops); i++) {
json_object_start(req->js, NULL);
json_add_pubkey(req->js, "id", &omsg->hops[i]->pubkey);
json_add_hex_talarr(req->js, "tlv", omsg->hops[i]->raw_payload);
json_object_end(req->js);
}
json_array_end(req->js);
return send_outreq(cmd->plugin, req);
}
struct command_result *
send_onion_reply(struct command *cmd,
struct blinded_path *reply_path,

View File

@ -4,6 +4,7 @@
struct command_result;
struct command;
struct onion_message;
struct plugin;
/* This is me. */
@ -29,6 +30,34 @@ send_onion_reply(struct command *cmd,
struct blinded_path *reply_path,
struct tlv_onionmsg_tlv *payload);
/* Helper to send an onion message */
#define inject_onionmessage(cmd, omsg, success, fail, arg) \
inject_onionmessage_((cmd), (omsg), \
typesafe_cb_preargs(struct command_result *, void *, \
(success), (arg), \
struct command *, \
const char *, \
const jsmntok_t *), \
typesafe_cb_preargs(struct command_result *, void *, \
(fail), (arg), \
struct command *, \
const char *, \
const jsmntok_t *), \
(arg))
struct command_result *
inject_onionmessage_(struct command *cmd,
const struct onion_message *omsg,
struct command_result *(*cb)(struct command *command,
const char *buf,
const jsmntok_t *result,
void *arg),
struct command_result *(*errcb)(struct command *command,
const char *buf,
const jsmntok_t *result,
void *arg),
void *arg);
/* Get the (latest) gossmap */
struct gossmap *get_gossmap(struct plugin *plugin);
#endif /* LIGHTNING_PLUGINS_OFFERS_H */