Inclusive span of tlv range >= minfield and <= maxfield */
| 668 | |
| 669 | /* Inclusive span of tlv range >= minfield and <= maxfield */ |
| 670 | size_t tlv_span(const u8 *tlvstream, u64 minfield, u64 maxfield, |
| 671 | size_t *startp) |
| 672 | { |
| 673 | const u8 *cursor = tlvstream; |
| 674 | size_t tlvlen = tal_bytelen(tlvstream); |
| 675 | const u8 *start, *end; |
| 676 | |
| 677 | start = end = NULL; |
| 678 | while (tlvlen) { |
| 679 | const u8 *before = cursor; |
| 680 | bigsize_t type = fromwire_bigsize(&cursor, &tlvlen); |
| 681 | bigsize_t len = fromwire_bigsize(&cursor, &tlvlen); |
| 682 | if (type >= minfield && start == NULL) |
| 683 | start = before; |
| 684 | if (type > maxfield) |
| 685 | break; |
| 686 | fromwire_pad(&cursor, &tlvlen, len); |
| 687 | end = cursor; |
| 688 | } |
| 689 | if (!start) |
| 690 | start = end; |
| 691 | |
| 692 | if (startp) |
| 693 | *startp = start - tlvstream; |
| 694 | return end - start; |
| 695 | } |
| 696 | |
| 697 | static void calc_offer(const u8 *tlvstream, struct sha256 *id) |
| 698 | { |