Skip to content

Commit a80dcf5

Browse files
committed
Dangle LDKTransactions when they're generated in-place
1 parent 87ff710 commit a80dcf5

9 files changed

+16
-14
lines changed

bindings/LDK/results/Result_TransactionNoneZ.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class Result_TransactionNoneZ: NativeTypeWrapper {
5252
oWrapper.noOpRetain()
5353
}
5454

55-
return Result_TransactionNoneZ(pointer: CResult_TransactionNoneZ_ok(oWrapper.cOpaqueStruct!));
55+
return Result_TransactionNoneZ(pointer: CResult_TransactionNoneZ_ok(oWrapper.dangle().cOpaqueStruct!));
5656
}
5757

5858
public class func err() -> Result_TransactionNoneZ {

bindings/LDK/structs/BuiltCommitmentTransaction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class BuiltCommitmentTransaction: NativeTypeWrapper {
1616
transaction_argWrapper.noOpRetain()
1717
}
1818

19-
self.cOpaqueStruct = BuiltCommitmentTransaction_new(transaction_argWrapper.cOpaqueStruct!, Bindings.new_LDKThirtyTwoBytes(array: txid_arg))
19+
self.cOpaqueStruct = BuiltCommitmentTransaction_new(transaction_argWrapper.dangle().cOpaqueStruct!, Bindings.new_LDKThirtyTwoBytes(array: txid_arg))
2020
super.init(conflictAvoidingVariableName: 0)
2121
}
2222
/* DEFAULT_CONSTRUCTOR_END */
@@ -56,7 +56,7 @@ BuiltCommitmentTransaction_get_transaction(this_ptrPointer)
5656
valWrapper.noOpRetain()
5757
}
5858

59-
return BuiltCommitmentTransaction_set_transaction(this_ptrPointer, valWrapper.cOpaqueStruct!);
59+
return BuiltCommitmentTransaction_set_transaction(this_ptrPointer, valWrapper.dangle().cOpaqueStruct!);
6060
}
6161

6262
public func get_txid() -> [UInt8] {

bindings/LDK/structs/ChannelManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ ChannelManager_send_spontaneous_payment(this_argPointer, routePointer, Bindings.
123123

124124
return Result_NoneAPIErrorZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKChannelManager>) in
125125
withUnsafePointer(to: Bindings.array_to_tuple32(array: temporary_channel_id)) { (temporary_channel_idPointer: UnsafePointer<(UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8)>) in
126-
ChannelManager_funding_transaction_generated(this_argPointer, temporary_channel_idPointer, funding_transactionWrapper.cOpaqueStruct!)
126+
ChannelManager_funding_transaction_generated(this_argPointer, temporary_channel_idPointer, funding_transactionWrapper.dangle().cOpaqueStruct!)
127127
}
128128
});
129129
}

bindings/LDK/structs/InMemorySigner.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ InMemorySigner_get_channel_parameters(this_argPointer)
189189

190190
return Result_CVec_CVec_u8ZZNoneZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKInMemorySigner>) in
191191
withUnsafePointer(to: descriptor.cOpaqueStruct!) { (descriptorPointer: UnsafePointer<LDKStaticPaymentOutputDescriptor>) in
192-
InMemorySigner_sign_counterparty_payment_input(this_argPointer, spend_txWrapper.cOpaqueStruct!, input_idx, descriptorPointer)
192+
InMemorySigner_sign_counterparty_payment_input(this_argPointer, spend_txWrapper.dangle().cOpaqueStruct!, input_idx, descriptorPointer)
193193
}
194194
});
195195
}
@@ -203,7 +203,7 @@ InMemorySigner_sign_counterparty_payment_input(this_argPointer, spend_txWrapper.
203203

204204
return Result_CVec_CVec_u8ZZNoneZ(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKInMemorySigner>) in
205205
withUnsafePointer(to: descriptor.cOpaqueStruct!) { (descriptorPointer: UnsafePointer<LDKDelayedPaymentOutputDescriptor>) in
206-
InMemorySigner_sign_dynamic_p2wsh_input(this_argPointer, spend_txWrapper.cOpaqueStruct!, input_idx, descriptorPointer)
206+
InMemorySigner_sign_dynamic_p2wsh_input(this_argPointer, spend_txWrapper.dangle().cOpaqueStruct!, input_idx, descriptorPointer)
207207
}
208208
});
209209
}

bindings/LDK/traits/BaseSign.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public class NativelyImplementedBaseSign: BaseSign {
306306

307307
return withUnsafePointer(to: Bindings.array_to_tuple32(array: per_commitment_key!)) { (per_commitment_keyPointer: UnsafePointer<(UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8)>) in
308308

309-
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_justice_revoked_output(self.cOpaqueStruct!.this_arg, justice_txWrapper.cOpaqueStruct!, input, amount, per_commitment_keyPointer))
309+
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_justice_revoked_output(self.cOpaqueStruct!.this_arg, justice_txWrapper.dangle().cOpaqueStruct!, input, amount, per_commitment_keyPointer))
310310

