This commit introduces a new field `invoice_msat` to the htlc_accepted hook. If this field is specified it will replace the amount of the invoice that belongs to the payment_hash of the HTLC on internal checks. This is useful in scenarios where we actually expect a smaller amount than initially specified in an invoice. Changelog-Changed: Plugins: `htlc_accepted` hook can now override the expected total amount of the invoice that belongs to the HTLC. Signed-off-by: Peter Neuroth <pet.v.ne@gmail.com>
30 lines
618 B
Python
Executable File
30 lines
618 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""A plugin that overrides the amount of the invoice that belongs to an HTLC."""
|
|
|
|
from pyln.client import Plugin
|
|
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
@plugin.hook("htlc_accepted")
|
|
def on_htlc_accepted(htlc, onion, plugin, **kwargs):
|
|
res = {"result": "continue"}
|
|
if plugin.invoice_msat:
|
|
res["invoice_msat"] = plugin.invoice_msat
|
|
return res
|
|
|
|
|
|
@plugin.method("setinvoicemsat")
|
|
def setinvoicemsat(plugin, msat: int):
|
|
"""Sets invoice_msat for the htlc_accepted response."""
|
|
plugin.invoice_msat = msat
|
|
|
|
|
|
@plugin.init()
|
|
def on_init(**kwargs):
|
|
plugin.invoice_msat = None
|
|
|
|
|
|
plugin.run()
|