param: upgraded json_tok_short_channel_id
Made previous version a utility function. Signed-off-by: Mark Beckwith <wythe@intrig.com>
This commit is contained in:
parent
9b28ecf8fc
commit
1fb203891d
|
@ -383,7 +383,7 @@ static void json_listchannels(struct command *cmd, const char *buffer,
|
||||||
u8 *req;
|
u8 *req;
|
||||||
struct short_channel_id *id;
|
struct short_channel_id *id;
|
||||||
if (!param(cmd, buffer, params,
|
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))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ static void json_dev_query_scids(struct command *cmd,
|
||||||
scids = tal_arr(cmd, struct short_channel_id, scidstok->size);
|
scids = tal_arr(cmd, struct short_channel_id, scidstok->size);
|
||||||
end = json_next(scidstok);
|
end = json_next(scidstok);
|
||||||
for (i = 0, t = scidstok + 1; t < end; t = json_next(t), i++) {
|
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,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"scid %zu '%.*s' is not an scid",
|
"scid %zu '%.*s' is not an scid",
|
||||||
i, t->end - t->start,
|
i, t->end - t->start,
|
||||||
|
|
|
@ -201,12 +201,26 @@ void json_add_short_channel_id(struct json_result *response,
|
||||||
type_to_string(response, struct short_channel_id, id));
|
type_to_string(response, struct short_channel_id, id));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool json_tok_short_channel_id(const char *buffer, const jsmntok_t *tok,
|
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||||
struct short_channel_id *scid)
|
struct short_channel_id *scid)
|
||||||
{
|
{
|
||||||
return short_channel_id_from_str(buffer + tok->start,
|
return (short_channel_id_from_str(buffer + tok->start,
|
||||||
tok->end - tok->start,
|
tok->end - tok->start, scid));
|
||||||
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
|
bool
|
||||||
|
|
|
@ -71,8 +71,12 @@ bool json_tok_pubkey(struct command *cmd, const char *name,
|
||||||
struct pubkey **pubkey);
|
struct pubkey **pubkey);
|
||||||
|
|
||||||
/* Extract a short_channel_id from this */
|
/* Extract a short_channel_id from this */
|
||||||
bool json_tok_short_channel_id(const char *buffer, const jsmntok_t *tok,
|
bool json_to_short_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||||
struct short_channel_id *scid);
|
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) */
|
/* Extract number from this (may be a string, or a number literal) */
|
||||||
bool json_tok_u64(struct command *cmd, const char *name,
|
bool json_tok_u64(struct command *cmd, const char *name,
|
||||||
|
|
|
@ -1007,8 +1007,8 @@ static void json_sendpay(struct command *cmd,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!json_tok_short_channel_id(buffer, chantok,
|
if (!json_to_short_channel_id(buffer, chantok,
|
||||||
&route[n_hops].channel_id)) {
|
&route[n_hops].channel_id)) {
|
||||||
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
"Route %zu invalid channel_id", n_hops);
|
"Route %zu invalid channel_id", n_hops);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -803,7 +803,7 @@ command_find_channel(struct command *cmd,
|
||||||
tok->end - tok->start,
|
tok->end - tok->start,
|
||||||
buffer + tok->start);
|
buffer + tok->start);
|
||||||
return NULL;
|
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) {
|
list_for_each(&ld->peers, peer, list) {
|
||||||
channel = peer_active_channel(peer);
|
channel = peer_active_channel(peer);
|
||||||
if (!channel)
|
if (!channel)
|
||||||
|
@ -1172,7 +1172,7 @@ static void json_dev_forget_channel(struct command *cmd, const char *buffer,
|
||||||
bool *force;
|
bool *force;
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req_tal("id", json_tok_pubkey, &peerid),
|
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),
|
p_opt_def_tal("force", json_tok_bool, &force, false),
|
||||||
NULL))
|
NULL))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -241,8 +241,9 @@ bool json_tok_pubkey(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||||
struct pubkey **pubkey UNNEEDED)
|
struct pubkey **pubkey UNNEEDED)
|
||||||
{ fprintf(stderr, "json_tok_pubkey called!\n"); abort(); }
|
{ fprintf(stderr, "json_tok_pubkey called!\n"); abort(); }
|
||||||
/* Generated stub for json_tok_short_channel_id */
|
/* Generated stub for json_tok_short_channel_id */
|
||||||
bool json_tok_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
bool json_tok_short_channel_id(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
||||||
struct short_channel_id *scid 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(); }
|
{ fprintf(stderr, "json_tok_short_channel_id called!\n"); abort(); }
|
||||||
/* Generated stub for json_tok_tok */
|
/* Generated stub for json_tok_tok */
|
||||||
bool json_tok_tok(struct command *cmd UNNEEDED, const char *name UNNEEDED,
|
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,
|
bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||||
struct pubkey *pubkey UNNEEDED)
|
struct pubkey *pubkey UNNEEDED)
|
||||||
{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); }
|
{ 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 */
|
/* Generated stub for kill_uncommitted_channel */
|
||||||
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
|
void kill_uncommitted_channel(struct uncommitted_channel *uc UNNEEDED,
|
||||||
const char *why UNNEEDED)
|
const char *why UNNEEDED)
|
||||||
|
|
Loading…
Reference in New Issue