Skip to content

Commit 5e8b987

Browse files
committed
split array accessors known a priori into fixed and variable length ones
1 parent 722d6c5 commit 5e8b987

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

src/conversion_helper.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, key: str, size: int = -1, length_key = None):
1111
self.length_key: str = length_key
1212

1313

14-
array_accessor_types: dict[str, ArrayAccessorType] = {
14+
array_accessor_types_fixed_length: dict[str, ArrayAccessorType] = {
1515
"LDKThirtyTwoBytes": ArrayAccessorType(size=32, key='data'),
1616
"LDKPaymentPreimage": ArrayAccessorType(size=32, key='data'),
1717
"LDKPublicKey": ArrayAccessorType(size=33, key='compressed_form'),
@@ -23,11 +23,20 @@ def __init__(self, key: str, size: int = -1, length_key = None):
2323
"LDKTwelveBytes": ArrayAccessorType(size=12, key='data'),
2424
"LDKSixteenBytes": ArrayAccessorType(size=16, key='data'),
2525
"LDKTwentyBytes": ArrayAccessorType(size=20, key='data'),
26-
"LDKRecoverableSignature": ArrayAccessorType(size=68, key='serialized_form'),
26+
"LDKRecoverableSignature": ArrayAccessorType(size=68, key='serialized_form')
27+
}
28+
29+
array_accessor_types_variable_length: dict[str, ArrayAccessorType] = {
30+
"LDKu5slice": ArrayAccessorType(length_key='datalen', key='data'),
2731
"LDKu8slice": ArrayAccessorType(length_key='datalen', key='data'),
2832
"LDKCVec_u8Z": ArrayAccessorType(length_key='datalen', key='data'),
2933
"LDKCVec_u5Z": ArrayAccessorType(length_key='datalen', key='data'),
30-
"LDKTransaction": ArrayAccessorType(length_key='datalen', key='data'),
34+
"LDKTransaction": ArrayAccessorType(length_key='datalen', key='data')
35+
}
36+
37+
array_accessor_types: dict[str, ArrayAccessorType] = {
38+
**array_accessor_types_fixed_length,
39+
**array_accessor_types_variable_length
3140
}
3241

3342
class ConversionHelper:
@@ -348,17 +357,6 @@ def prepare_native_to_swift_callback_arguments(cls, argument_types, array_unwrap
348357
elif received_raw_type is not None and received_raw_type.startswith('LDK'):
349358
swift_local_conversion_prefix = f'Bindings.{received_raw_type}_to_array(nativeType: '
350359
swift_local_conversion_suffix = ')'
351-
elif received_raw_type == 'LDKTransaction':
352-
swift_local_conversion_prefix = f'Bindings.LDKTransaction_to_array(nativeType: '
353-
swift_local_conversion_suffix = ')'
354-
published_swift_type = '[UInt8]'
355-
elif received_raw_type == 'LDKu8slice':
356-
swift_local_conversion_prefix = f'Bindings.LDKu8slice_to_array(nativeType: '
357-
swift_local_conversion_suffix = ')'
358-
published_swift_type = '[UInt8]'
359-
elif received_raw_type == 'LDKCVec_PaymentPreimageZ':
360-
swift_local_conversion_prefix = f'Bindings.LDKCVec_PaymentPreimageZ_to_array(nativeType: '
361-
swift_local_conversion_suffix = ')'
362360
elif received_raw_type is not None and received_raw_type.startswith('LDK'):
363361
if cls.is_instance_type(published_swift_type, received_raw_type):
364362
swift_local_conversion_prefix = f'{published_swift_type}(pointer: '

src/lightning_header_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def populate_type_details(self):
219219
vec_ty_match = line_indicates_vec_regex.match(struct_line)
220220
if vec_ty_match is not None and struct_name.startswith("LDKCVec_"):
221221
iterated_type = vec_ty_match.group(2)
222-
elif struct_name in ['LDKTransaction', 'LDKCVec_u8Z', 'LDKu8slice', 'LDKu5slice', 'LDKCVec_u5Z']:
222+
elif struct_name in src.conversion_helper.array_accessor_types_variable_length.keys():
223223
iterated_type = 'uint8_t'
224224
elif struct_name.startswith("LDKC2Tuple_") or struct_name.startswith("LDKC3Tuple_"):
225225
# this check should only be run once, it can be moved out of the loop

0 commit comments

Comments
 (0)