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

Function json_add_offer

plugins/offers.c:302–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302static void json_add_offer(struct json_stream *js, const struct tlv_offer *offer)
303{
304 struct sha256 offer_id;
305 bool valid = true;
306
307 merkle_tlv(offer->fields, &offer_id);
308 json_add_sha256(js, "offer_id", &offer_id);
309 if (offer->chains)
310 json_add_chains(js, offer->chains);
311 if (offer->currency) {
312 const struct iso4217_name_and_divisor *iso4217;
313 json_add_stringn(js, "currency",
314 offer->currency, tal_bytelen(offer->currency));
315 if (offer->amount)
316 json_add_u64(js, "amount", *offer->amount);
317 iso4217 = find_iso4217(offer->currency,
318 tal_bytelen(offer->currency));
319 if (iso4217)
320 json_add_num(js, "minor_unit", iso4217->minor_unit);
321 else
322 json_add_string(js, "warning_offer_unknown_currency",
323 "unknown currency code");
324 } else if (offer->amount)
325 json_add_amount_msat_only(js, "amount_msat",
326 amount_msat(*offer->amount));
327 if (offer->send_invoice)
328 json_add_bool(js, "send_invoice", true);
329 if (offer->refund_for)
330 json_add_sha256(js, "refund_for", offer->refund_for);
331
332 /* BOLT-offers #12:
333 * A reader of an offer:
334 *...
335 * - if `node_id` or `description` is not set:
336 * - MUST NOT respond to the offer.
337 */
338 if (offer->description)
339 json_add_stringn(js, "description",
340 offer->description,
341 tal_bytelen(offer->description));
342 else {
343 json_add_string(js, "warning_offer_missing_description",
344 "offers without a description are invalid");
345 valid = false;
346 }
347
348 if (offer->issuer)
349 json_add_stringn(js, "issuer", offer->issuer,
350 tal_bytelen(offer->issuer));
351 if (offer->features)
352 json_add_hex_talarr(js, "features", offer->features);
353 if (offer->absolute_expiry)
354 json_add_u64(js, "absolute_expiry",
355 *offer->absolute_expiry);
356 if (offer->paths)
357 valid &= json_add_blinded_paths(js, offer->paths, NULL);
358
359 if (offer->quantity_min)

Callers 1

json_decodeFunction · 0.85

Calls 15

json_add_chainsFunction · 0.85
tal_bytelenFunction · 0.85
find_iso4217Function · 0.85
json_add_blinded_pathsFunction · 0.85
json_add_point32Function · 0.85
json_add_bip340sigFunction · 0.85
amount_msatClass · 0.70
merkle_tlvFunction · 0.50
json_add_sha256Function · 0.50
json_add_stringnFunction · 0.50
json_add_u64Function · 0.50

Tested by

no test coverage detected