Browse Source

param: upgraded json_tok_short_channel_id

Made previous version a utility function.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 6 years ago
committed by Rusty Russell
parent
commit
1fb203891d
  1. 4
      lightningd/gossip_control.c
  2. 24
      lightningd/json.c
  3. 8
      lightningd/json.h
  4. 4
      lightningd/pay.c
  5. 4
      lightningd/peer_control.c
  6. 9
      wallet/test/run-wallet.c

4
lightningd/gossip_control.c

@ -383,7 +383,7 @@ static void json_listchannels(struct command *cmd, const char *buffer,
u8 *req;
struct short_channel_id *id;
if (!param(cmd, buffer, params,
p_opt("short_channel_id", json_tok_short_channel_id, &id),
p_opt_tal("short_channel_id", json_tok_short_channel_id, &id),
NULL))
return;
@ -452,7 +452,7 @@ static void json_dev_query_scids(struct command *cmd,
scids = tal_arr(cmd, struct short_channel_id, scidstok->size);
end = json_next(scidstok);
for (i = 0, t = scidstok + 1; t < end; t = json_next(t), i++) {
if (!json_tok_short_channel_id(buffer, t, &scids[i])) {
if (!json_to_short_channel_id(buffer, t, &scids[i])) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"scid %zu '%.*s' is not an scid",
i, t->end - t->start,

24
lightningd/json.c

@ -201,12 +201,26 @@ void json_add_short_channel_id(struct json_result *response,
type_to_string(response, struct short_channel_id, id));
}
bool json_tok_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid)
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid)
{
return short_channel_id_from_str(buffer + tok->start,
tok->end - tok->start,
scid);
return (short_channel_id_from_str(buffer + tok->start,
tok->end - tok->start, scid));
}
bool json_tok_short_channel_id(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
struct short_channel_id **scid)
{
*scid = tal(cmd, struct short_channel_id);
if (short_channel_id_from_str(buffer + tok->start,
tok->end - tok->start, *scid))
return true;
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"'%s' should be a short channel id, not '%.*s'",
name, tok->end - tok->start, buffer + tok->start);
return false;
}
bool

8
lightningd/json.h

@ -71,8 +71,12 @@ bool json_tok_pubkey(struct command *cmd, const char *name,
struct pubkey **pubkey);
/* Extract a short_channel_id from this */
bool json_tok_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid);
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
struct short_channel_id *scid);
bool json_tok_short_channel_id(struct command *cmd, const char *name,
const char *buffer, const jsmntok_t *tok,
struct short_channel_id **scid);
/* Extract number from this (may be a string, or a number literal) */
bool json_tok_u64(struct command *cmd, const char *name,

4
lightningd/pay.c

@ -1007,8 +1007,8 @@ static void json_sendpay(struct command *cmd,
return;
}
if (!json_tok_short_channel_id(buffer, chantok,
&route[n_hops].channel_id)) {
if (!json_to_short_channel_id(buffer, chantok,
&route[n_hops].channel_id)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu invalid channel_id", n_hops);
return;

4
lightningd/peer_control.c

@ -803,7 +803,7 @@ command_find_channel(struct command *cmd,
tok->end - tok->start,
buffer + tok->start);
return NULL;
} else if (json_tok_short_channel_id(buffer, tok, &scid)) {
} else if (json_to_short_channel_id(buffer, tok, &scid)) {
list_for_each(&ld->peers, peer, list) {
channel = peer_active_channel(peer);
if (!channel)
@ -1172,7 +1172,7 @@ static void json_dev_forget_channel(struct command *cmd, const char *buffer,
bool *force;
if (!param(cmd, buffer, params,
p_req_tal("id", json_tok_pubkey, &peerid),
p_opt("short_channel_id", json_tok_short_channel_id, &scid),
p_opt_tal("short_channel_id", json_tok_short_channel_id, &scid),
p_opt_def_tal("force", json_tok_bool, &force, false),
NULL))
return;

9
wallet/test/run-wallet.c

@ -241,8 +241,9 @@ bool json_tok_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
struct pubkey **pubkey UNNEEDED)
{ fprintf(stderr, "json_tok_pubkey called!\n"); abort(); }
/* Generated stub for json_tok_short_channel_id */
bool json_tok_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id *scid UNNEEDED)
bool json_tok_short_channel_id(struct command *cmd UNNEEDED, const char *name UNNEEDED,
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id **scid UNNEEDED)
{ fprintf(stderr, "json_tok_short_channel_id called!\n"); abort(); }
/* Generated stub for json_tok_tok */
bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
@ -253,6 +254,10 @@ bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct pubkey *pubkey UNNEEDED)
{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); }
/* Generated stub for json_to_short_channel_id */
bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
struct short_channel_id *scid UNNEEDED)
{ fprintf(stderr, "json_to_short_channel_id called!\n"); abort(); }
/* Generated stub for kill_uncommitted_channel */
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
const char *why UNNEEDED)

Loading…
Cancel
Save