| 377 | } |
| 378 | |
| 379 | struct 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 | */ |