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

Function json_sendonion

lightningd/pay.c:1324–1384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1322}
1323
1324static struct command_result *json_sendonion(struct command *cmd,
1325 const char *buffer,
1326 const jsmntok_t *obj UNNEEDED,
1327 const jsmntok_t *params)
1328{
1329 u8 *onion;
1330 struct onionpacket *packet;
1331 enum onion_wire failcode;
1332 struct route_hop *first_hop;
1333 struct sha256 *payment_hash;
1334 struct lightningd *ld = cmd->ld;
1335 const char *label, *invstring, *description;
1336 struct node_id *destination;
1337 struct secret *path_secrets;
1338 struct amount_msat *msat, *total_msat;
1339 u64 *partid, *group;
1340 struct sha256 *local_invreq_id = NULL;
1341
1342 if (!param_check(cmd, buffer, params,
1343 p_req("onion", param_bin_from_hex, &onion),
1344 p_req("first_hop", param_route_hop, &first_hop),
1345 p_req("payment_hash", param_sha256, &payment_hash),
1346 p_opt("label", param_escaped_string, &label),
1347 p_opt("shared_secrets", param_secrets_array, &path_secrets),
1348 p_opt_def("partid", param_u64, &partid, 0),
1349 /* FIXME: parameter should be invstring now */
1350 p_opt("bolt11", param_invstring, &invstring),
1351 p_opt_def("amount_msat", param_msat, &msat, AMOUNT_MSAT(0)),
1352 p_opt("destination", param_node_id, &destination),
1353 p_opt("localinvreqid", param_sha256, &local_invreq_id),
1354 p_opt("groupid", param_u64, &group),
1355 p_opt("description", param_string, &description),
1356 p_opt_def("total_amount_msat", param_msat, &total_msat, AMOUNT_MSAT(0)),
1357 NULL))
1358 return command_param_failed();
1359
1360 /* If groupid was not provided default to incrementing from the previous one. */
1361 if (group == NULL) {
1362 group = tal(tmpctx, u64);
1363 *group =
1364 wallet_payment_get_groupid(cmd->ld->wallet, payment_hash) +
1365 1;
1366 }
1367
1368 packet = parse_onionpacket(cmd, onion, tal_bytelen(onion), &failcode);
1369
1370 if (!packet)
1371 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1372 "Could not parse the onion. Parsing failed "
1373 "with failcode=%d",
1374 failcode);
1375
1376 if (command_check_only(cmd))
1377 return command_check_done(cmd);
1378
1379 return send_payment_core(ld, cmd, payment_hash, *partid, *group,
1380 first_hop, *msat, *total_msat,
1381 label, invstring, description,

Callers

nothing calls this directly

Calls 9

param_checkFunction · 0.85
parse_onionpacketFunction · 0.85
tal_bytelenFunction · 0.85
send_payment_coreFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70

Tested by

no test coverage detected