2018-11-17 15:18:34 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-12-10 16:38:36 +01:00
|
|
|
from lightning import Plugin
|
2018-11-17 15:18:34 +01:00
|
|
|
|
|
|
|
|
2018-12-10 16:38:36 +01:00
|
|
|
plugin = Plugin(autopatch=True)
|
2018-11-17 15:18:34 +01:00
|
|
|
|
|
|
|
|
2018-12-10 16:38:36 +01:00
|
|
|
@plugin.method("hello")
|
2019-01-02 23:16:56 +01:00
|
|
|
def hello(plugin, name="world"):
|
2018-12-10 16:38:36 +01:00
|
|
|
"""This is the documentation string for the hello-function.
|
2018-11-17 15:18:34 +01:00
|
|
|
|
2018-12-10 16:38:36 +01:00
|
|
|
It gets reported as the description when registering the function
|
|
|
|
as a method with `lightningd`.
|
2018-11-17 15:18:34 +01:00
|
|
|
|
|
|
|
"""
|
2018-12-10 16:38:36 +01:00
|
|
|
greeting = plugin.get_option('greeting')
|
|
|
|
s = '{} {}'.format(greeting, name)
|
|
|
|
plugin.log(s)
|
|
|
|
return s
|
2018-11-17 15:18:34 +01:00
|
|
|
|
2018-11-26 18:47:27 +01:00
|
|
|
|
2019-02-04 11:55:42 +01:00
|
|
|
@plugin.init()
|
2018-12-10 16:38:36 +01:00
|
|
|
def init(options, configuration, plugin):
|
|
|
|
plugin.log("Plugin helloworld.py initialized")
|
2018-11-26 19:47:52 +01:00
|
|
|
|
|
|
|
|
2018-12-13 17:35:01 +01:00
|
|
|
@plugin.subscribe("connect")
|
2019-01-02 23:16:56 +01:00
|
|
|
def on_connect(plugin, id, address):
|
2018-12-13 17:35:01 +01:00
|
|
|
plugin.log("Received connect event for peer {}".format(id))
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.subscribe("disconnect")
|
2019-01-02 23:16:56 +01:00
|
|
|
def on_disconnect(plugin, id):
|
2018-12-13 17:35:01 +01:00
|
|
|
plugin.log("Received disconnect event for peer {}".format(id))
|
|
|
|
|
|
|
|
|
2018-12-10 16:38:36 +01:00
|
|
|
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
|
|
|
plugin.run()
|