Browse Source

param: add ok flag to struct command

Callers to param() can now optionally set a flag to see if command_fail was
called.

This is necessary because the `cmd` is freed in case of failure.

I spent a bit of time trying to extend the lifetime of the `cmd` to the end
of parse_request(), but the destructors still needed to be called when they
were, and it was getting ugly.  So I took this minimal approach.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
fix-benchmarks
Mark Beckwith 6 years ago
committed by Christian Decker
parent
commit
1a4f355a7b
  1. 6
      lightningd/jsonrpc.c
  2. 1
      lightningd/jsonrpc.h

6
lightningd/jsonrpc.c

@ -282,6 +282,8 @@ static void connection_complete_ok(struct json_connection *jcon,
{
assert(id != NULL);
assert(result != NULL);
if (cmd->ok)
*(cmd->ok) = true;
/* This JSON is simple enough that we build manually */
json_done(jcon, cmd, take(tal_fmt(jcon,
@ -310,6 +312,9 @@ static void connection_complete_error(struct json_connection *jcon,
assert(id != NULL);
if (cmd->ok)
*(cmd->ok) = false;
json_done(jcon, cmd, take(tal_fmt(tmpctx,
"{ \"jsonrpc\": \"2.0\", "
" \"error\" : "
@ -452,6 +457,7 @@ static void parse_request(struct json_connection *jcon, const jsmntok_t tok[])
json_tok_contents(jcon->buffer, id),
json_tok_len(id));
c->mode = CMD_NORMAL;
c->ok = NULL;
list_add(&jcon->commands, &c->list);
tal_add_destructor(c, destroy_cmd);

1
lightningd/jsonrpc.h

@ -37,6 +37,7 @@ struct command {
enum command_mode mode;
/* This is created if mode is CMD_USAGE */
const char *usage;
bool *ok;
};
struct json_connection {

Loading…
Cancel
Save