jsonrpc: add json_tok_short_channel_id helper.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2018-01-17 06:14:32 +10:30
parent e1e7f289fb
commit 8cf1870465
3 changed files with 13 additions and 2 deletions

View File

@ -388,6 +388,14 @@ 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)
{
return short_channel_id_from_str(buffer + tok->start,
tok->end - tok->start,
scid);
}
void json_add_address(struct json_result *response, const char *fieldname,
const struct wireaddr *addr)
{

View File

@ -76,6 +76,10 @@ void json_add_txid(struct json_result *result, const char *fieldname,
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
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);
/* '"fieldname" : "1234:5:6"' */
void json_add_short_channel_id(struct json_result *response,
const char *fieldname,

View File

@ -299,8 +299,7 @@ static void json_sendpay(struct command *cmd,
return;
}
if (!short_channel_id_from_str(buffer + chantok->start,
chantok->end - chantok->start,
if (!json_tok_short_channel_id(buffer, chantok,
&route[n_hops].channel_id)) {
command_fail(cmd, "route %zu invalid channel_id", n_hops);
return;