diff --git a/doc/developers-guide/plugin-development/hooks.md b/doc/developers-guide/plugin-development/hooks.md index ba2c53daa..96f1ff1a9 100644 --- a/doc/developers-guide/plugin-development/hooks.md +++ b/doc/developers-guide/plugin-development/hooks.md @@ -506,7 +506,8 @@ The `htlc_accepted` hook is a chained hook, i.e., multiple plugins can register ### `rpc_command` -The `rpc_command` hook allows a plugin to take over any RPC command. It sends the received JSON-RPC request (for any method!) to the registered plugin, +The `rpc_command` hook allows a plugin to take over any RPC command. It sends the received JSON-RPC request to the registered plugin. You can optionally specify a "filters" array, containing the command names you want to intercept: without this, all commands will be sent to this hook. + ```json { diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 6e2d5f7a5..48f5cd754 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -1003,11 +1003,11 @@ log_error_and_skip: return true; } -REGISTER_PLUGIN_HOOK(rpc_command, - rpc_command_hook_callback, - rpc_command_hook_final, - rpc_command_hook_serialize, - struct rpc_command_hook_payload *); +REGISTER_PLUGIN_HOOK_STRFILTER(rpc_command, + rpc_command_hook_callback, + rpc_command_hook_final, + rpc_command_hook_serialize, + struct rpc_command_hook_payload *); /* We return struct command_result so command_fail return value has a natural * sink; we don't actually use the result. */ @@ -1124,7 +1124,8 @@ parse_request(struct json_connection *jcon, trace_span_start("lightningd/jsonrpc", &c); trace_span_tag(&c, "method", c->json_cmd->name); - completed = plugin_hook_call_rpc_command(jcon->ld, c->id, rpc_hook); + /* They can filter by command name */ + completed = plugin_hook_call_rpc_command(jcon->ld, c->json_cmd->name, c->id, rpc_hook); trace_span_end(&c); /* If it's deferred, mark it (otherwise, it's completed) */