Browse Source

param: use param for json_pay routes

Note: Unlike before, this will now accept positional parameters.

Note: In case of error we no longer report the hop number.  Is this acceptable?
We still report the name of the bad param and its value.

One option is to log the hop number if param() returns false.  This would require
a change to command_fail so it doesn't delete the cmd, so we can still
access cmd->ld->log.

Signed-off-by: Mark Beckwith <wythe@intrig.com>
ppa-0.6.1
Mark Beckwith 7 years ago
committed by Rusty Russell
parent
commit
4cef0d062c
  1. 59
      lightningd/pay.c

59
lightningd/pay.c

@ -975,54 +975,25 @@ static void json_sendpay(struct command *cmd,
route = tal_arr(cmd, struct route_hop, n_hops);
for (t = routetok + 1; t < end; t = json_next(t)) {
/* FIXME: Use param() to handle parsing each route? -- @wythe */
const jsmntok_t *amttok, *idtok, *delaytok, *chantok;
if (t->type != JSMN_OBJECT) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu '%.*s' is not an object",
n_hops,
t->end - t->start,
buffer + t->start);
return;
}
amttok = json_get_member(buffer, t, "msatoshi");
idtok = json_get_member(buffer, t, "id");
delaytok = json_get_member(buffer, t, "delay");
chantok = json_get_member(buffer, t, "channel");
if (!amttok || !idtok || !delaytok || !chantok) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu needs msatoshi/id/channel/delay",
n_hops);
u64 *amount;
struct pubkey *id;
struct short_channel_id *channel;
unsigned *delay;
if (!param(cmd, buffer, t,
p_req("msatoshi", json_tok_u64, &amount),
p_req("id", json_tok_pubkey, &id),
p_req("delay", json_tok_number, &delay),
p_req("channel", json_tok_short_channel_id, &channel),
NULL))
return;
}
tal_resize(&route, n_hops + 1);
/* What that hop will forward */
if (!json_to_u64(buffer, amttok, &route[n_hops].amount)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu invalid msatoshi",
n_hops);
return;
}
if (!json_to_short_channel_id(buffer, chantok,
&route[n_hops].channel_id)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu invalid channel_id", n_hops);
return;
}
if (!json_to_pubkey(buffer, idtok, &route[n_hops].nodeid)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu invalid id", n_hops);
return;
}
if (!json_to_number(buffer, delaytok, &route[n_hops].delay)) {
command_fail(cmd, JSONRPC2_INVALID_PARAMS,
"Route %zu invalid delay", n_hops);
return;
}
route[n_hops].amount = *amount;
route[n_hops].nodeid = *id;
route[n_hops].delay = *delay;
route[n_hops].channel_id = *channel;
n_hops++;
}

Loading…
Cancel
Save