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

Function json_fetchinvoice

plugins/fetchinvoice.c:1119–1315  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1117
1118/* Fetches an invoice for this offer, and makes sure it corresponds. */
1119static struct command_result *json_fetchinvoice(struct command *cmd,
1120 const char *buffer,
1121 const jsmntok_t *params)
1122{
1123 struct amount_msat *msat;
1124 const char *rec_label, *payer_note;
1125 struct out_req *req;
1126 struct tlv_invoice_request *invreq;
1127 struct sent *sent = tal(cmd, struct sent);
1128 struct secret *payer_secret = NULL;
1129 u32 *timeout;
1130
1131 invreq = tlv_invoice_request_new(sent);
1132 if (!param(cmd, buffer, params,
1133 p_req("offer", param_offer, &sent->offer),
1134 p_opt("amount_msat|msatoshi", param_msat, &msat),
1135 p_opt("quantity", param_u64, &invreq->quantity),
1136 p_opt("recurrence_counter", param_number,
1137 &invreq->recurrence_counter),
1138 p_opt("recurrence_start", param_number,
1139 &invreq->recurrence_start),
1140 p_opt("recurrence_label", param_string, &rec_label),
1141 p_opt_def("timeout", param_number, &timeout, 60),
1142 p_opt("payer_note", param_string, &payer_note),
1143#if DEVELOPER
1144 p_opt("payer_secret", param_secret, &payer_secret),
1145#endif
1146 NULL))
1147 return command_param_failed();
1148
1149 sent->wait_timeout = *timeout;
1150
1151 /* BOLT-offers #12:
1152 * - MUST set `offer_id` to the Merkle root of the offer as described
1153 * in [Signature Calculation](#signature-calculation).
1154 */
1155 invreq->offer_id = tal(invreq, struct sha256);
1156 merkle_tlv(sent->offer->fields, invreq->offer_id);
1157
1158 /* Check if they are trying to send us money. */
1159 if (sent->offer->send_invoice)
1160 return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
1161 "Offer wants an invoice, not invoice_request");
1162
1163 /* BOLT-offers #12:
1164 * - SHOULD not respond to an offer if the current time is after
1165 * `absolute_expiry`.
1166 */
1167 if (sent->offer->absolute_expiry
1168 && time_now().ts.tv_sec > *sent->offer->absolute_expiry)
1169 return command_fail(cmd, OFFER_EXPIRED, "Offer expired");
1170
1171 /* BOLT-offers-recurrence #12:
1172 * - if the offer did not specify `amount`:
1173 * - MUST specify `amount`.`msat` in multiples of the minimum
1174 * lightning-payable unit (e.g. milli-satoshis for bitcoin) for
1175 * `chain` (or for bitcoin, if there is no `chain`).
1176 * - otherwise:

Callers

nothing calls this directly

Calls 10

time_nowFunction · 0.85
plugin_feature_setFunction · 0.85
force_payer_secretFunction · 0.85
invrequest_encodeFunction · 0.85
command_param_failedFunction · 0.70
command_failFunction · 0.70
send_outreqFunction · 0.70
paramFunction · 0.50
merkle_tlvFunction · 0.50
json_add_stringFunction · 0.50

Tested by

no test coverage detected