Browse Source

Merge remote-tracking branch 'origin/pr/55'

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
dfad49bbd7
  1. 24
      daemon/jsonrpc.c
  2. 11
      daemon/lightning-cli.c

24
daemon/jsonrpc.c

@ -353,12 +353,18 @@ static void json_result(struct json_connection *jcon,
const char *id, const char *res, const char *err) const char *id, const char *res, const char *err)
{ {
struct json_output *out = tal(jcon, struct json_output); struct json_output *out = tal(jcon, struct json_output);
if (err == NULL)
out->json = tal_fmt(out, out->json = tal_fmt(out,
"{ \"result\" : %s," "{ \"jsonrpc\": \"2.0\", "
" \"error\" : %s," "\"result\" : %s,"
" \"id\" : %s }\n", " \"id\" : %s }\n",
res, err, id); res, id);
else
out->json = tal_fmt(out,
"{ \"jsonrpc\": \"2.0\", "
" \"error\" : %s,"
" \"id\" : %s }\n",
err, id);
/* Queue for writing, and wake writer (and maybe reader). */ /* Queue for writing, and wake writer (and maybe reader). */
list_add_tail(&jcon->output, &out->list); list_add_tail(&jcon->output, &out->list);
@ -386,7 +392,7 @@ void command_success(struct command *cmd, struct json_result *result)
return; return;
} }
assert(jcon->current == cmd); assert(jcon->current == cmd);
json_result(jcon, cmd->id, json_result_string(result), "null"); json_result(jcon, cmd->id, json_result_string(result), NULL);
log_debug(jcon->log, "Success"); log_debug(jcon->log, "Success");
jcon->current = tal_free(cmd); jcon->current = tal_free(cmd);
} }
@ -418,7 +424,7 @@ void command_fail(struct command *cmd, const char *fmt, ...)
quote = tal_fmt(cmd, "\"%s\"", error); quote = tal_fmt(cmd, "\"%s\"", error);
assert(jcon->current == cmd); assert(jcon->current == cmd);
json_result(jcon, cmd->id, "null", quote); json_result(jcon, cmd->id, NULL, quote);
jcon->current = tal_free(cmd); jcon->current = tal_free(cmd);
} }
@ -426,7 +432,7 @@ static void json_command_malformed(struct json_connection *jcon,
const char *id, const char *id,
const char *error) const char *error)
{ {
return json_result(jcon, id, "null", error); return json_result(jcon, id, NULL, error);
} }
static void parse_request(struct json_connection *jcon, const jsmntok_t tok[]) static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])

11
daemon/lightning-cli.c

@ -128,7 +128,7 @@ int main(int argc, char *argv[])
tal_resize(&resp, tal_count(resp) * 2); tal_resize(&resp, tal_count(resp) * 2);
/* parsing huge outputs is slow: do quick check first. */ /* parsing huge outputs is slow: do quick check first. */
if (num_opens == num_closes && strstr(resp, "\"result\"")) if (num_opens == num_closes)
break; break;
} }
if (i < 0) if (i < 0)
@ -158,13 +158,10 @@ int main(int argc, char *argv[])
"Non-object response '%s'", resp); "Non-object response '%s'", resp);
result = json_get_member(resp, toks, "result"); result = json_get_member(resp, toks, "result");
if (!result)
errx(ERROR_TALKING_TO_LIGHTNINGD,
"Missing 'result' in response '%s'", resp);
error = json_get_member(resp, toks, "error"); error = json_get_member(resp, toks, "error");
if (!error) if (!error && !result)
errx(ERROR_TALKING_TO_LIGHTNINGD, errx(ERROR_TALKING_TO_LIGHTNINGD,
"Missing 'error' in response '%s'", resp); "Either 'result' or 'error' must be returned in response '%s'", resp);
id = json_get_member(resp, toks, "id"); id = json_get_member(resp, toks, "id");
if (!id) if (!id)
errx(ERROR_TALKING_TO_LIGHTNINGD, errx(ERROR_TALKING_TO_LIGHTNINGD,
@ -174,7 +171,7 @@ int main(int argc, char *argv[])
"Incorrect 'id' in response: %.*s", "Incorrect 'id' in response: %.*s",
json_tok_len(id), json_tok_contents(resp, id)); json_tok_len(id), json_tok_contents(resp, id));
if (json_tok_is_null(resp, error)) { if (!error || json_tok_is_null(resp, error)) {
printf("%.*s\n", printf("%.*s\n",
json_tok_len(result), json_tok_len(result),
json_tok_contents(resp, result)); json_tok_contents(resp, result));

Loading…
Cancel
Save