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

Function offer_decode

common/bolt12.c:379–532  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377}
378
379struct tlv_offer *offer_decode(const tal_t *ctx,
380 const char *b12, size_t b12len,
381 const struct feature_set *our_features,
382 const struct chainparams *must_be_chain,
383 const char **fail)
384{
385 struct tlv_offer *offer;
386 const u8 *data;
387 size_t dlen;
388 const struct tlv_field *badf;
389 const struct recurrence *recurr;
390
391 data = b12_string_to_data(tmpctx, b12, b12len, "lno", &dlen, fail);
392 if (!data) {
393 tal_steal(ctx, *fail);
394 return NULL;
395 }
396
397 offer = fromwire_tlv_offer(ctx, &data, &dlen);
398 if (!offer) {
399 *fail = tal_fmt(ctx, "invalid offer data");
400 return NULL;
401 }
402
403 *fail = check_features_and_chain(ctx,
404 our_features, must_be_chain,
405 offer->offer_features,
406 BOLT12_OFFER_FEATURE,
407 offer->offer_chains,
408 tal_count(offer->offer_chains));
409 if (*fail)
410 return tal_free(offer);
411
412 /* BOLT #12:
413 * A reader of an offer:
414 * - if the offer contains any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999:
415 * - MUST NOT respond to the offer.
416 * - if `offer_features` contains unknown _odd_ bits that are non-zero:
417 * - MUST ignore the bit.
418 * - if `offer_features` contains unknown _even_ bits that are non-zero:
419 * - MUST NOT respond to the offer.
420 * - SHOULD indicate the unknown bit to the user.
421 */
422 badf = any_field_outside_range(offer->fields, false,
423 1, 79,
424 1000000000, 1999999999);
425 if (badf) {
426 *fail = tal_fmt(ctx,
427 "Offer %"PRIu64" field outside offer range",
428 badf->numtype);
429 return tal_free(offer);
430 }
431
432 /* BOLT #12:
433 *
434 * - if `offer_amount` is set and `offer_description` is not set:
435 * - MUST NOT respond to the offer.
436 */

Callers 11

param_b12_offerFunction · 0.85
runFunction · 0.85
mainFunction · 0.85
print_valid_offerFunction · 0.85
param_offerFunction · 0.85
param_bolt12_invstringFunction · 0.85
param_decodableFunction · 0.85
check_offer_payableFunction · 0.85
mainFunction · 0.85

Calls 6

b12_string_to_dataFunction · 0.85
check_features_and_chainFunction · 0.85
tal_freeFunction · 0.85
any_field_outside_rangeFunction · 0.85
offer_recurrenceFunction · 0.85
fromwire_tlv_offerFunction · 0.50

Tested by 2

mainFunction · 0.68
print_valid_offerFunction · 0.68