-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for the 'rpc_command' hook
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
This plugin is used to test the `rpc_command` hook. | ||
""" | ||
import json | ||
from lightning import Plugin | ||
|
||
plugin = Plugin(dynamic=False) | ||
|
||
|
||
@plugin.hook("rpc_command") | ||
def on_rpc_command(plugin, rpc_command, **kwargs): | ||
if rpc_command["method"] == "invoice": | ||
# Replace part of this command | ||
rpc_command["params"] = json.loads(rpc_command["params"]) | ||
rpc_command["params"]["description"] = "A plugin modified this description" | ||
return {"replace": rpc_command} | ||
elif rpc_command["method"] == "listfunds": | ||
# Return a custom result to the command | ||
return {"return": {"result": ["Custom result"]}} | ||
elif rpc_command["method"] == "sendpay": | ||
# Don't allow this command to be executed | ||
return {"return": {"error": {"code": -1, "message": "You cannot do this"}}} | ||
return "continue" | ||
|
||
|
||
plugin.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters