| 166 | } |
| 167 | |
| 168 | struct tlv_offer *offer_decode(const tal_t *ctx, |
| 169 | const char *b12, size_t b12len, |
| 170 | const struct feature_set *our_features, |
| 171 | const struct chainparams *must_be_chain, |
| 172 | const char **fail) |
| 173 | { |
| 174 | struct tlv_offer *offer; |
| 175 | const u8 *data; |
| 176 | size_t dlen; |
| 177 | const struct tlv_field *badf; |
| 178 | const struct recurrence *recurr; |
| 179 | |
| 180 | data = b12_string_to_data(tmpctx, b12, b12len, "lno", &dlen, fail); |
| 181 | if (!data) { |
| 182 | tal_steal(ctx, *fail); |
| 183 | return NULL; |
| 184 | } |
| 185 | |
| 186 | offer = fromwire_tlv_offer(ctx, &data, &dlen); |
| 187 | if (!offer) { |
| 188 | *fail = tal_fmt(ctx, "invalid offer data"); |
| 189 | return NULL; |
| 190 | } |
| 191 | |
| 192 | *fail = check_features_and_chain(ctx, |
| 193 | our_features, must_be_chain, |
| 194 | offer->offer_features, |
| 195 | BOLT12_OFFER_FEATURE, |
| 196 | offer->offer_chains, |
| 197 | tal_count(offer->offer_chains)); |
| 198 | if (*fail) |
| 199 | return tal_free(offer); |
| 200 | |
| 201 | /* BOLT #12: |
| 202 | * A reader of an offer: |
| 203 | * - if the offer contains any TLV fields outside the inclusive ranges: 1 to 79 and 1000000000 to 1999999999: |
| 204 | * - MUST NOT respond to the offer. |
| 205 | * - if `offer_features` contains unknown _odd_ bits that are non-zero: |
| 206 | * - MUST ignore the bit. |
| 207 | * - if `offer_features` contains unknown _even_ bits that are non-zero: |
| 208 | * - MUST NOT respond to the offer. |
| 209 | * - SHOULD indicate the unknown bit to the user. |
| 210 | */ |
| 211 | badf = any_field_outside_range(offer->fields, false, |
| 212 | 1, 79, |
| 213 | 1000000000, 1999999999); |
| 214 | if (badf) { |
| 215 | *fail = tal_fmt(ctx, |
| 216 | "Offer %"PRIu64" field outside offer range", |
| 217 | badf->numtype); |
| 218 | return tal_free(offer); |
| 219 | } |
| 220 | |
| 221 | /* BOLT #12: |
| 222 | * |
| 223 | * - if `offer_amount` is set and `offer_description` is not set: |
| 224 | * - MUST NOT respond to the offer. |
| 225 | */ |