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

Function json_sendpay

lightningd/pay.c:1566–1658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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