MCPcopy Create free account
hub / github.com/ElementsProject/lightning / fromwire_tlv

Function fromwire_tlv

wire/tlvstream.c:146–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146bool fromwire_tlv(const u8 **cursor, size_t *max,
147 const struct tlv_record_type *types, size_t num_types,
148 void *record, struct tlv_field **fields,
149 const u64 *extra_types,
150 size_t *err_off, u64 *err_type)
151{
152 bool first = true;
153 u64 prev_type = 0;
154 size_t initial_len = *max;
155
156 update_err_off(err_off, initial_len, *max);
157 while (*max > 0) {
158 struct tlv_field field;
159
160 /* BOLT #1:
161 *
162 * The `type` is encoded using the BigSize format.
163 */
164 field.numtype = fromwire_bigsize(cursor, max);
165
166 /* BOLT #1:
167 * - if a `type` or `length` is not minimally encoded:
168 * - MUST fail to parse the `tlv_stream`.
169 */
170 if (!*cursor) {
171 SUPERVERBOSE("type");
172 if (err_type)
173 *err_type = 0;
174 goto fail;
175 }
176
177 /* BOLT #1:
178 * - if decoded `type`s are not strictly-increasing
179 * (including situations when two or more occurrences
180 * of the same `type` are met):
181 * - MUST fail to parse the `tlv_stream`.
182 */
183 if (!first && field.numtype <= prev_type) {
184 if (field.numtype == prev_type)
185 SUPERVERBOSE("duplicate tlv type");
186 else
187 SUPERVERBOSE("invalid ordering");
188 if (err_type)
189 *err_type = field.numtype;
190 goto fail;
191 }
192 first = false;
193 prev_type = field.numtype;
194
195 /* BOLT #1:
196 * - if `type` is known:
197 * - MUST decode the next `length` bytes using the known
198 * encoding for `type`.
199 */
200 field.meta = NULL;
201 for (size_t i = 0; i < num_types; i++) {
202 if (types[i].type == field.numtype) {
203 field.meta = &types[i];

Callers 2

htlc_accepted_hook_finalFunction · 0.50
htlc_accepted_callFunction · 0.50

Calls 4

update_err_offFunction · 0.85
tlv_type_is_allowedFunction · 0.85
fromwire_failFunction · 0.70
fromwire_bigsizeFunction · 0.50

Tested by

no test coverage detected