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