2019-09-09 02:16:53 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
This plugin is used to test the `rpc_command` hook.
|
|
|
|
"""
|
2020-02-11 23:04:21 +01:00
|
|
|
from pyln.client import Plugin
|
2019-09-09 02:16:53 +02:00
|
|
|
|
2019-12-06 04:54:41 +01:00
|
|
|
plugin = Plugin()
|
2019-09-09 02:16:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
@plugin.hook("rpc_command")
|
|
|
|
def on_rpc_command(plugin, rpc_command, **kwargs):
|
2020-03-03 14:02:06 +01:00
|
|
|
request = rpc_command
|
2019-09-09 02:16:53 +02:00
|
|
|
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"}}}
|
2019-12-06 10:34:17 +01:00
|
|
|
elif request["method"] == "help":
|
|
|
|
request["method"] = "autocleaninvoice"
|
|
|
|
return {"replace": request}
|
2020-01-31 12:50:37 +01:00
|
|
|
return {"result": "continue"}
|
2019-09-09 02:16:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
plugin.run()
|