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

Function invreq_done

plugins/fetchinvoice.c:948–1056  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

946}
947
948static struct command_result *invreq_done(struct command *cmd,
949 const char *buf,
950 const jsmntok_t *result,
951 struct sent *sent)
952{
953 const jsmntok_t *t;
954 char *fail;
955 enum nodeid_parity parity;
956
957 /* Get invoice request */
958 t = json_get_member(buf, result, "bolt12");
959 if (!t)
960 return command_fail(cmd, LIGHTNINGD,
961 "Missing bolt12 %.*s",
962 json_tok_full_len(result),
963 json_tok_full(buf, result));
964
965 plugin_log(cmd->plugin, LOG_DBG,
966 "invoice_request: %.*s",
967 json_tok_full_len(t),
968 json_tok_full(buf, t));
969
970 sent->inv = NULL;
971 sent->invreq = invrequest_decode(sent,
972 buf + t->start,
973 t->end - t->start,
974 plugin_feature_set(cmd->plugin),
975 chainparams,
976 &fail);
977 if (!sent->invreq)
978 return command_fail(cmd, LIGHTNINGD,
979 "Invalid invoice_request %.*s: %s",
980 json_tok_full_len(t),
981 json_tok_full(buf, t),
982 fail);
983
984 /* Now that's given us the previous base, check this is an OK time
985 * to request an invoice. */
986 if (sent->invreq->recurrence_counter) {
987 u64 *base;
988 const jsmntok_t *pbtok;
989 u64 period_idx = *sent->invreq->recurrence_counter;
990
991 if (sent->invreq->recurrence_start)
992 period_idx += *sent->invreq->recurrence_start;
993
994 /* BOLT-offers-recurrence #12:
995 * - if the offer contained `recurrence_limit`:
996 * - MUST NOT send an `invoice_request` for a period greater
997 * than `max_period`
998 */
999 if (sent->offer->recurrence_limit
1000 && period_idx > *sent->offer->recurrence_limit)
1001 return command_fail(cmd, LIGHTNINGD,
1002 "Can't send invreq for period %"
1003 PRIu64" (limit %u)",
1004 period_idx,
1005 *sent->offer->recurrence_limit);

Callers

nothing calls this directly

Calls 13

invrequest_decodeFunction · 0.85
plugin_feature_setFunction · 0.85
time_nowFunction · 0.85
offer_period_paywindowFunction · 0.85
path_to_nodeFunction · 0.85
connect_directFunction · 0.85
sendinvreq_after_connectFunction · 0.85
command_failFunction · 0.70
plugin_logFunction · 0.70
json_get_memberFunction · 0.50
json_tok_full_lenFunction · 0.50
json_tok_fullFunction · 0.50

Tested by

no test coverage detected