| 162 | } |
| 163 | |
| 164 | struct tlv_offer *offer_decode(const tal_t *ctx, |
| 165 | const char *b12, size_t b12len, |
| 166 | const struct feature_set *our_features, |
| 167 | const struct chainparams *must_be_chain, |
| 168 | char **fail) |
| 169 | { |
| 170 | struct tlv_offer *offer; |
| 171 | const u8 *data; |
| 172 | size_t dlen; |
| 173 | |
| 174 | data = string_to_data(tmpctx, b12, b12len, "lno", &dlen, fail); |
| 175 | if (!data) |
| 176 | return NULL;; |
| 177 | |
| 178 | offer = fromwire_tlv_offer(ctx, &data, &dlen); |
| 179 | if (!offer) { |
| 180 | *fail = tal_fmt(ctx, "invalid offer data"); |
| 181 | return NULL; |
| 182 | } |
| 183 | |
| 184 | *fail = check_features_and_chain(ctx, |
| 185 | our_features, must_be_chain, |
| 186 | offer->features, |
| 187 | offer->chains, |
| 188 | tal_count(offer->chains)); |
| 189 | if (*fail) |
| 190 | return tal_free(offer); |
| 191 | |
| 192 | /* BOLT-offers #12: |
| 193 | * - if `signature` is present, but is not a valid signature using |
| 194 | * `node_id` as described in [Signature Calculation](#signature-calculation): |
| 195 | * - MUST NOT respond to the offer. |
| 196 | */ |
| 197 | if (offer->signature) { |
| 198 | *fail = check_signature(ctx, offer->fields, |
| 199 | "offer", "signature", |
| 200 | offer->node_id, offer->signature); |
| 201 | if (*fail) |
| 202 | return tal_free(offer); |
| 203 | } |
| 204 | |
| 205 | return offer; |
| 206 | } |
| 207 | |
| 208 | char *invrequest_encode(const tal_t *ctx, const struct tlv_invoice_request *invrequest_tlv) |
| 209 | { |