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; return;
} }
if (!pubkey_from_hexstr(buffer + idtok->start, if (!json_tok_pubkey(buffer, idtok, &id)) {
idtok->end - idtok->start, &id)) {
command_fail(cmd, "Invalid id"); command_fail(cmd, "Invalid id");
return; 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)); 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, void json_add_short_channel_id(struct json_result *response,
const char *fieldname, const char *fieldname,
const struct short_channel_id *id) 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 char *fieldname,
const struct pubkey *key); 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"' */ /* '"fieldname" : "1234:5:6"' */
void json_add_short_channel_id(struct json_result *response, void json_add_short_channel_id(struct json_result *response,
const char *fieldname, 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); command_fail(cmd, "route %zu invalid channel_id", n_hops);
return; return;
} }
if (!pubkey_from_hexstr(buffer + idtok->start, if (!json_tok_pubkey(buffer, idtok, &ids[n_hops])) {
idtok->end - idtok->start,
&ids[n_hops])) {
command_fail(cmd, "route %zu invalid id", n_hops); command_fail(cmd, "route %zu invalid id", n_hops);
return; return;
} }

6
lightningd/peer_control.c

@ -808,8 +808,7 @@ static void json_connect(struct command *cmd,
return; return;
} }
if (!pubkey_from_hexstr(buffer + idtok->start, if (!json_tok_pubkey(buffer, idtok, &id)) {
idtok->end - idtok->start, &id)) {
command_fail(cmd, "id %.*s not valid", command_fail(cmd, "id %.*s not valid",
idtok->end - idtok->start, idtok->end - idtok->start,
buffer + idtok->start); buffer + idtok->start);
@ -1015,8 +1014,7 @@ struct peer *peer_from_json(struct lightningd *ld,
{ {
struct pubkey peerid; struct pubkey peerid;
if (!pubkey_from_hexstr(buffer + peeridtok->start, if (!json_tok_pubkey(buffer, peeridtok, &peerid))
peeridtok->end - peeridtok->start, &peerid))
return NULL; return NULL;
return peer_by_id(ld, &peerid); return peer_by_id(ld, &peerid);

Loading…
Cancel
Save