mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-20 02:27:51 +01:00
3e3b05e1b2
`pylightning` is not much more than an alias for `pyln-client`, so this removes the need to install that as well just to run the tests.
31 lines
964 B
Python
Executable File
31 lines
964 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
This plugin is used to test the `rpc_command` hook.
|
|
"""
|
|
from pyln.client import Plugin
|
|
|
|
plugin = Plugin()
|
|
|
|
|
|
@plugin.hook("rpc_command")
|
|
def on_rpc_command(plugin, rpc_command, **kwargs):
|
|
request = rpc_command
|
|
if request["method"] == "invoice":
|
|
# Replace part of this command
|
|
request["params"]["description"] = "A plugin modified this description"
|
|
return {"replace": request}
|
|
elif request["method"] == "listfunds":
|
|
# Return a custom result to the command
|
|
return {"return": {"result": ["Custom result"]}}
|
|
elif request["method"] == "sendpay":
|
|
# Don't allow this command to be executed
|
|
return {"return": {"error": {"code": -1,
|
|
"message": "You cannot do this"}}}
|
|
elif request["method"] == "help":
|
|
request["method"] = "autocleaninvoice"
|
|
return {"replace": request}
|
|
return {"result": "continue"}
|
|
|
|
|
|
plugin.run()
|