mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
plugins/offers: add code to catch invoice_request onion messages.
We prepare an invoice, but there's no code to send an error reply yet (future patch). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
08e110b568
commit
9d75fbe237
@@ -1,11 +1,41 @@
|
||||
/* This plugin covers both sending and receiving offers */
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <plugins/libplugin.h>
|
||||
#include <plugins/offers_invreq_hook.h>
|
||||
#include <plugins/offers_offer.h>
|
||||
|
||||
struct pubkey32 id;
|
||||
u32 cltv_final;
|
||||
|
||||
static struct command_result *onion_message_call(struct command *cmd,
|
||||
const char *buf,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
const jsmntok_t *om, *invreqtok;
|
||||
|
||||
om = json_get_member(buf, params, "onion_message");
|
||||
|
||||
invreqtok = json_get_member(buf, om, "invoice_request");
|
||||
if (invreqtok) {
|
||||
const jsmntok_t *replytok;
|
||||
|
||||
replytok = json_get_member(buf, om, "reply_path");
|
||||
if (replytok && replytok->size > 0)
|
||||
return handle_invoice_request(cmd, buf,
|
||||
invreqtok, replytok);
|
||||
else
|
||||
plugin_log(cmd->plugin, LOG_DBG,
|
||||
"invoice_request without reply_path");
|
||||
}
|
||||
|
||||
return command_hook_success(cmd);
|
||||
}
|
||||
|
||||
static const struct plugin_hook hooks[] = {
|
||||
{
|
||||
"onion_message",
|
||||
onion_message_call
|
||||
},
|
||||
};
|
||||
|
||||
static void init(struct plugin *p,
|
||||
@@ -24,6 +54,12 @@ static void init(struct plugin *p,
|
||||
if (secp256k1_xonly_pubkey_from_pubkey(secp256k1_ctx, &id.pubkey,
|
||||
NULL, &k.pubkey) != 1)
|
||||
abort();
|
||||
|
||||
field =
|
||||
rpc_delve(tmpctx, p, "listconfigs",
|
||||
take(json_out_obj(NULL, "config", "cltv-final")),
|
||||
".cltv-final");
|
||||
cltv_final = atoi(field);
|
||||
}
|
||||
|
||||
static const struct plugin_command commands[] = {
|
||||
@@ -40,6 +76,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
setup_locale();
|
||||
|
||||
/* We deal in UTC; mktime() uses local time */
|
||||
setenv("TZ", "", 1);
|
||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, true, NULL, commands,
|
||||
ARRAY_SIZE(commands), NULL, 0, hooks, ARRAY_SIZE(hooks),
|
||||
NULL);
|
||||
|
||||
Reference in New Issue
Block a user