Skip to content

Instantly share code, notes, and snippets.

@MrHash
Last active November 1, 2022 07:03
Show Gist options
  • Save MrHash/f95652c92a7748d607092386f8a51f3c to your computer and use it in GitHub Desktop.
Save MrHash/f95652c92a7748d607092386f8a51f3c to your computer and use it in GitHub Desktop.
c-lightning hodl invoice plugin example only
#!/usr/bin/env python3
from lightning import Plugin
import json
plugin = Plugin()
heldinvoices = dict()
@plugin.init()
def init(options, configuration, plugin):
plugin.log("Plugin hodl-invoice initialized")
# WARNING: This turns ALL invoices into hodl invoices
@plugin.async_hook("invoice_payment")
def on_invoice_payment(plugin, payment, request):
heldinvoices[payment['label']] = request
@plugin.method("hodlinvoice")
def hodl_invoice(plugin, label):
"""Add an invoice to be held
"""
heldinvoices[label].set_result({})
return json.loads({label: label, message: 'Invoice settled.'})
@plugin.method("settleinvoice")
def settle_invoice(plugin, label):
"""Settle a held invoice
"""
heldinvoices[label].set_result({})
return json.loads({label: label, message: 'Invoice settled.'})
@plugin.method("cancelinvoice")
def cancel_invoice(plugin, label):
"""Cancel a held invoice
"""
heldinvoices[label].set_result({failure_code:8194})
return json.loads({label: label, message: 'Invoice cancelled.'})
plugin.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment