mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
libplugin: Add features to plugin_main and getmanifest
This commit is contained in:
committed by
Rusty Russell
parent
59567dc04b
commit
e03acd9663
@@ -88,7 +88,7 @@ static const struct plugin_command commands[] = { {
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setup_locale();
|
setup_locale();
|
||||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, commands, ARRAY_SIZE(commands),
|
||||||
NULL, 0, NULL, 0,
|
NULL, 0, NULL, 0,
|
||||||
plugin_option("autocleaninvoice-cycle",
|
plugin_option("autocleaninvoice-cycle",
|
||||||
"string",
|
"string",
|
||||||
|
|||||||
@@ -947,7 +947,7 @@ int main(int argc, char *argv[])
|
|||||||
bitcoind->rpcport = NULL;
|
bitcoind->rpcport = NULL;
|
||||||
bitcoind->max_fee_multiplier = 10;
|
bitcoind->max_fee_multiplier = 10;
|
||||||
|
|
||||||
plugin_main(argv, init, PLUGIN_STATIC, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_STATIC, NULL, commands, ARRAY_SIZE(commands),
|
||||||
NULL, 0, NULL, 0,
|
NULL, 0, NULL, 0,
|
||||||
plugin_option("bitcoin-datadir",
|
plugin_option("bitcoin-datadir",
|
||||||
"string",
|
"string",
|
||||||
|
|||||||
@@ -446,6 +446,6 @@ static const struct plugin_command commands[] = { {
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setup_locale();
|
setup_locale();
|
||||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, commands,
|
||||||
NULL, 0, NULL, 0, NULL);
|
ARRAY_SIZE(commands), NULL, 0, NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,4 +131,7 @@ int main(int argc, char *argv[])
|
|||||||
setup_locale();
|
setup_locale();
|
||||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
||||||
NULL, 0, hooks, ARRAY_SIZE(hooks), NULL);
|
NULL, 0, hooks, ARRAY_SIZE(hooks), NULL);
|
||||||
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, commands,
|
||||||
|
ARRAY_SIZE(commands), NULL, 0, hooks, ARRAY_SIZE(hooks),
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
#include <ccan/read_write_all/read_write_all.h>
|
#include <ccan/read_write_all/read_write_all.h>
|
||||||
#include <ccan/tal/str/str.h>
|
#include <ccan/tal/str/str.h>
|
||||||
#include <common/daemon.h>
|
#include <common/daemon.h>
|
||||||
#include <common/features.h>
|
|
||||||
#include <common/json_stream.h>
|
#include <common/json_stream.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -86,7 +85,6 @@ struct plugin {
|
|||||||
struct feature_set *our_features;
|
struct feature_set *our_features;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* command_result is mainly used as a compile-time check to encourage you
|
/* command_result is mainly used as a compile-time check to encourage you
|
||||||
* to return as soon as you get one (and not risk use-after-free of command).
|
* to return as soon as you get one (and not risk use-after-free of command).
|
||||||
* Here we use two values: complete (cmd freed) and pending (still going) */
|
* Here we use two values: complete (cmd freed) and pending (still going) */
|
||||||
@@ -605,6 +603,18 @@ handle_getmanifest(struct command *getmanifest_cmd)
|
|||||||
json_add_string(params, NULL, p->hook_subs[i].name);
|
json_add_string(params, NULL, p->hook_subs[i].name);
|
||||||
json_array_end(params);
|
json_array_end(params);
|
||||||
|
|
||||||
|
if (p->our_features != NULL) {
|
||||||
|
json_object_start(params, "features");
|
||||||
|
for (size_t i = 0; i < NUM_FEATURE_PLACE; i++) {
|
||||||
|
u8 *f = p->our_features->bits[i];
|
||||||
|
const char *fieldname = feature_place_names[i];
|
||||||
|
if (fieldname == NULL)
|
||||||
|
continue;
|
||||||
|
json_add_hex(params, fieldname, f, tal_bytelen(f));
|
||||||
|
}
|
||||||
|
json_object_end(params);
|
||||||
|
}
|
||||||
|
|
||||||
json_add_bool(params, "dynamic", p->restartability == PLUGIN_RESTARTABLE);
|
json_add_bool(params, "dynamic", p->restartability == PLUGIN_RESTARTABLE);
|
||||||
|
|
||||||
return command_finished(getmanifest_cmd, params);
|
return command_finished(getmanifest_cmd, params);
|
||||||
@@ -1151,6 +1161,7 @@ static struct plugin *new_plugin(const tal_t *ctx,
|
|||||||
void (*init)(struct plugin *p,
|
void (*init)(struct plugin *p,
|
||||||
const char *buf, const jsmntok_t *),
|
const char *buf, const jsmntok_t *),
|
||||||
const enum plugin_restartability restartability,
|
const enum plugin_restartability restartability,
|
||||||
|
struct feature_set *features,
|
||||||
const struct plugin_command *commands,
|
const struct plugin_command *commands,
|
||||||
size_t num_commands,
|
size_t num_commands,
|
||||||
const struct plugin_notification *notif_subs,
|
const struct plugin_notification *notif_subs,
|
||||||
@@ -1173,6 +1184,8 @@ static struct plugin *new_plugin(const tal_t *ctx,
|
|||||||
p->rpc_len_read = 0;
|
p->rpc_len_read = 0;
|
||||||
p->next_outreq_id = 0;
|
p->next_outreq_id = 0;
|
||||||
uintmap_init(&p->out_reqs);
|
uintmap_init(&p->out_reqs);
|
||||||
|
|
||||||
|
p->our_features = features;
|
||||||
/* Sync RPC FIXME: maybe go full async ? */
|
/* Sync RPC FIXME: maybe go full async ? */
|
||||||
p->rpc_conn = tal(p, struct rpc_conn);
|
p->rpc_conn = tal(p, struct rpc_conn);
|
||||||
membuf_init(&p->rpc_conn->mb,
|
membuf_init(&p->rpc_conn->mb,
|
||||||
@@ -1210,6 +1223,7 @@ void plugin_main(char *argv[],
|
|||||||
void (*init)(struct plugin *p,
|
void (*init)(struct plugin *p,
|
||||||
const char *buf, const jsmntok_t *),
|
const char *buf, const jsmntok_t *),
|
||||||
const enum plugin_restartability restartability,
|
const enum plugin_restartability restartability,
|
||||||
|
struct feature_set *features,
|
||||||
const struct plugin_command *commands,
|
const struct plugin_command *commands,
|
||||||
size_t num_commands,
|
size_t num_commands,
|
||||||
const struct plugin_notification *notif_subs,
|
const struct plugin_notification *notif_subs,
|
||||||
@@ -1229,8 +1243,8 @@ void plugin_main(char *argv[],
|
|||||||
daemon_setup(argv[0], NULL, NULL);
|
daemon_setup(argv[0], NULL, NULL);
|
||||||
|
|
||||||
va_start(ap, num_hook_subs);
|
va_start(ap, num_hook_subs);
|
||||||
plugin = new_plugin(NULL, init, restartability, commands, num_commands,
|
plugin = new_plugin(NULL, init, restartability, features, commands,
|
||||||
notif_subs, num_notif_subs, hook_subs,
|
num_commands, notif_subs, num_notif_subs, hook_subs,
|
||||||
num_hook_subs, ap);
|
num_hook_subs, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
setup_command_usage(plugin);
|
setup_command_usage(plugin);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <ccan/time/time.h>
|
#include <ccan/time/time.h>
|
||||||
#include <ccan/timer/timer.h>
|
#include <ccan/timer/timer.h>
|
||||||
#include <common/errcode.h>
|
#include <common/errcode.h>
|
||||||
|
#include <common/features.h>
|
||||||
#include <common/json.h>
|
#include <common/json.h>
|
||||||
#include <common/json_command.h>
|
#include <common/json_command.h>
|
||||||
#include <common/json_helpers.h>
|
#include <common/json_helpers.h>
|
||||||
@@ -245,6 +246,7 @@ void NORETURN LAST_ARG_NULL plugin_main(char *argv[],
|
|||||||
void (*init)(struct plugin *p,
|
void (*init)(struct plugin *p,
|
||||||
const char *buf, const jsmntok_t *),
|
const char *buf, const jsmntok_t *),
|
||||||
const enum plugin_restartability restartability,
|
const enum plugin_restartability restartability,
|
||||||
|
struct feature_set *features,
|
||||||
const struct plugin_command *commands,
|
const struct plugin_command *commands,
|
||||||
size_t num_commands,
|
size_t num_commands,
|
||||||
const struct plugin_notification *notif_subs,
|
const struct plugin_notification *notif_subs,
|
||||||
|
|||||||
@@ -1712,6 +1712,6 @@ static const struct plugin_command commands[] = { {
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setup_locale();
|
setup_locale();
|
||||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, commands,
|
||||||
NULL, 0, NULL, 0, NULL);
|
ARRAY_SIZE(commands), NULL, 0, NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ static const struct plugin_notification notifs[] = { {
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
setup_locale();
|
setup_locale();
|
||||||
plugin_main(argv, init, PLUGIN_RESTARTABLE, commands, ARRAY_SIZE(commands),
|
plugin_main(argv, init, PLUGIN_RESTARTABLE, NULL, commands, ARRAY_SIZE(commands),
|
||||||
notifs, ARRAY_SIZE(notifs), hooks, ARRAY_SIZE(hooks),
|
notifs, ARRAY_SIZE(notifs), hooks, ARRAY_SIZE(hooks),
|
||||||
plugin_option("name",
|
plugin_option("name",
|
||||||
"string",
|
"string",
|
||||||
|
|||||||
Reference in New Issue
Block a user