311311
}
312312

@@ -323,7 +323,7 @@ public class NativelyImplementedBaseSign: BaseSign {
323323
return withUnsafePointer(to: Bindings.array_to_tuple32(array: per_commitment_key!)) { (per_commitment_keyPointer: UnsafePointer<(UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8,UInt8)>) in
324324
withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLCOutputInCommitment>) in
325325

326-
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_justice_revoked_htlc(self.cOpaqueStruct!.this_arg, justice_txWrapper.cOpaqueStruct!, input, amount, per_commitment_keyPointer, htlcPointer))
326+
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_justice_revoked_htlc(self.cOpaqueStruct!.this_arg, justice_txWrapper.dangle().cOpaqueStruct!, input, amount, per_commitment_keyPointer, htlcPointer))
327327

328328
}
329329
}
@@ -340,7 +340,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
340340

341341
return withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLCOutputInCommitment>) in
342342

343-
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_counterparty_htlc_transaction(self.cOpaqueStruct!.this_arg, htlc_txWrapper.cOpaqueStruct!, input, amount, Bindings.new_LDKPublicKey(array: per_commitment_point), htlcPointer))
343+
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_counterparty_htlc_transaction(self.cOpaqueStruct!.this_arg, htlc_txWrapper.dangle().cOpaqueStruct!, input, amount, Bindings.new_LDKPublicKey(array: per_commitment_point), htlcPointer))
344344

345345
}
346346

@@ -355,7 +355,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
355355
}
356356

357357
return
358-
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_closing_transaction(self.cOpaqueStruct!.this_arg, closing_txWrapper.cOpaqueStruct!))
358+
Result_SignatureNoneZ(pointer: self.cOpaqueStruct!.sign_closing_transaction(self.cOpaqueStruct!.this_arg, closing_txWrapper.dangle().cOpaqueStruct!))
359359

360360

361361
}

bindings/LDK/traits/BroadcasterInterface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class NativelyImplementedBroadcasterInterface: BroadcasterInterface {
9898
}
9999

100100

101-
self.cOpaqueStruct!.broadcast_transaction(self.cOpaqueStruct!.this_arg, txWrapper.cOpaqueStruct!)
101+
self.cOpaqueStruct!.broadcast_transaction(self.cOpaqueStruct!.this_arg, txWrapper.dangle().cOpaqueStruct!)
102102

103103

104104
}

bindings/LDK/tuples/C2Tuple_usizeTransactionZ.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ C2Tuple_usizeTransactionZ_clone(origPointer)
4444
bWrapper.noOpRetain()
4545
}
4646

47-
return C2Tuple_usizeTransactionZ(pointer: C2Tuple_usizeTransactionZ_new(a, bWrapper.cOpaqueStruct!));
47+
return C2Tuple_usizeTransactionZ(pointer: C2Tuple_usizeTransactionZ_new(a, bWrapper.dangle().cOpaqueStruct!));
4848
}
4949

5050
internal func free() -> Void {

src/conversion_helper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
class ConversionHelper:
99
trait_structs = set()
10+
freeable_types = set()
1011

1112
@classmethod
12-
def prepare_swift_to_native_arguments(cls, argument_types, is_trait_callback=False, force_pass_instance=False, is_free_method=False):
13+
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):
1314
swift_arguments = []
1415
native_arguments = []
1516
pointer_wrapping_prefix = ''
@@ -160,7 +161,7 @@ def prepare_swift_to_native_arguments(cls, argument_types, is_trait_callback=Fal
160161
{passed_argument_name}Wrapper.noOpRetain()
161162
}}
162163
'''
163-
if current_argument_details.rust_obj.startswith('LDKCVec_'):
164+
if current_argument_details.rust_obj.startswith('LDKCVec_') or current_argument_details.rust_obj == 'LDKTransaction':
164165
# vectors will be freed by the underlying function automatically
165166
native_arguments.append(f'{passed_argument_name}Wrapper.dangle().cOpaqueStruct!')
166167
else:

src/lightning_header_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ def populate_type_details(self):
425425
associated_type_name = method_details['associated_type_name']['native']
426426
if method_details['is_free']:
427427
self.type_details[associated_type_name].free_method = method_details
428+
src.conversion_helper.ConversionHelper.freeable_types.add(associated_type_name)
428429
elif method_details['is_constructor']:
429430
# TODO: handle case for multiple constructors
430431
self.type_details[associated_type_name].constructor_method = method_details

0 commit comments

Comments
 (0)