Browse Source

json: helper to parse pubkeys.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
79ebb9dfd0
  1. 3
      lightningd/gossip_control.c
  2. 7
      lightningd/jsonrpc.c
  3. 4
      lightningd/jsonrpc.h
  4. 4
      lightningd/pay.c
  5. 6
      lightningd/peer_control.c

3
lightningd/gossip_control.c

@ -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;
}

7
lightningd/jsonrpc.c

@ -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)

4
lightningd/jsonrpc.h

@ -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,

4
lightningd/pay.c

@ -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;
}

6
lightningd/peer_control.c

@ -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…
Cancel
Save