Browse Source
Make the `htlc_accepted` hook the first chained hook in our repertoire. The plugins are called one after the other in order until we have no more plugins or the HTLC was handled by one of the plugins. If no plugins handles the HTLC we continue to handle it internally like always. Handling in this case means the plugin returns either `{"result": "resolve", ...}` or `{"result": "fail", ...}`. Changelog-Changed: plugin: Multiple plugins can now register for the htlc_accepted hook.travis-debug
committed by
Rusty Russell
4 changed files with 122 additions and 1 deletions
@ -0,0 +1,24 @@ |
|||
#!/usr/bin/env python3 |
|||
from pyln.client import Plugin |
|||
from hashlib import sha256 |
|||
from binascii import hexlify |
|||
|
|||
"""A simple plugin that accepts invoices with "BB"*32 preimages |
|||
""" |
|||
plugin = Plugin() |
|||
|
|||
|
|||
@plugin.hook('htlc_accepted') |
|||
def on_htlc_accepted(htlc, plugin, **kwargs): |
|||
preimage = b"\xBB" * 32 |
|||
payment_hash = sha256(preimage).hexdigest() |
|||
preimage = hexlify(preimage).decode('ASCII') |
|||
print("htlc_accepted called for payment_hash {}".format(htlc['payment_hash'])) |
|||
|
|||
if htlc['payment_hash'] == payment_hash: |
|||
return {'result': 'resolve', 'payment_key': preimage} |
|||
else: |
|||
return {'result': 'continue'} |
|||
|
|||
|
|||
plugin.run() |
@ -0,0 +1,24 @@ |
|||
#!/usr/bin/env python3 |
|||
from pyln.client import Plugin |
|||
from hashlib import sha256 |
|||
from binascii import hexlify |
|||
|
|||
"""A simple plugin that accepts invoices with "AA"*32 preimages |
|||
""" |
|||
plugin = Plugin() |
|||
|
|||
|
|||
@plugin.hook('htlc_accepted') |
|||
def on_htlc_accepted(htlc, plugin, **kwargs): |
|||
preimage = b"\xAA" * 32 |
|||
payment_hash = sha256(preimage).hexdigest() |
|||
preimage = hexlify(preimage).decode('ASCII') |
|||
print("htlc_accepted called for payment_hash {}".format(htlc['payment_hash'])) |
|||
|
|||
if htlc['payment_hash'] == payment_hash: |
|||
return {'result': 'resolve', 'payment_key': preimage} |
|||
else: |
|||
return {'result': 'continue'} |
|||
|
|||
|
|||
plugin.run() |
Loading…
Reference in new issue