2018-11-17 15:18:34 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-02-11 23:04:21 +01:00
|
|
|
from pyln.client import Plugin
|
2019-01-03 19:49:31 +01:00
|
|
|
import time
|
2018-11-17 15:18:34 +01:00
|
|
|
|
2019-04-15 14:21:35 +02:00
|
|
|
plugin = Plugin()
|
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
|
|
|
|
2020-04-10 00:47:01 +02: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 11:55:42 +01:00
|
|
|
@plugin.init()
|
2019-08-05 02:19:48 +02:00
|
|
|
def init(options, configuration, plugin, **kwargs):
|
2018-12-10 16:38:36 +01:00
|
|
|
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-08-05 02:19:48 +02:00
|
|
|
def on_connect(plugin, id, address, **kwargs):
|
2018-12-13 17:35:01 +01:00
|
|
|
plugin.log("Received connect event for peer {}".format(id))
|
|
|
|
|
|
|
|
|
|
|
|
@plugin.subscribe("disconnect")
|
2019-08-05 02:19:48 +02:00
|
|
|
def on_disconnect(plugin, id, **kwargs):
|
2018-12-13 17:35:01 +01:00
|
|
|
plugin.log("Received disconnect event for peer {}".format(id))
|
|
|
|
|
|
|
|
|
2019-07-21 14:08:33 +02:00
|
|
|
@plugin.subscribe("invoice_payment")
|
2019-08-05 02:19:48 +02:00
|
|
|
def on_payment(plugin, invoice_payment, **kwargs):
|
2019-07-21 14:08:33 +02:00
|
|
|
plugin.log("Received invoice_payment event for label {}, preimage {},"
|
|
|
|
" and amount of {}".format(invoice_payment.get("label"),
|
|
|
|
invoice_payment.get("preimage"),
|
|
|
|
invoice_payment.get("msat")))
|
|
|
|
|
|
|
|
|
2020-04-21 03:04:01 +02:00
|
|
|
@plugin.subscribe("invoice_creation")
|
|
|
|
def on_invoice_creation(plugin, invoice_creation, **kwargs):
|
|
|
|
plugin.log("Received invoice_creation event for label {}, preimage {},"
|
|
|
|
" and amount of {}".format(invoice_creation.get("label"),
|
|
|
|
invoice_creation.get("preimage"),
|
|
|
|
invoice_creation.get("msat")))
|
|
|
|
|
|
|
|
|
2019-01-03 19:49:31 +01:00
|
|
|
@plugin.hook("htlc_accepted")
|
2019-08-05 02:19:48 +02:00
|
|
|
def on_htlc_accepted(onion, htlc, plugin, **kwargs):
|
2019-01-03 19:49:31 +01:00
|
|
|
plugin.log('on_htlc_accepted called')
|
|
|
|
time.sleep(20)
|
2019-01-09 16:12:35 +01:00
|
|
|
return {'result': 'continue'}
|
2019-01-03 19:49:31 +01:00
|
|
|
|
|
|
|
|
2018-12-10 16:38:36 +01:00
|
|
|
plugin.add_option('greeting', 'Hello', 'The greeting I should use.')
|
|
|
|
plugin.run()
|