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

Function maybe_encode_9

common/bolt11.c:1072–1102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1070}
1071
1072static void maybe_encode_9(u5 **data, const u8 *features,
1073 bool have_payment_metadata)
1074{
1075 u5 *f5 = tal_arr(NULL, u5, 0);
1076
1077 for (size_t i = 0; i < tal_count(features) * CHAR_BIT; i++) {
1078 if (!feature_is_set(features, i))
1079 continue;
1080
1081 /* Don't set option_payment_metadata unless we acually use it */
1082 if (!have_payment_metadata
1083 && COMPULSORY_FEATURE(i) == OPT_PAYMENT_METADATA)
1084 continue;
1085
1086 /* We expand it out so it makes a BE 5-bit/btye bitfield */
1087 set_feature_bit(&f5, (i / 5) * 8 + (i % 5));
1088 }
1089
1090 /* BOLT #11:
1091 *
1092 * - if `9` contains non-zero bits:
1093 * - SHOULD use the minimum `data_length` possible.
1094 * - otherwise:
1095 * - MUST omit the `9` field altogether.
1096 */
1097 if (tal_count(f5) != 0) {
1098 push_field_type_and_len(data, '9', tal_count(f5) * 5);
1099 tal_expand(data, f5, tal_count(f5));
1100 }
1101 tal_free(f5);
1102}
1103
1104static bool encode_extra(u5 **data, const struct bolt11_field *extra)
1105{

Callers 1

bolt11_encode_Function · 0.85

Calls 4

set_feature_bitFunction · 0.85
push_field_type_and_lenFunction · 0.85
tal_freeFunction · 0.85
feature_is_setFunction · 0.70

Tested by

no test coverage detected