2018-11-17 14:18:34 +00:00
|
|
|
#!/usr/bin/env python3
|
2020-02-11 22:04:21 +00:00
|
|
|
from pyln.client import Plugin
|
2019-01-03 18:49:31 +00:00
|
|
|
import time
|
2018-11-17 14:18:34 +00:00
|
|
|
|
2019-04-15 13:21:35 +01:00
|
|
|
plugin = Plugin()
|
2018-11-17 14:18:34 +00:00
|
|
|
|
|
|
|
|
2018-12-10 15:38:36 +00:00
|
|
|
@plugin.method("hello")
|
2019-01-02 22:16:56 +00:00
|
|
|
def hello(plugin, name="world"):
|
2018-12-10 15:38:36 +00:00
|
|
|
"""This is the documentation string for the hello-function.
|
2018-11-17 14:18:34 +00:00
|
|
|
|
2018-12-10 15:38:36 +00:00
|
|
|
It gets reported as the description when registering the function
|
|
|
|
as a method with `lightningd`.
|
2018-11-17 14:18:34 +00:00
|
|
|
|
|
|
|
"""
|
2018-12-10 15:38:36 +00:00
|
|
|
greeting = plugin.get_option('greeting')
|
|
|
|
s = '{} {}'.format(greeting, name)
|
|
|
|
plugin.log(s)
|
|
|
|
return s
|
2018-11-17 14:18:34 +00:00
|
|
|
|
2018-11-26 17:47:27 +00:00
|
|
|
|
2020-04-09 23:47:01 +01:00
|
|
|
@plugin.method("bye")
|
|
|
|
def bye(plugin, name, **kwargs):
|
|
|
|
"""This methods requires {name} to be set by the caller !"""
|
|
|
|
return "Bye {}".format(name)
|
|
|
|
|
|
|
|
|
2019-02-04 10:55:42 +00:00
|
|
|
@plugin.init()
|
2019-08-05 01:19:48 +01:00
|
|
|
def init(options, configuration, plugin, **kwargs):
|
2018-12-10 15:38:36 +00:00
|
|
|
plugin.log("Plugin helloworld.py initialized")
|
2018-11-26 18:47:52 +00:00
|
|
|
|
|
|
|
|
2018-12-13 16:35:01 +00:00
|
|
|
@plugin.subscribe("connect")
|
2023-06-29 18:30:30 +01:00
|
|
|
def on_connect(plugin, connect, **kwargs):
|
|
|
|
plugin.log("Received connect event for peer {}".format(connect))
|
2018-12-13 16:35:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
@plugin.subscribe("disconnect")
|
2023-06-29 18:30:30 +01:00
|
|
|
def on_disconnect(plugin, disconnect, **kwargs):
|
|
|
|
plugin.log("Received disconnect event for peer {}".format(disconnect))
|
2018-12-13 16:35:01 +00:00
|
|
|
|
|
|
|
|
2019-07-21 13:08:33 +01:00
|
|
|
@plugin.subscribe("invoice_payment")
|
2019-08-05 01:19:48 +01:00
|
|
|
def on_payment(plugin, invoice_payment, **kwargs):
|
2020-04-22 02:01:57 +01:00
|
|
|
plugin.log("Received invoice_payment event for label {label}, preimage {preimage},"
|
|
|
|
" and amount of {msat}".format(**invoice_payment))
|
2019-07-21 13:08:33 +01:00
|
|
|
|
|
|
|
|
2020-04-21 02:04:01 +01:00
|
|
|
@plugin.subscribe("invoice_creation")
|
|
|
|
def on_invoice_creation(plugin, invoice_creation, **kwargs):
|
2020-04-22 02:01:57 +01:00
|
|
|
plugin.log("Received invoice_creation event for label {label}, preimage {preimage},"
|
|
|
|
" and amount of {msat}".format(**invoice_creation))
|
2020-04-21 02:04:01 +01:00
|
|
|
|
|
|
|
|
2019-01-03 18:49:31 +00:00
|
|
|
@plugin.hook("htlc_accepted")
|
2019-08-05 01:19:48 +01:00
|
|
|
def on_htlc_accepted(onion, htlc, plugin, **kwargs):
|
2019-01-03 18:49:31 +00:00
|
|
|
plugin.log('on_htlc_accepted called')
|
|
|
|
time.sleep(20)
|
2019-01-09 15:12:35 +00:00
|
|
|
return {'result': 'continue'}
|
2019-01-03 18:49:31 +00:00
|
|
|
|
|
|
|
|
2018-12-10 15:38:36 +00:00
|
|
|
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
|
|
|
plugin.run()
|