Skip to content

Instantly share code, notes, and snippets.

@RCasatta
Last active September 14, 2019 06:32
Show Gist options
  • Save RCasatta/462abf9cfb14b954433234db780f0f2e to your computer and use it in GitHub Desktop.
Save RCasatta/462abf9cfb14b954433234db780f0f2e to your computer and use it in GitHub Desktop.
plugin for c-lightning
#!/usr/bin/env python3
from lightning import Plugin
import uuid
from paramiko import SSHClient
from scp import SCPClient
import io
plugin = Plugin()
@plugin.init()
def init(options, configuration, plugin):
plugin.log("Plugin fresh_invoice initialize")
# @plugin.subscribe("connect")
# def on_connect(plugin, id, address):
@plugin.subscribe("invoice_payment")
def on_invoice_payment(plugin, invoice_payment):
# TODO check if the payed invoice is generated by me, only then generate a new one
plugin.log("fresh_invoice on_invoice_payment")
invoice = plugin.rpc.invoice("any", str(uuid.uuid4()), "donation to OpenTimestamps (Finney)", "52w")['bolt11']
port = int(plugin.options['fresh-invoice-scp-port']['value'])
host = plugin.options['fresh-invoice-scp-host']['value']
user = plugin.options['fresh-invoice-scp-user']['value']
path = plugin.options['fresh-invoice-scp-path']['value']
stream = io.BytesIO()
stream.write(invoice.encode('utf-8'))
stream.seek(0)
ssh = SSHClient()
ssh.load_system_host_keys()
ssh.connect(host, port=port, username=user)
scp = SCPClient(ssh.get_transport())
scp.putfo(stream, path)
plugin.add_option('fresh-invoice-scp-host', 'localhost', 'The host where to scp the invoice')
plugin.add_option('fresh-invoice-scp-port', '22', 'The host port')
plugin.add_option('fresh-invoice-scp-user', 'root', 'The host username')
plugin.add_option('fresh-invoice-scp-path', 'invoice.txt', 'The path of the scp host where to write the invoice')
plugin.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment