mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
feat: make custommsg hook chainable
Changelog-Changed: custommsg hook is now chainable
This commit is contained in:
parent
a5f16ab5b1
commit
8e71c7a1f1
@ -2410,10 +2410,28 @@ struct custommsg_payload {
|
||||
const u8 *msg;
|
||||
};
|
||||
|
||||
static void custommsg_callback(struct custommsg_payload *payload STEALS,
|
||||
static bool custommsg_cb(struct custommsg_payload *payload,
|
||||
const char *buffer, const jsmntok_t *toks)
|
||||
{
|
||||
tal_free(payload);
|
||||
const jsmntok_t *t_res;
|
||||
|
||||
if (!toks || !buffer)
|
||||
return true;
|
||||
|
||||
t_res = json_get_member(buffer, toks, "result");
|
||||
|
||||
/* fail */
|
||||
if (!t_res || !json_tok_streq(buffer, t_res, "continue"))
|
||||
fatal("Plugin returned an invalid response to the "
|
||||
"custommsg hook: %s", buffer);
|
||||
|
||||
/* call next hook */
|
||||
return true;
|
||||
}
|
||||
|
||||
static void custommsg_final(struct custommsg_payload *payload STEALS)
|
||||
{
|
||||
tal_steal(tmpctx, payload);
|
||||
}
|
||||
|
||||
static void custommsg_payload_serialize(struct custommsg_payload *payload,
|
||||
@ -2423,8 +2441,9 @@ static void custommsg_payload_serialize(struct custommsg_payload *payload,
|
||||
json_add_node_id(stream, "peer_id", &payload->peer_id);
|
||||
}
|
||||
|
||||
REGISTER_SINGLE_PLUGIN_HOOK(custommsg,
|
||||
custommsg_callback,
|
||||
REGISTER_PLUGIN_HOOK(custommsg,
|
||||
custommsg_cb,
|
||||
custommsg_final,
|
||||
custommsg_payload_serialize,
|
||||
struct custommsg_payload *);
|
||||
|
||||
|
@ -10,6 +10,7 @@ def on_custommsg(peer_id, message, plugin, **kwargs):
|
||||
msg=message,
|
||||
peer_id=peer_id
|
||||
))
|
||||
return {'result': 'continue'}
|
||||
|
||||
|
||||
plugin.run()
|
||||
|
Loading…
Reference in New Issue
Block a user