| 1219 | } |
| 1220 | |
| 1221 | static struct command_result * |
| 1222 | param_route_hop(struct command *cmd, const char *name, const char *buffer, |
| 1223 | const jsmntok_t *tok, struct route_hop **hop) |
| 1224 | { |
| 1225 | const jsmntok_t *idtok, *channeltok, *amounttok, *delaytok; |
| 1226 | struct route_hop *res; |
| 1227 | |
| 1228 | res = tal(cmd, struct route_hop); |
| 1229 | idtok = json_get_member(buffer, tok, "id"); |
| 1230 | channeltok = json_get_member(buffer, tok, "channel"); |
| 1231 | amounttok = json_get_member(buffer, tok, "amount_msat"); |
| 1232 | delaytok = json_get_member(buffer, tok, "delay"); |
| 1233 | |
| 1234 | /* General verification that all fields that we need are present. */ |
| 1235 | if (!idtok && !channeltok) |
| 1236 | return command_fail( |
| 1237 | cmd, JSONRPC2_INVALID_PARAMS, |
| 1238 | "Either 'id' or 'channel' is required for a route_hop"); |
| 1239 | |
| 1240 | if (!amounttok) |
| 1241 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1242 | "'amount_msat' is required"); |
| 1243 | |
| 1244 | if (!delaytok) |
| 1245 | return command_fail(cmd, JSONRPC2_INVALID_PARAMS, |
| 1246 | "'delay' is required"); |
| 1247 | |
| 1248 | /* Parsing of actual values including sanity check for all parsed |
| 1249 | * values. */ |
| 1250 | if (!idtok) { |
| 1251 | memset(&res->node_id, 0, sizeof(struct node_id)); |
| 1252 | } else if (!json_to_node_id(buffer, idtok, &res->node_id)) { |
| 1253 | return command_fail_badparam(cmd, name, buffer, idtok, |
| 1254 | "should be a node_id"); |
| 1255 | } |
| 1256 | |
| 1257 | if (!channeltok) { |
| 1258 | memset(&res->scid, 0, sizeof(struct short_channel_id)); |
| 1259 | } else if (!json_to_short_channel_id(buffer, channeltok, &res->scid)) { |
| 1260 | return command_fail_badparam(cmd, name, buffer, channeltok, |
| 1261 | "should be a short_channel_id"); |
| 1262 | } |
| 1263 | |
| 1264 | if (!json_to_msat(buffer, amounttok, &res->amount)) |
| 1265 | return command_fail_badparam(cmd, name, buffer, amounttok, |
| 1266 | "should be a valid amount_msat"); |
| 1267 | |
| 1268 | if (!json_to_number(buffer, delaytok, &res->delay) || res->delay < 1) |
| 1269 | return command_fail_badparam(cmd, name, buffer, delaytok, |
| 1270 | "should be a positive, non-zero, number"); |
| 1271 | |
| 1272 | *hop = res; |
| 1273 | return NULL; |
| 1274 | } |
| 1275 | |
| 1276 | static struct command_result *json_sendonion(struct command *cmd, |
| 1277 | const char *buffer, |
nothing calls this directly
no test coverage detected