diff --git a/README.md b/README.md index 3584588..93a7da7 100644 --- a/README.md +++ b/README.md @@ -34,5 +34,5 @@ - [x] Add more info to the Bot - [ ] APIs - [ ] LDK & CLN support -- [ ] DVMs -- [ ] CLN plugin \ No newline at end of file +- [x] DVMs [WIP] +- [x] CLN plugin [WIP] \ No newline at end of file diff --git a/cln_plugin b/cln_plugin new file mode 100644 index 0000000..9aa8298 --- /dev/null +++ b/cln_plugin @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +from pyln.client import Plugin +import time + +plugin = Plugin() + + +@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.method("bye") +def bye(plugin, name, **kwargs): + """This method requires {name} to be set by the caller !""" + return "Bye {}".format(name) + + +@plugin.init() +def init(options, configuration, plugin, **kwargs): + plugin.log("Plugin helloworld.py initialized") + + +@plugin.subscribe("connect") +def on_connect(plugin, id, address, **kwargs): + plugin.log("Received connect event for peer {}".format(id)) + + +@plugin.subscribe("disconnect") +def on_disconnect(plugin, id, **kwargs): + plugin.log("Received disconnect event for peer {}".format(id)) + + +@plugin.subscribe("invoice_payment") +def on_payment(plugin, invoice_payment, **kwargs): + plugin.log("Received invoice_payment event for label {label}, preimage {preimage}," + " and amount of {msat}".format(**invoice_payment)) + + +@plugin.subscribe("invoice_creation") +def on_invoice_creation(plugin, invoice_creation, **kwargs): + plugin.log("Received invoice_creation event for label {label}, preimage {preimage}," + " and amount of {msat}".format(**invoice_creation)) + + +@plugin.hook("htlc_accepted") +def on_htlc_accepted(onion, htlc, plugin, **kwargs): + plugin.log('on_htlc_accepted called') + time.sleep(20) + return {'result': 'continue'} + + +plugin.add_option('greeting', 'Hello', 'The greeting I should use.') +plugin.run() \ No newline at end of file