diff --git a/contrib/plugins/helloworld.py b/contrib/plugins/helloworld.py index 335b01207..e7987329c 100755 --- a/contrib/plugins/helloworld.py +++ b/contrib/plugins/helloworld.py @@ -34,6 +34,14 @@ def on_disconnect(plugin, id): plugin.log("Received disconnect event for peer {}".format(id)) +@plugin.subscribe("invoice_payment") +def on_payment(plugin, invoice_payment): + 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"))) + + @plugin.hook("htlc_accepted") def on_htlc_accepted(onion, htlc, plugin): plugin.log('on_htlc_accepted called') diff --git a/tests/test_plugin.py b/tests/test_plugin.py index ac3648956..d51e4fbef 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -476,3 +476,21 @@ def test_warning_notification(node_factory): l1.daemon.wait_for_log('plugin-pretend_badlog.py time: *') l1.daemon.wait_for_log('plugin-pretend_badlog.py source: plugin-pretend_badlog.py') l1.daemon.wait_for_log('plugin-pretend_badlog.py log: Test warning notification\\(for broken event\\)') + + +def test_invoice_payment_notification(node_factory): + """ + Test the 'invoice_payment' notification + """ + opts = [{}, {"plugin": "contrib/plugins/helloworld.py"}] + l1, l2 = node_factory.line_graph(2, opts=opts) + + msats = 12345 + preimage = '1' * 64 + label = "a_descriptive_label" + inv1 = l2.rpc.invoice(msats, label, 'description', preimage=preimage) + l1.rpc.pay(inv1['bolt11']) + + l2.daemon.wait_for_log(r"Received invoice_payment event for label {}," + " preimage {}, and amount of {}msat" + .format(label, preimage, msats))