Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin args enhancements #4278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/private_channel_announcement.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <bitcoin/pubkey.h>
#include <common/node_id.h>
#include <common/private_channel_announcement.h>
#include <wire/peer_wiregen.h>
#include <wire/peer_wire.h>

const u8 *private_channel_announcement(const tal_t *ctx,
const struct short_channel_id *scid,
Expand Down
5 changes: 3 additions & 2 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,14 +1014,15 @@ def ping(self, peer_id, length=128, pongbytes=128):
}
return self.call("ping", payload)

def plugin_start(self, plugin):
def plugin_start(self, plugin, **kwargs):
"""
Adds a plugin to lightningd.
"""
payload = {
"subcommand": "start",
"plugin": plugin
"plugin": plugin,
}
payload.update({k: v for k, v in kwargs.items()})
return self.call("plugin", payload)

def plugin_startdir(self, directory):
Expand Down
4 changes: 3 additions & 1 deletion contrib/pyln-client/pyln/client/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ def decorator(f: Callable[..., None]) -> Callable[..., None]:

def add_option(self, name: str, default: Optional[str],
description: Optional[str],
opt_type: str = "string", deprecated: bool = False) -> None:
opt_type: str = "string", deprecated: bool = False,
multi: bool = False) -> None:
"""Add an option that we'd like to register with lightningd.

Needs to be called before `Plugin.run`, otherwise we might not
Expand All @@ -349,6 +350,7 @@ def add_option(self, name: str, default: Optional[str],
'description': description,
'type': opt_type,
'value': None,
'multi': multi,
'deprecated': deprecated,
}

Expand Down
14 changes: 13 additions & 1 deletion doc/PLUGINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ There are currently four supported option 'types':
- int: parsed as a signed integer (64-bit)
- flag: no-arg flag option. Is boolean under the hood. Defaults to false.

In addition, string and int types can specify `"multi": true` to indicate
they can be specified multiple times. These will always be represented in
`init` as a (possibly empty) JSON array.

Nota bene: if a `flag` type option is not set, it will not appear
in the options set that is passed to the plugin.

Expand Down Expand Up @@ -187,6 +191,13 @@ Here's an example option set, as sent in response to `getmanifest`
"type": "int",
"default": 6666,
"description": "Port to use to connect to 3rd-party service"
},
{
"name": "number",
"type": "int",
"default": 0,
"description": "Another number to add",
"multi": true
}
],
```
Expand All @@ -201,7 +212,8 @@ simple JSON object containing the options:
```json
{
"options": {
"greeting": "World"
"greeting": "World",
"number": [0]
},
"configuration": {
"lightning-dir": "/home/user/.lightning/testnet",
Expand Down
9 changes: 5 additions & 4 deletions doc/lightning-plugin.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions doc/lightning-plugin.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ restart lightningd. It takes 1 to 3 parameters: a command
optionally one or two parameters which describes the plugin on which the
action has to be taken.

The *start* command takes a path as the first parameter and will load the
plugin available from this path. It will wait for the plugin to complete
the handshake with `lightningd` for 20 seconds at the most.
The *start* command takes a path as the first parameter and will load
the plugin available from this path. Any additional parameters are
passed to the plugin. It will wait for the plugin to complete the
handshake with `lightningd` for 20 seconds at the most.

The *stop* command takes a plugin name as parameter. It will kill and
unload the specified plugin.
Expand Down
4 changes: 2 additions & 2 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static char *opt_add_plugin(const char *arg, struct lightningd *ld)
log_info(ld->log, "%s: disabled via disable-plugin", arg);
return NULL;
}
plugin_register(ld->plugins, arg, NULL, false);
plugin_register(ld->plugins, arg, NULL, false, NULL, NULL);
return NULL;
}

Expand All @@ -375,7 +375,7 @@ static char *opt_important_plugin(const char *arg, struct lightningd *ld)
log_info(ld->log, "%s: disabled via disable-plugin", arg);
return NULL;
}
plugin_register(ld->plugins, arg, NULL, true);
plugin_register(ld->plugins, arg, NULL, true, NULL, NULL);
return NULL;
}

Expand Down
Loading