| 542 | } |
| 543 | |
| 544 | struct tlv_invoice_request *invrequest_decode(const tal_t *ctx, |
| 545 | const char *b12, size_t b12len, |
| 546 | const struct feature_set *our_features, |
| 547 | const struct chainparams *must_be_chain, |
| 548 | const char **fail) |
| 549 | { |
| 550 | struct tlv_invoice_request *invrequest; |
| 551 | const u8 *data; |
| 552 | size_t dlen; |
| 553 | const struct tlv_field *badf; |
| 554 | |
| 555 | data = b12_string_to_data(tmpctx, b12, b12len, "lnr", &dlen, fail); |
| 556 | if (!data) { |
| 557 | tal_steal(ctx, *fail); |
| 558 | return NULL; |
| 559 | } |
| 560 | |
| 561 | invrequest = fromwire_tlv_invoice_request(ctx, &data, &dlen); |
| 562 | if (!invrequest) { |
| 563 | *fail = tal_fmt(ctx, "invalid invreq data"); |
| 564 | return NULL; |
| 565 | } |
| 566 | |
| 567 | *fail = check_features_and_chain(ctx, |
| 568 | our_features, must_be_chain, |
| 569 | invrequest->invreq_features, |
| 570 | BOLT12_INVREQ_FEATURE, |
| 571 | invrequest->invreq_chain, 1); |
| 572 | if (*fail) |
| 573 | return tal_free(invrequest); |
| 574 | |
| 575 | /* BOLT #12: |
| 576 | * The reader: |
| 577 | *... |
| 578 | * - MUST reject the invoice request if any non-signature TLV fields are outside the inclusive ranges: 0 to 159 and 1000000000 to 2999999999 |
| 579 | */ |
| 580 | badf = any_field_outside_range(invrequest->fields, true, |
| 581 | 0, 159, |
| 582 | 1000000000, 2999999999); |
| 583 | if (badf) { |
| 584 | *fail = tal_fmt(ctx, |
| 585 | "Invoice request %"PRIu64" field outside invoice request range", |
| 586 | badf->numtype); |
| 587 | return tal_free(invrequest); |
| 588 | } |
| 589 | |
| 590 | /* Likewise, sendinvoice assumes a non-NULL invreq_paths has a path. */ |
| 591 | if (invrequest->invreq_paths && tal_count(invrequest->invreq_paths) == 0) { |
| 592 | *fail = tal_strdup(ctx, "Invoice request contains an empty invreq_paths"); |
| 593 | return tal_free(invrequest); |
| 594 | } |
| 595 | |
| 596 | /* BOLT #12: |
| 597 | * - if `num_hops` is 0 in any `blinded_path` in `invreq_paths`: |
| 598 | * - MUST reject the invoice request. |
| 599 | */ |
| 600 | for (size_t i = 0; i < tal_count(invrequest->invreq_paths); i++) { |
| 601 | if (tal_count(invrequest->invreq_paths[i]->path) == 0) { |