Skip to content

Commit

Permalink
plugin: Unwrap the rpc_command payload
Browse files Browse the repository at this point in the history
We were nesting like the following:

```json
{"params": {
  "rpc_command": {
    "rpc_command": {
    }
  }
}
```

This is really excessive, so we unwrap once, and now have the following:

```json
{"params": {
  "rpc_command": {
  }
}
```

Still more wrapping than necessary (the method is repeated in the `params`
object), but it's getting closer.

Changelog-Deprecated: JSON-RPC: Removed double wrapping of `rpc_command` payload in `rpc_command` JSON field.

Suggested-by: @fiatjaf
Signed-off-by: Christian Decker <@cdecker>
  • Loading branch information
cdecker authored and rustyrussell committed Mar 10, 2020
1 parent 15ca3b6 commit d2688bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lightningd/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,22 @@ struct rpc_command_hook_payload {
static void rpc_command_hook_serialize(struct rpc_command_hook_payload *p,
struct json_stream *s)
{
const jsmntok_t *tok;
size_t i;
char *key;
json_object_start(s, "rpc_command");
json_add_tok(s, "rpc_command", p->request, p->buffer);

#ifdef COMPAT_V081
if (deprecated_apis)
json_add_tok(s, "rpc_command", p->request, p->buffer);
#endif

json_for_each_obj(i, tok, p->request) {
key = tal_strndup(NULL, p->buffer + tok->start,
tok->end - tok->start);
json_add_tok(s, key, tok + 1, p->buffer);
tal_free(key);
}
json_object_end(s);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/rpc_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@plugin.hook("rpc_command")
def on_rpc_command(plugin, rpc_command, **kwargs):
request = rpc_command["rpc_command"]
request = rpc_command
if request["method"] == "invoice":
# Replace part of this command
request["params"]["description"] = "A plugin modified this description"
Expand Down

0 comments on commit d2688bb

Please sign in to comment.