rgb-cln/tests/plugins/rpc_command_2.py

25 lines
718 B
Python
Raw Permalink Normal View History

2019-09-09 01:16:53 +01:00
#!/usr/bin/env python3
"""
2021-02-11 15:18:41 +00:00
This plugin is used to test the chained `rpc_command` hook.
2019-09-09 01:16:53 +01:00
"""
from pyln.client import Plugin
2019-09-09 01:16:53 +01:00
plugin = Plugin()
2019-09-09 01:16:53 +01:00
@plugin.hook("rpc_command")
def on_rpc_command(plugin, rpc_command, **kwargs):
request = rpc_command
2019-09-09 01:16:53 +01:00
if request["method"] == "invoice":
# Replace part of this command
2021-02-11 15:18:41 +00:00
request["params"]["description"] = "rpc_command_2 modified this description"
2019-09-09 01:16:53 +01:00
return {"replace": request}
elif request["method"] == "sendpay":
# Don't allow this command to be executed
return {"return": {"error": {"code": -1,
2021-02-11 15:18:41 +00:00
"message": "rpc_command_2 cannot do this"}}}
return {"result": "continue"}
2019-09-09 01:16:53 +01:00
plugin.run()