| 1217 | } |
| 1218 | |
| 1219 | static void maybe_encode_9(u5 **data, const u8 *features, |
| 1220 | bool have_payment_metadata) |
| 1221 | { |
| 1222 | u5 *f5 = tal_arr(NULL, u5, 0); |
| 1223 | |
| 1224 | for (size_t i = 0; i < tal_count(features) * CHAR_BIT; i++) { |
| 1225 | if (!feature_is_set(features, i)) |
| 1226 | continue; |
| 1227 | |
| 1228 | /* Don't set option_payment_metadata unless we acually use it */ |
| 1229 | if (!have_payment_metadata |
| 1230 | && COMPULSORY_FEATURE(i) == OPT_PAYMENT_METADATA) |
| 1231 | continue; |
| 1232 | |
| 1233 | /* We expand it out so it makes a BE 5-bit/btye bitfield */ |
| 1234 | set_feature_bit(&f5, (i / 5) * 8 + (i % 5)); |
| 1235 | } |
| 1236 | |
| 1237 | /* BOLT #11: |
| 1238 | * |
| 1239 | * - if `9` contains non-zero bits: |
| 1240 | * - MUST use the minimum `data_length` possible to encode the non-zero bits |
| 1241 | * with no 0 field-elements at the start. |
| 1242 | * - otherwise: |
| 1243 | * - MUST omit the `9` field altogether. |
| 1244 | */ |
| 1245 | if (tal_count(f5) != 0) { |
| 1246 | push_field_type_and_len(data, '9', tal_count(f5) * 5); |
| 1247 | tal_expand(data, f5, tal_count(f5)); |
| 1248 | } |
| 1249 | tal_free(f5); |
| 1250 | } |
| 1251 | |
| 1252 | static bool encode_extra(u5 **data, const struct bolt11_field *extra) |
| 1253 | { |
no test coverage detected