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

Function json_sendpay

lightningd/pay.c:1563–1655  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1561}
1562
1563static struct command_result *json_sendpay(struct command *cmd,
1564 const char *buffer,
1565 const jsmntok_t *obj UNNEEDED,
1566 const jsmntok_t *params)
1567{
1568 struct sha256 *rhash;
1569 struct route_hop *route;
1570 struct amount_msat *msat;
1571 const char *invstring, *label, *description;
1572 u64 *partid, *group;
1573 struct secret *payment_secret;
1574 struct sha256 *local_invreq_id;
1575 u8 *payment_metadata;
1576 bool *dev_legacy_hop;
1577
1578 if (!param_check(cmd, buffer, params,
1579 p_req("route", param_route_hops, &route),
1580 p_req("payment_hash", param_sha256, &rhash),
1581 p_opt("label", param_escaped_string, &label),
1582 p_opt("amount_msat", param_msat, &msat),
1583 /* FIXME: parameter should be invstring now */
1584 p_opt("bolt11", param_invstring, &invstring),
1585 p_opt("payment_secret", param_secret, &payment_secret),
1586 p_opt_def("partid", param_u64, &partid, 0),
1587 p_opt("localinvreqid", param_sha256, &local_invreq_id),
1588 p_opt("groupid", param_u64, &group),
1589 p_opt("payment_metadata", param_bin_from_hex, &payment_metadata),
1590 p_opt("description", param_string, &description),
1591 p_opt_dev("dev_legacy_hop", param_bool, &dev_legacy_hop, false),
1592 NULL))
1593 return command_param_failed();
1594
1595 if (*partid && !msat)
1596 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1597 "Must specify msatoshi with partid");
1598
1599 /* If groupid was not provided default to incrementing from the previous one. */
1600 if (group == NULL) {
1601 group = tal(tmpctx, u64);
1602 *group = wallet_payment_get_groupid(cmd->ld->wallet, rhash) + 1;
1603 }
1604
1605 if (tal_count(route) == 0) {
1606 if (!msat)
1607 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1608 "Self-payment requires amount_msat");
1609 if (*partid)
1610 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1611 "Self-payment does not allow (non-zero) partid");
1612 if (command_check_only(cmd))
1613 return command_check_done(cmd);
1614
1615 return self_payment(cmd->ld, cmd, rhash, *partid, *group, *msat,
1616 label, invstring, description, local_invreq_id,
1617 payment_secret, payment_metadata);
1618 }
1619
1620 const struct amount_msat final_amount = route[tal_count(route)-1].amount;

Callers

nothing calls this directly

Calls 11

param_checkFunction · 0.85
self_paymentFunction · 0.85
amount_msat_greaterFunction · 0.85
send_paymentFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
command_check_onlyFunction · 0.70
command_check_doneFunction · 0.70
amount_msat_eqFunction · 0.50
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected