Skip to content

Commit 1d4f7f0

Browse files
rustyrussellcdecker
authored andcommitted
Revert "lightningd: always require "jsonrpc": "2.0" in request."
This reverts commit 43b037a. Nicholas Dorier says BTC Payserver still wants this for another year or so. Changelog-Added: JSON-RPC: reverts requirement for "jsonrpc" "2.0" inside requests (still deprecated though, just for a while longer!)
1 parent 70fc702 commit 1d4f7f0

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

lightningd/jsonrpc.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static void replace_command(struct rpc_command_hook_payload *p,
711711
const char *buffer,
712712
const jsmntok_t *replacetok)
713713
{
714-
const jsmntok_t *method = NULL, *params = NULL, *jsonrpc;
714+
const jsmntok_t *method = NULL, *params = NULL;
715715
const char *bad;
716716

717717
/* Must contain "method", "params" and "id" */
@@ -743,10 +743,14 @@ static void replace_command(struct rpc_command_hook_payload *p,
743743
goto fail;
744744
}
745745

746-
jsonrpc = json_get_member(buffer, replacetok, "jsonrpc");
747-
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
748-
bad = "jsonrpc: \"2.0\" must be specified in the request";
749-
goto fail;
746+
// deprecated phase to give the possibility to all to migrate and stay safe
747+
// from this more restrictive change.
748+
if (!deprecated_apis) {
749+
const jsmntok_t *jsonrpc = json_get_member(buffer, replacetok, "jsonrpc");
750+
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(buffer, jsonrpc, "2.0")) {
751+
bad = "jsonrpc: \"2.0\" must be specified in the request";
752+
goto fail;
753+
}
750754
}
751755

752756
was_pending(command_exec(p->cmd->jcon, p->cmd, buffer, replacetok,
@@ -883,7 +887,7 @@ REGISTER_PLUGIN_HOOK(rpc_command,
883887
static struct command_result *
884888
parse_request(struct json_connection *jcon, const jsmntok_t tok[])
885889
{
886-
const jsmntok_t *method, *id, *params, *filter, *jsonrpc;
890+
const jsmntok_t *method, *id, *params, *filter;
887891
struct command *c;
888892
struct rpc_command_hook_payload *rpc_hook;
889893
bool completed;
@@ -912,11 +916,13 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
912916

913917
// Adding a deprecated phase to make sure that all the Core Lightning wrapper
914918
// can migrate all the frameworks
915-
jsonrpc = json_get_member(jcon->buffer, tok, "jsonrpc");
919+
if (!deprecated_apis) {
920+
const jsmntok_t *jsonrpc = json_get_member(jcon->buffer, tok, "jsonrpc");
916921

917-
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(jcon->buffer, jsonrpc, "2.0")) {
918-
json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request");
919-
return NULL;
922+
if (!jsonrpc || jsonrpc->type != JSMN_STRING || !json_tok_streq(jcon->buffer, jsonrpc, "2.0")) {
923+
json_command_malformed(jcon, "null", "jsonrpc: \"2.0\" must be specified in the request");
924+
return NULL;
925+
}
920926
}
921927

922928
/* Allocate the command off of the `jsonrpc` object and not

0 commit comments

Comments
 (0)