Skip to content

Commit 46e7ffb

Browse files
committed
Update to 0.0.14 step 3
1 parent 0e8a8e9 commit 46e7ffb

File tree

12 files changed

+154
-113
lines changed

12 files changed

+154
-113
lines changed

__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from src.sdk_generator import generate_sdk
1+
from src.sdk_generator import generate_sdk, cleanup_bindings
22

3+
cleanup_bindings()
34
generate_sdk()

bindings/LDK/Bindings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6057,7 +6057,7 @@ withUnsafePointer(to: scorer.cOpaqueStruct!) { (scorerPointer: UnsafePointer<LDK
60576057
*/
60586058

60596059
public class func get_ldk_swift_bindings_version() -> String {
6060-
return "e1e1c09ce5f801f30ca2b644e540821050272436"
6060+
return "0e8a8e97affee47cd2c0af734ee76c3bb396663c"
60616061
}
60626062

60636063
}

bindings/LDK/options/Option_TypeZ.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class Option_TypeZ: NativeTypeWrapper {
66
internal var cOpaqueStruct: LDKCOption_TypeZ?
77

88
/* DEFAULT_CONSTRUCTOR_START */
9-
public init(value: Type?) {
9+
public init(value: BindingsType?) {
1010
Self.instanceCounter += 1
1111
self.instanceNumber = Self.instanceCounter
1212

@@ -42,22 +42,22 @@ public class Option_TypeZ: NativeTypeWrapper {
4242

4343
/* OPTION_METHODS_START */
4444

45-
public func getValue() -> Type? {
45+
public func getValue() -> BindingsType? {
4646

4747

4848
if self.cOpaqueStruct!.tag == LDKCOption_TypeZ_None {
4949
return nil
5050
}
5151
if self.cOpaqueStruct!.tag == LDKCOption_TypeZ_Some {
52-
return Type(pointer: self.cOpaqueStruct!.some)
52+
return BindingsType(pointer: self.cOpaqueStruct!.some)
5353
}
5454
assert(false, "invalid option enum value")
5555
return nil
5656

5757

5858
}
5959

60-
public class func some(o: Type) -> Option_TypeZ {
60+
public class func some(o: BindingsType) -> Option_TypeZ {
6161

6262
return Option_TypeZ(pointer: COption_TypeZ_some(o.danglingClone().cOpaqueStruct!));
6363
}

bindings/LDK/traits/CustomMessageHandler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ open class CustomMessageHandler: NativeTypeWrapper {
1616
func handle_custom_messageCallback(pointer: UnsafeRawPointer?, msg: LDKType, sender_node_id: LDKPublicKey) -> LDKCResult_NoneLightningErrorZ {
1717
let instance: CustomMessageHandler = Bindings.pointerToInstance(pointer: pointer!, sourceMarker: "CustomMessageHandler.swift::handle_custom_message")
1818

19-
return instance.handle_custom_message(msg: Type(pointer: msg), sender_node_id: Bindings.tuple33_to_array(nativeType: sender_node_id.compressed_form)).cOpaqueStruct!
19+
return instance.handle_custom_message(msg: BindingsType(pointer: msg), sender_node_id: Bindings.tuple33_to_array(nativeType: sender_node_id.compressed_form)).cOpaqueStruct!
2020
}
2121

2222
func get_and_clear_pending_msgCallback(pointer: UnsafeRawPointer?) -> LDKCVec_C2Tuple_PublicKeyTypeZZ {
@@ -83,7 +83,7 @@ open class CustomMessageHandler: NativeTypeWrapper {
8383
}
8484

8585

86-
open func handle_custom_message(msg: Type, sender_node_id: [UInt8]) -> Result_NoneLightningErrorZ {
86+
open func handle_custom_message(msg: BindingsType, sender_node_id: [UInt8]) -> Result_NoneLightningErrorZ {
8787
/* EDIT ME */
8888
Bindings.print("CustomMessageHandler::handle_custom_message should be overridden!", severity: .WARNING)
8989

@@ -112,7 +112,7 @@ return [LDKC2Tuple_PublicKeyTypeZ]()
112112
public class NativelyImplementedCustomMessageHandler: CustomMessageHandler {
113113
/* SWIFT_DEFAULT_CALLBACKS_START */
114114

115-
public override func handle_custom_message(msg: Type, sender_node_id: [UInt8]) -> Result_NoneLightningErrorZ {
115+
public override func handle_custom_message(msg: BindingsType, sender_node_id: [UInt8]) -> Result_NoneLightningErrorZ {
116116

117117

118118
return

bindings/LDK/traits/Type.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ open class Type: NativeTypeWrapper {
7474
/* SWIFT_CALLBACKS_START */
7575

7676

77-
public func clone() -> Type {
77+
public func clone() -> BindingsType {
7878

7979
return withUnsafePointer(to: self.cOpaqueStruct!) { (origPointer: UnsafePointer<LDKType>) in
8080

81-
Type(pointer: Type_clone(origPointer))
81+
BindingsType(pointer: Type_clone(origPointer))
8282

8383
}
8484
}
8585

8686

87-
internal func danglingClone() -> Type {
87+
internal func danglingClone() -> BindingsType {
8888
let dangledClone = self.clone()
8989
dangledClone.dangling = true
9090
return dangledClone

bindings/LDK/tuples/C2Tuple_PublicKeyTypeZ.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ C2Tuple_PublicKeyTypeZ_clone(origPointer)
3737
}
3838

3939

40-
public class func new(a: [UInt8], b: Type) -> C2Tuple_PublicKeyTypeZ {
40+
public class func new(a: [UInt8], b: BindingsType) -> C2Tuple_PublicKeyTypeZ {
4141

4242
return C2Tuple_PublicKeyTypeZ(pointer: C2Tuple_PublicKeyTypeZ_new(Bindings.new_LDKPublicKey(array: a), b.danglingClone().cOpaqueStruct!));
4343
}

src/conversion_helper.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ class ConversionHelper:
1010
freeable_types = set()
1111
nullable_inner_types = {'LDKOutPoint'}
1212

13+
@classmethod
14+
def is_instance_type(cls, swift_type: str, raw_rust_type: str, include_options_and_results: bool = True):
15+
if raw_rust_type == 'LDK' + swift_type:
16+
return True
17+
18+
if include_options_and_results:
19+
if raw_rust_type == 'LDKC' + swift_type:
20+
return True
21+
22+
# for edge cases
23+
if raw_rust_type == 'LDKType' and swift_type == 'BindingsType':
24+
return True
25+
26+
return False
27+
28+
@classmethod
29+
def is_array_type(cls, swift_type: str):
30+
return swift_type.startswith('[')
31+
1332
@classmethod
1433
def prepare_swift_to_native_arguments(cls, argument_types, is_trait_callback=False, force_pass_instance=False, is_free_method=False, is_returned_value_freeable=False, unwrap_complex_arrays = True, array_unwrapping_preparation_only = False, is_trait_default_redirect = False):
1534
swift_arguments = []
@@ -204,9 +223,7 @@ def prepare_swift_to_native_arguments(cls, argument_types, is_trait_callback=Fal
204223
swift_redirection_arguments.append(f'{argument_name}: {argument_name}')
205224

206225
# native_arguments.append(f'{passed_argument_name}')
207-
if current_argument_details.rust_obj == 'LDK' + swift_argument_type and not current_argument_details.is_ptr:
208-
native_arguments.append(f'{passed_argument_name}{clone_infix}.cOpaqueStruct!')
209-
elif current_argument_details.rust_obj == 'LDKC' + swift_argument_type and not current_argument_details.is_ptr:
226+
if cls.is_instance_type(swift_argument_type, current_argument_details.rust_obj) and not current_argument_details.is_ptr:
210227
native_arguments.append(f'{passed_argument_name}{clone_infix}.cOpaqueStruct!')
211228
elif current_argument_details.rust_obj is not None and current_argument_details.rust_obj.startswith('LDK') and swift_argument_type.startswith('[') and not is_pointer_to_array:
212229
# if current_argument_details.swift_type == '[UInt8]' and not current_argument_details.swift_raw_type.startswith('LDKC'):
@@ -308,7 +325,13 @@ def prepare_native_to_swift_callback_arguments(cls, argument_types, array_unwrap
308325
swift_local_conversion_suffix = ')'
309326
published_swift_type = '[UInt8]'
310327
elif received_raw_type is not None and received_raw_type.startswith('LDK'):
311-
if received_raw_type == 'LDK' + published_swift_type:
328+
if cls.is_instance_type(published_swift_type, received_raw_type):
329+
swift_local_conversion_prefix = f'{published_swift_type}(pointer: '
330+
swift_local_conversion_suffix = ')'
331+
# TODO: see if `current_argument_details.pass_by_ref` condition is necessary
332+
if current_argument_details.passed_as_ptr and current_argument_details.pass_by_ref:
333+
swift_local_conversion_suffix = ').dangle()'
334+
elif received_raw_type.startswith('LDKCOption_') and received_raw_type == 'LDKC' + published_swift_type:
312335
swift_local_conversion_prefix = f'{published_swift_type}(pointer: '
313336
swift_local_conversion_suffix = ')'
314337
# TODO: see if `current_argument_details.pass_by_ref` condition is necessary
@@ -439,7 +462,7 @@ def prepare_return_value(cls, return_type, is_clone_method=False, is_trait_insta
439462
array_length = return_type.arr_len
440463
return_prefix = f'Bindings.tuple{array_length}_to_array(nativeType: '
441464
return_suffix = ')'
442-
elif rust_return_type == 'LDK' + return_type_string:
465+
elif cls.is_instance_type(return_type_string, rust_return_type):
443466
return_prefix = f'{swift_return_instantiation_type}(pointer: '
444467
if is_clone_method:
445468
# return_prefix = 'Self(pointer: '
@@ -450,15 +473,6 @@ def prepare_return_value(cls, return_type, is_clone_method=False, is_trait_insta
450473
if is_trait_instantiator or is_raw_property_getter:
451474
# replace if with elif if it's only to be used for _as methods (ChannelManagerReadArgs with get_ vs KeysManager with as_)
452475
return_suffix = return_suffix.rstrip(')') + ', anchor: self)'
453-
elif rust_return_type == 'LDKC' + return_type_string:
454-
return_prefix = f'{swift_return_instantiation_type}(pointer: '
455-
if is_clone_method:
456-
# return_prefix = 'Self(pointer: '
457-
pass
458-
return_suffix = ')'
459-
if is_raw_property_getter:
460-
# return_suffix += '.dangle()'
461-
return_suffix = return_suffix.rstrip(')') + ', anchor: self)'
462476
# if is_trait_instantiator:
463477
# only applies to tuples, but is never hit
464478
# return_suffix = ', anchor: self)'

src/generators/option_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def generate_option(self, struct_name, struct_details, all_type_details={}):
9797
swift_local_conversion_prefix = ''
9898
swift_local_conversion_suffix = ''
9999

100-
if raw_rust_type == 'LDK' + swift_type:
100+
if ConversionHelper.is_instance_type(swift_type, raw_rust_type):
101101
native_conversion_prefix = ''
102102
native_conversion_suffix = '.cOpaqueStruct!'
103103
swift_local_conversion_prefix = f'{swift_type}(pointer: '

src/generators/trait_generator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ def generate_trait(self, struct_name, struct_details):
151151
# if current_lambda['return_type'].rust_obj is not None and current_lambda['return_type'].rust_obj.startswith(
152152
# 'LDK'):
153153
current_return_type_details = current_lambda['return_type']
154-
if current_return_type_details.rust_obj is not None and (
155-
current_return_type_details.rust_obj == 'LDK' + swift_return_type or current_return_type_details.rust_obj == 'LDKC' + swift_return_type):
154+
if current_return_type_details.rust_obj is not None and ConversionHelper.is_instance_type(swift_return_type, current_return_type_details.rust_obj):
156155
swift_raw_return_type = current_return_type_details.rust_obj
157156
return_conversion_suffix = '.cOpaqueStruct!'
158157
elif swift_raw_return_type.startswith('(UInt'):

src/generators/util_generators/static_method_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def generate_static_methods(self, static_methods):
2727
# continue
2828
pass
2929

30+
if native_method_name == '__unmangle_inner_ptr':
31+
continue
32+
3033
arguments = ConversionHelper.prepare_swift_to_native_arguments(current_method['argument_types'], False)
3134
return_wrappers = ConversionHelper.prepare_return_value(current_method['return_type'], False)
3235

0 commit comments

Comments
 (0)