core-lightning/contrib/plugins/helloworld.py
Rusty Russell 0c89fc5d70 pylightning: use different decoration for init msg.
The next patch wants to decorate the methods with a compulsory
'usage' option, which doesn't make sense for init.  So I wanted
to change the init to its own decoration.

Made-to-work-by: @cdecker
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2019-02-07 20:33:50 +00:00

39 lines
897 B
Python
Executable File

#!/usr/bin/env python3
from lightning import Plugin
plugin = Plugin(autopatch=True)
@plugin.method("hello")
def hello(plugin, name="world"):
"""This is the documentation string for the hello-function.
It gets reported as the description when registering the function
as a method with `lightningd`.
"""
greeting = plugin.get_option('greeting')
s = '{} {}'.format(greeting, name)
plugin.log(s)
return s
@plugin.init()
def init(options, configuration, plugin):
plugin.log("Plugin helloworld.py initialized")
@plugin.subscribe("connect")
def on_connect(plugin, id, address):
plugin.log("Received connect event for peer {}".format(id))
@plugin.subscribe("disconnect")
def on_disconnect(plugin, id):
plugin.log("Received disconnect event for peer {}".format(id))
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
plugin.run()