mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
lightningd: set filter when we see 'filter' object.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `filter` object allows reduction of JSON response to (most) commands.
This commit is contained in:
parent
3b4c1968a3
commit
2a14afbf21
1 changed files with 23 additions and 1 deletions
|
@ -462,6 +462,16 @@ struct command_result *command_success(struct command *cmd,
|
|||
{
|
||||
assert(cmd);
|
||||
assert(cmd->json_stream == result);
|
||||
|
||||
/* Filter will get upset if we close "result" object it didn't
|
||||
* see! */
|
||||
if (cmd->filter) {
|
||||
const char *err = json_stream_detach_filter(tmpctx, result);
|
||||
if (err)
|
||||
json_add_string(result, "warning_parameter_filter",
|
||||
err);
|
||||
}
|
||||
|
||||
json_object_end(result);
|
||||
json_object_end(result);
|
||||
|
||||
|
@ -606,6 +616,10 @@ struct json_stream *json_stream_success(struct command *cmd)
|
|||
{
|
||||
struct json_stream *r = json_start(cmd);
|
||||
json_object_start(r, "result");
|
||||
|
||||
/* We have results? OK, start filtering */
|
||||
if (cmd->filter)
|
||||
json_stream_attach_filter(r, cmd->filter);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -869,7 +883,7 @@ REGISTER_PLUGIN_HOOK(rpc_command,
|
|||
static struct command_result *
|
||||
parse_request(struct json_connection *jcon, const jsmntok_t tok[])
|
||||
{
|
||||
const jsmntok_t *method, *id, *params, *jsonrpc;
|
||||
const jsmntok_t *method, *id, *params, *filter, *jsonrpc;
|
||||
struct command *c;
|
||||
struct rpc_command_hook_payload *rpc_hook;
|
||||
bool completed;
|
||||
|
@ -882,6 +896,7 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
|
|||
|
||||
method = json_get_member(jcon->buffer, tok, "method");
|
||||
params = json_get_member(jcon->buffer, tok, "params");
|
||||
filter = json_get_member(jcon->buffer, tok, "filter");
|
||||
id = json_get_member(jcon->buffer, tok, "id");
|
||||
|
||||
if (!id) {
|
||||
|
@ -929,6 +944,13 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
|
|||
"Expected string for method");
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
struct command_result *ret;
|
||||
ret = parse_filter(c, "filter", jcon->buffer, filter);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Debug was too chatty, so we use IO here, even though we're
|
||||
* actually just logging the id */
|
||||
log_io(jcon->log, LOG_IO_IN, NULL, c->id, NULL, 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue