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

Function json_fetchinvoice

plugins/fetchinvoice.c:958–1258  ·  view source on GitHub ↗

Fetches an invoice for this offer, and makes sure it corresponds. */

Source from the content-addressed store, hash-verified

956
957/* Fetches an invoice for this offer, and makes sure it corresponds. */
958struct command_result *json_fetchinvoice(struct command *cmd,
959 const char *buffer,
960 const jsmntok_t *params)
961{
962 const struct offers_data *od = get_offers_data(cmd->plugin);
963 struct amount_msat *msat;
964 const char *rec_label, *payer_note;
965 u8 *payer_metadata;
966 struct out_req *req;
967 struct tlv_invoice_request *invreq;
968 struct sent *sent = tal(cmd, struct sent);
969 struct bip_353_name *bip353;
970 u32 *timeout;
971 u64 *quantity;
972 u32 *recurrence_counter, *recurrence_start;
973 char *error;
974
975 if (!param_check(cmd, buffer, params,
976 p_req("offer", param_offer, &sent->offer),
977 p_opt("amount_msat", param_msat, &msat),
978 p_opt("quantity", param_u64, &quantity),
979 p_opt("recurrence_counter", param_number, &recurrence_counter),
980 p_opt("recurrence_start", param_number, &recurrence_start),
981 p_opt("recurrence_label", param_string, &rec_label),
982 p_opt_def("timeout", param_number, &timeout, 60),
983 p_opt("payer_note", param_string, &payer_note),
984 p_opt("payer_metadata", param_bin_from_hex, &payer_metadata),
985 p_opt("bip353", param_bip353, &bip353),
986 p_opt("dev_path_use_scidd", param_dev_scidd, &sent->dev_path_use_scidd),
987 p_opt("dev_reply_path", param_dev_reply_path, &sent->dev_reply_path),
988 NULL))
989 return command_param_failed();
990
991 error = offer_check_recurrence_policy(tmpctx, sent->offer);
992 if (error) {
993 return command_fail(
994 cmd, JSONRPC2_INVALID_PARAMS,
995 "offer doesn't satisfy CLN's recurrence policy: %s", error);
996 }
997
998 sent->wait_timeout = *timeout;
999 sent->their_paths = sent->offer->offer_paths;
1000 if (sent->their_paths)
1001 sent->direct_dest = NULL;
1002 else
1003 sent->direct_dest = sent->offer->offer_issuer_id;
1004 /* This is NULL if offer_issuer_id is missing, and set by try_establish */
1005 sent->issuer_key = sent->offer->offer_issuer_id;
1006
1007 /* BOLT #12:
1008 * - if the current time is after `offer_absolute_expiry`:
1009 * - MUST NOT respond to the offer.
1010 */
1011 /* BOLT-recurrence #12:
1012 * - if the current time is after `offer_absolute_expiry`:
1013 * - MUST NOT make an initial response to the offer
1014 * (i.e. continuing an existing offer with recurrence is ok)
1015 */

Callers

nothing calls this directly

Calls 15

get_offers_dataFunction · 0.85
param_checkFunction · 0.85
clock_timeFunction · 0.85
invreq_recurrenceFunction · 0.85
tal_bytelenFunction · 0.85
invrequest_encodeFunction · 0.85
json_add_boolFunction · 0.85
command_param_failedFunction · 0.70

Tested by

no test coverage detected