MCPcopy Create free account
hub / github.com/ElementsProject/lightning / param_route_hop

Function param_route_hop

lightningd/pay.c:1272–1325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

json_get_memberFunction · 0.85
command_failFunction · 0.70
json_to_node_idFunction · 0.50
command_fail_badparamFunction · 0.50
json_to_short_channel_idFunction · 0.50
json_to_msatFunction · 0.50
json_to_numberFunction · 0.50

Tested by

no test coverage detected