mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 10:46:58 +01:00
json: helper to parse pubkeys.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
8430e33f3b
commit
79ebb9dfd0
5 changed files with 15 additions and 9 deletions
|
@ -262,8 +262,7 @@ static void json_getroute(struct command *cmd, const char *buffer, const jsmntok
|
|||
return;
|
||||
}
|
||||
|
||||
if (!pubkey_from_hexstr(buffer + idtok->start,
|
||||
idtok->end - idtok->start, &id)) {
|
||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
||||
command_fail(cmd, "Invalid id");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -352,6 +352,13 @@ void json_add_pubkey(struct json_result *response,
|
|||
json_add_hex(response, fieldname, der, sizeof(der));
|
||||
}
|
||||
|
||||
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||
struct pubkey *pubkey)
|
||||
{
|
||||
return pubkey_from_hexstr(buffer + tok->start,
|
||||
tok->end - tok->start, pubkey);
|
||||
}
|
||||
|
||||
void json_add_short_channel_id(struct json_result *response,
|
||||
const char *fieldname,
|
||||
const struct short_channel_id *id)
|
||||
|
|
|
@ -59,6 +59,10 @@ void json_add_pubkey(struct json_result *response,
|
|||
const char *fieldname,
|
||||
const struct pubkey *key);
|
||||
|
||||
/* Extract a pubkey from this */
|
||||
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||
struct pubkey *pubkey);
|
||||
|
||||
/* '"fieldname" : "1234:5:6"' */
|
||||
void json_add_short_channel_id(struct json_result *response,
|
||||
const char *fieldname,
|
||||
|
|
|
@ -232,9 +232,7 @@ static void json_sendpay(struct command *cmd,
|
|||
command_fail(cmd, "route %zu invalid channel_id", n_hops);
|
||||
return;
|
||||
}
|
||||
if (!pubkey_from_hexstr(buffer + idtok->start,
|
||||
idtok->end - idtok->start,
|
||||
&ids[n_hops])) {
|
||||
if (!json_tok_pubkey(buffer, idtok, &ids[n_hops])) {
|
||||
command_fail(cmd, "route %zu invalid id", n_hops);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -808,8 +808,7 @@ static void json_connect(struct command *cmd,
|
|||
return;
|
||||
}
|
||||
|
||||
if (!pubkey_from_hexstr(buffer + idtok->start,
|
||||
idtok->end - idtok->start, &id)) {
|
||||
if (!json_tok_pubkey(buffer, idtok, &id)) {
|
||||
command_fail(cmd, "id %.*s not valid",
|
||||
idtok->end - idtok->start,
|
||||
buffer + idtok->start);
|
||||
|
@ -1015,8 +1014,7 @@ struct peer *peer_from_json(struct lightningd *ld,
|
|||
{
|
||||
struct pubkey peerid;
|
||||
|
||||
if (!pubkey_from_hexstr(buffer + peeridtok->start,
|
||||
peeridtok->end - peeridtok->start, &peerid))
|
||||
if (!json_tok_pubkey(buffer, peeridtok, &peerid))
|
||||
return NULL;
|
||||
|
||||
return peer_by_id(ld, &peerid);
|
||||
|
|
Loading…
Add table
Reference in a new issue