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

Function fromwire_tlv

wire/tlvstream.c:144–300  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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