core-lightning/tests/plugins/rpc_command_1.py

27 lines
779 B
Python
Raw Normal View History

2019-09-09 02:16:53 +02:00
#!/usr/bin/env python3
"""
2021-02-11 16:18:41 +01:00
This plugin is used to test the chained `rpc_command` hook.
2019-09-09 02:16:53 +02:00
"""
from pyln.client import Plugin
2019-09-09 02:16:53 +02:00
plugin = Plugin()
2019-09-09 02:16:53 +02:00
@plugin.hook("rpc_command")
def on_rpc_command(plugin, rpc_command, **kwargs):
request = rpc_command
2019-09-09 02:16:53 +02:00
if request["method"] == "invoice":
# Replace part of this command
2021-02-11 16:18:41 +01:00
request["params"]["description"] = "rpc_command_1 modified this description"
2019-09-09 02:16:53 +02:00
return {"replace": request}
elif request["method"] == "listfunds":
# Return a custom result to the command
2021-02-11 16:18:41 +01:00
return {"return": {"result": ["Custom rpc_command_1 result"]}}
elif request["method"] == "help":
request["method"] = "autocleaninvoice"
return {"replace": request}
return {"result": "continue"}
2019-09-09 02:16:53 +02:00
plugin.run()