diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c index 195f2f9ff..c71132f04 100644 --- a/lightningd/jsonrpc.c +++ b/lightningd/jsonrpc.c @@ -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) { diff --git a/lightningd/jsonrpc.h b/lightningd/jsonrpc.h index 149e942a6..4811eedb8 100644 --- a/lightningd/jsonrpc.h +++ b/lightningd/jsonrpc.h @@ -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, diff --git a/lightningd/pay.c b/lightningd/pay.c index fe54b32b3..d61fbe7a6 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -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;