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

Function json_sendonion

lightningd/pay.c:1327–1387  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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