Skip to content

Commit

Permalink
WIP CLN plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
223880 committed Sep 9, 2024
1 parent f12064c commit bcae3d5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
- [x] Add more info to the Bot
- [ ] APIs
- [ ] LDK & CLN support
- [ ] DVMs
- [ ] CLN plugin
- [x] DVMs [WIP]
- [x] CLN plugin [WIP]
63 changes: 63 additions & 0 deletions cln_plugin
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit bcae3d5

Please sign in to comment.