Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove excessive wrapping in the rpc_command hook call #3560

Merged
merged 2 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endif

ifeq ($(COMPAT),1)
# We support compatibility with pre-0.6.
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V072=1 -DCOMPAT_V073=1 -DCOMPAT_V080=1
COMPAT_CFLAGS=-DCOMPAT_V052=1 -DCOMPAT_V060=1 -DCOMPAT_V061=1 -DCOMPAT_V062=1 -DCOMPAT_V070=1 -DCOMPAT_V072=1 -DCOMPAT_V073=1 -DCOMPAT_V080=1 -DCOMPAT_V081=1
endif

# Timeout shortly before the 600 second travis silence timeout
Expand Down
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this commit needs a Changelog-Deprecated line ?

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heh i came across this yesterday. can you remove the outer object and instead do this line? it should achieve the same result without needing to iterate through the object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do that, however if I use json_add_tok to fill in {"rpc_command": <copy>} I cannot re-enter the rpc_command key to then add the compat version, i.e., {"rpc_command": {"rpc_command": <copy>, <copied-fields}}. Once we remove the COMPAT_V081 flag we can actually do this and avoid iterating through, but until then I'm afraid we need to keep this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack. i understand what this outputs now. thanks.

#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