diff --git a/doc/schemas/commando.request.json b/doc/schemas/commando.request.json index 52c52773f..80da4b98a 100644 --- a/doc/schemas/commando.request.json +++ b/doc/schemas/commando.request.json @@ -30,6 +30,11 @@ "rune": { "type": "string", "description": "rune to authorize the command" + }, + "filter": { + "type": "object", + "additionalProperties": true, + "description": "filter to peer to apply to any successful result" } } } diff --git a/plugins/commando.c b/plugins/commando.c index 177860603..4e3b0936c 100644 --- a/plugins/commando.c +++ b/plugins/commando.c @@ -382,7 +382,7 @@ static void try_command(struct node_id *peer, const u8 *msg, size_t msglen) { struct commando *incoming = tal(plugin, struct commando); - const jsmntok_t *toks, *method, *params, *rune, *id; + const jsmntok_t *toks, *method, *params, *rune, *id, *filter; const char *buf = (const char *)msg, *failmsg; struct out_req *req; const char *cmdid_prefix; @@ -415,6 +415,7 @@ static void try_command(struct node_id *peer, return; } rune = json_get_member(buf, toks, "rune"); + filter = json_get_member(buf, toks, "filter"); id = json_get_member(buf, toks, "id"); if (!id) { if (!deprecated_apis) { @@ -476,6 +477,11 @@ static void try_command(struct node_id *peer, json_object_start(req->js, "params"); json_object_end(req->js); } + if (filter) { + json_add_jsonstr(req->js, "filter", + json_tok_full(buf, filter), + json_tok_full_len(filter)); + } tal_free(toks); send_outreq(plugin, req); } @@ -700,7 +706,7 @@ static struct command_result *json_commando(struct command *cmd, { struct node_id *peer; const char *method, *cparams; - const char *rune; + const char *rune, *filter; struct commando *ocmd; struct outgoing *outgoing; char *json; @@ -711,6 +717,7 @@ static struct command_result *json_commando(struct command *cmd, p_req("method", param_string, &method), p_opt("params", param_string, &cparams), p_opt("rune", param_string, &rune), + p_opt("filter", param_string, &filter), NULL)) return command_param_failed(); @@ -731,6 +738,8 @@ static struct command_result *json_commando(struct command *cmd, ocmd->json_id, cparams ? cparams : "{}"); if (rune) tal_append_fmt(&json, ",\"rune\":\"%s\"", rune); + if (filter) + tal_append_fmt(&json, ",\"filter\":%s", filter); tal_append_fmt(&json, "}"); outgoing = tal(cmd, struct outgoing); diff --git a/tests/test_plugin.py b/tests/test_plugin.py index c2d06580c..7f4298cec 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -2648,6 +2648,14 @@ def test_commando(node_factory, executor): assert len(res['peers']) == 1 assert res['peers'][0]['id'] == l2.info['id'] + # Filter test + res = l2.rpc.call(method='commando', + payload={'peer_id': l1.info['id'], + 'rune': rune, + 'method': 'listpeers', + 'filter': {'peers': [{'id': True}]}}) + assert res == {'peers': [{'id': l2.info['id']}]} + with pytest.raises(RpcError, match='missing required parameter'): l2.rpc.call(method='commando', payload={'peer_id': l1.info['id'],