core-lightning/tests/plugins/reject.py
Christian Decker 9d4148ce68 pylightning: Warn users of plugins that may break due to extra args
We recently noticed that the way we unpack the call arguments for hooks and
notifications in pylightning breaks pretty quickly once you start changing the
hook and notification params. If you add params they will not get mapped
correctly causing the plugin to error out.

This can be fixed by adding a `VAR_KEYWORD` argument to the calbacks, i.e., by
adding a single `**kwargs` argument at the end of the signature. This commit
adds a check that such a catch-all argument exists, and emits a warning if it
doesn't.

It also fixes up the plugins that we ship ourselves.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-08-05 00:19:48 +00:00

39 lines
935 B
Python
Executable File

#!/usr/bin/env python3
"""Simple plugin to test the connected_hook.
It can mark some node_ids as rejects and it'll check for each
connection if it should be disconnected immediately or if it can
continue.
"""
from lightning import Plugin
plugin = Plugin()
@plugin.hook('peer_connected')
def on_connected(peer, plugin, **kwargs):
if peer['id'] in plugin.reject_ids:
print("{} is in reject list, disconnecting".format(peer['id']))
return {'result': 'disconnect', 'error_message': 'You are in reject list'}
print("{} is allowed".format(peer['id']))
return {'result': 'continue'}
@plugin.init()
def init(configuration, options, plugin):
plugin.reject_ids = []
@plugin.method('reject')
def reject(node_id, plugin):
"""Mark a given node_id as reject for future connections.
"""
print("Rejecting connections from {}".format(node_id))
plugin.reject_ids.append(node_id)
plugin.run()