| 1267 | } |
| 1268 | |
| 1269 | static struct command_result * |
| 1270 | param_route_hop(struct command *cmd, const char *name, const char *buffer, |
| 1271 | const jsmntok_t *tok, struct route_hop **hop) |
| 1272 | { |
| 1273 | const jsmntok_t *idtok, *channeltok, *amounttok, *delaytok; |
| 1274 | struct route_hop *res; |
| 1275 | |
| 1276 | res = tal(cmd, struct route_hop); |
| 1277 | idtok = json_get_member(buffer, tok, "id"); |
| 1278 | channeltok = json_get_member(buffer, tok, "channel"); |
| 1279 | amounttok = json_get_member(buffer, tok, "amount_msat"); |
| 1280 | delaytok = json_get_member(buffer, tok, "delay"); |
| 1281 | |
| 1282 | /* General verification that all fields that we need are present. */ |
| 1283 | if (!idtok && !channeltok) |
| 1284 | return command_fail( |
| 1285 | cmd, JSONRPC2_INVALID_PARAMS, |
| 1286 | "Either 'id' or 'channel' is required for a route_hop"); |
| 1287 | |
| 1288 | if (!amounttok) |
| 1289 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1290 | "'amount_msat' is required"); |
| 1291 | |
| 1292 | if (!delaytok) |
| 1293 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1294 | "'delay' is required"); |
| 1295 | |
| 1296 | /* Parsing of actual values including sanity check for all parsed |
| 1297 | * values. */ |
| 1298 | if (!idtok) { |
| 1299 | memset(&res->node_id, 0, sizeof(struct node_id)); |
| 1300 | } else if (!json_to_node_id(buffer, idtok, &res->node_id)) { |
| 1301 | return command_fail_badparam(cmd, name, buffer, idtok, |
| 1302 | "should be a node_id"); |
| 1303 | } |
| 1304 | |
| 1305 | if (!channeltok) { |
| 1306 | memset(&res->scid, 0, sizeof(struct short_channel_id)); |
| 1307 | } else if (!json_to_short_channel_id(buffer, channeltok, &res->scid)) { |
| 1308 | return command_fail_badparam(cmd, name, buffer, channeltok, |
| 1309 | "should be a short_channel_id"); |
| 1310 | } |
| 1311 | |
| 1312 | if (!json_to_msat(buffer, amounttok, &res->amount)) |
| 1313 | return command_fail_badparam(cmd, name, buffer, amounttok, |
| 1314 | "should be a valid amount_msat"); |
| 1315 | |
| 1316 | if (!json_to_number(buffer, delaytok, &res->delay) || res->delay < 1) |
| 1317 | return command_fail_badparam(cmd, name, buffer, delaytok, |
| 1318 | "should be a positive, non-zero, number"); |
| 1319 | |
| 1320 | *hop = res; |
| 1321 | return NULL; |
| 1322 | } |
| 1323 | |
| 1324 | static struct command_result *json_sendonion(struct command *cmd, |
| 1325 | const char *buffer, |
nothing calls this directly
no test coverage detected