Skip to content

Commit 556d959

Browse files
committed
generate options with array support
1 parent c57f422 commit 556d959

31 files changed

+1598
-172
lines changed

bindings/LDK/Bindings.swift

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ public class Bindings {
927927
/* RUST_TO_SWIFT_END */
928928
public class func extractNativeLDKC2Tuple_BlockHashChannelMonitorZArray(array: [C2Tuple_BlockHashChannelMonitorZ]) -> [LDKC2Tuple_BlockHashChannelMonitorZ] {
929929
return array.map { entry -> LDKC2Tuple_BlockHashChannelMonitorZ in
930-
entry.cOpaqueStruct!
930+
entry.danglingClone().cOpaqueStruct!
931931
}
932932
}
933933

@@ -943,6 +943,13 @@ public class Bindings {
943943
}
944944
}
945945

946+
internal class func cloneNativeLDKC2Tuple_BlockHashChannelMonitorZArray(array: [LDKC2Tuple_BlockHashChannelMonitorZ]) -> [LDKC2Tuple_BlockHashChannelMonitorZ] {
947+
return array.map { entry -> LDKC2Tuple_BlockHashChannelMonitorZ in
948+
// create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
949+
C2Tuple_BlockHashChannelMonitorZ(pointer: entry).dangle().clone().dangle().cOpaqueStruct!
950+
}
951+
}
952+
946953

947954
/* SWIFT_TO_RUST_START */
948955
public class func new_LDKCVec_C2Tuple_PublicKeyTypeZZWrapper(array: [LDKC2Tuple_PublicKeyTypeZ]) -> LDKCVec_C2Tuple_PublicKeyTypeZZWrapper {
@@ -2558,6 +2565,108 @@ public class Bindings {
25582565
}
25592566

25602567

2568+
/* SWIFT_TO_RUST_START */
2569+
public class func new_LDKCVec_OutPointZWrapper(array: [LDKOutPoint]) -> LDKCVec_OutPointZWrapper {
2570+
/* DIMENSION_REDUCTION_PREP */
2571+
2572+
/*
2573+
let dataContainer = array.withUnsafeBufferPointer { (pointer: UnsafeBufferPointer<LDKOutPoint>) -> UnsafeMutablePointer<LDKOutPoint> in
2574+
let mutablePointer = UnsafeMutablePointer<LDKOutPoint>(mutating: pointer.baseAddress!)
2575+
return mutablePointer
2576+
}
2577+
*/
2578+
2579+
let dataContainer = UnsafeMutablePointer<LDKOutPoint>.allocate(capacity: array.count)
2580+
dataContainer.initialize(from: array, count: array.count)
2581+
2582+
let vector = LDKCVec_OutPointZ(data: dataContainer, datalen: UInt(array.count))
2583+
let wrapper = LDKCVec_OutPointZWrapper(pointer: vector)
2584+
return wrapper
2585+
}
2586+
2587+
public class LDKCVec_OutPointZWrapper: NativeTypeWrapper {
2588+
private static var instanceCounter: UInt = 0
2589+
internal let instanceNumber: UInt
2590+
2591+
internal var cOpaqueStruct: LDKCVec_OutPointZ?
2592+
internal var subdimensionWrapper: [AnyObject]? = nil
2593+
2594+
public init(pointer: LDKCVec_OutPointZ){
2595+
Self.instanceCounter += 1
2596+
self.instanceNumber = Self.instanceCounter
2597+
self.cOpaqueStruct = pointer
2598+
super.init(conflictAvoidingVariableName: 0)
2599+
}
2600+
2601+
internal init(pointer: LDKCVec_OutPointZ, subdimensionWrapper: [AnyObject]){
2602+
Self.instanceCounter += 1
2603+
self.instanceNumber = Self.instanceCounter
2604+
self.subdimensionWrapper = subdimensionWrapper
2605+
self.cOpaqueStruct = pointer
2606+
super.init(conflictAvoidingVariableName: 0)
2607+
}
2608+
2609+
public func noOpRetain(){}
2610+
2611+
internal func dangle(dangleSubdimensions: Bool = true) -> LDKCVec_OutPointZWrapper {
2612+
self.dangling = true
2613+
/* SUBDIMENSION_DANGLE_PREP */
2614+
return self
2615+
}
2616+
2617+
deinit {
2618+
if !self.dangling {
2619+
print("Freeing LDKCVec_OutPointZWrapper \(self.instanceNumber).")
2620+
self.cOpaqueStruct!.data.deallocate()
2621+
} else {
2622+
print("Not freeing LDKCVec_OutPointZWrapper \(self.instanceNumber) due to dangle.")
2623+
}
2624+
}
2625+
}
2626+
/* SWIFT_TO_RUST_END */
2627+
2628+
/* RUST_TO_SWIFT_START */
2629+
public class func LDKCVec_OutPointZ_to_array(nativeType: LDKCVec_OutPointZ, deallocate: Bool = true) -> [LDKOutPoint] {
2630+
var array = [LDKOutPoint]()
2631+
for index in 0..<Int(nativeType.datalen) {
2632+
let currentEntry = nativeType.data[index]
2633+
/* CONVERSION_PREP */
2634+
array.append(currentEntry)
2635+
}
2636+
2637+
if deallocate && nativeType.datalen > 0 {
2638+
nativeType.data.deallocate()
2639+
}
2640+
2641+
return array
2642+
}
2643+
/* RUST_TO_SWIFT_END */
2644+
public class func extractNativeLDKOutPointArray(array: [OutPoint]) -> [LDKOutPoint] {
2645+
return array.map { entry -> LDKOutPoint in
2646+
entry.danglingClone().cOpaqueStruct!
2647+
}
2648+
}
2649+
2650+
public class func wrapNativeLDKOutPointArray(array: [LDKOutPoint]) -> [OutPoint] {
2651+
return array.map { entry -> OutPoint in
2652+
OutPoint(pointer: entry)
2653+
}
2654+
}
2655+
2656+
public class func wrapDanglingNativeLDKOutPointArray(array: [LDKOutPoint]) -> [OutPoint] {
2657+
return array.map { entry -> OutPoint in
2658+
OutPoint(pointer: entry).dangle()
2659+
}
2660+
}
2661+
2662+
internal class func cloneNativeLDKOutPointArray(array: [LDKOutPoint]) -> [LDKOutPoint] {
2663+
return array.map { entry -> LDKOutPoint in
2664+
// create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
2665+
OutPoint(pointer: entry).dangle().clone().dangle().cOpaqueStruct!
2666+
}
2667+
}
2668+
2669+
25612670
/* SWIFT_TO_RUST_START */
25622671
public class func new_LDKCVec_PrivateRouteZWrapper(array: [LDKPrivateRoute]) -> LDKCVec_PrivateRouteZWrapper {
25632672
/* DIMENSION_REDUCTION_PREP */
@@ -4362,7 +4471,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
43624471

43634472

43644473
}
4365-
public class func swift_get_keysend_route(our_node_id: [UInt8], network: NetworkGraph, payee: [UInt8], first_hops: [ChannelDetails]?, last_hops: [RouteHint], final_value_msat: UInt64, final_cltv: UInt32, logger: Logger) -> Result_RouteLightningErrorZ {
4474+
public class func swift_get_keysend_route(our_node_pubkey: [UInt8], network: NetworkGraph, payee: [UInt8], first_hops: [ChannelDetails]?, last_hops: [RouteHint], final_value_msat: UInt64, final_cltv: UInt32, logger: Logger, scorer: Score) -> Result_RouteLightningErrorZ {
43664475

43674476

43684477
var first_hopsPointer: UnsafeMutablePointer<LDKCVec_ChannelDetailsZ>? = nil
@@ -4388,9 +4497,11 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
43884497
}
43894498

43904499
return withUnsafePointer(to: network.cOpaqueStruct!) { (networkPointer: UnsafePointer<LDKNetworkGraph>) in
4500+
withUnsafePointer(to: scorer.cOpaqueStruct!) { (scorerPointer: UnsafePointer<LDKScore>) in
43914501

4392-
Result_RouteLightningErrorZ(pointer: get_keysend_route(Bindings.new_LDKPublicKey(array: our_node_id), networkPointer, Bindings.new_LDKPublicKey(array: payee), first_hopsPointer, last_hopsWrapper.dangle().cOpaqueStruct!, final_value_msat, final_cltv, logger.cOpaqueStruct!))
4502+
Result_RouteLightningErrorZ(pointer: get_keysend_route(Bindings.new_LDKPublicKey(array: our_node_pubkey), networkPointer, Bindings.new_LDKPublicKey(array: payee), first_hopsPointer, last_hopsWrapper.dangle().cOpaqueStruct!, final_value_msat, final_cltv, logger.cOpaqueStruct!, scorerPointer))
43934503

4504+
}
43944505
}
43954506

43964507
}
@@ -4583,7 +4694,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
45834694
}
45844695

45854696
public class func get_ldk_swift_bindings_version() -> String {
4586-
return "034c20c8e2a658f53ade8a8350a1aa5f36118992"
4697+
return "c57f422ea3fecd28800deabc7d81ffed507baa36"
45874698
}
45884699

45894700
}

bindings/LDK/options/Event.swift

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Event: NativeTypeWrapper {
2626
/* OPTION_METHODS_START */
2727

2828
public enum EventValueType {
29-
case FundingGenerationReady, PaymentReceived, PaymentSent, PaymentPathFailed, PendingHTLCsForwardable, SpendableOutputs, PaymentForwarded, ChannelClosed
29+
case FundingGenerationReady, PaymentReceived, PaymentSent, PaymentPathFailed, PendingHTLCsForwardable, SpendableOutputs, PaymentForwarded, ChannelClosed, DiscardFunding
3030
}
3131

3232
public func getValueType() -> EventValueType? {
@@ -48,6 +48,8 @@ public class Event: NativeTypeWrapper {
4848
return .PaymentForwarded
4949
case LDKEvent_ChannelClosed:
5050
return .ChannelClosed
51+
case LDKEvent_DiscardFunding:
52+
return .DiscardFunding
5153
default:
5254
return nil
5355
}
@@ -110,6 +112,13 @@ public class Event: NativeTypeWrapper {
110112
return ChannelClosed(pointer: self.cOpaqueStruct!.channel_closed, anchor: self)
111113
}
112114

115+
public func getValueAsDiscardFunding() -> DiscardFunding? {
116+
if self.cOpaqueStruct?.tag != LDKEvent_DiscardFunding {
117+
return nil
118+
}
119+
return DiscardFunding(pointer: self.cOpaqueStruct!.discard_funding, anchor: self)
120+
}
121+
113122

114123
internal func free() -> Void {
115124

@@ -160,12 +169,12 @@ Event_clone(origPointer)
160169
return Event(pointer: Event_payment_received(Bindings.new_LDKThirtyTwoBytes(array: payment_hash), amt, purpose.danglingClone().cOpaqueStruct!));
161170
}
162171

163-
public class func payment_sent(payment_preimage: [UInt8]) -> Event {
172+
public class func payment_sent(payment_preimage: [UInt8], payment_hash: [UInt8]) -> Event {
164173

165-
return Event(pointer: Event_payment_sent(Bindings.new_LDKThirtyTwoBytes(array: payment_preimage)));
174+
return Event(pointer: Event_payment_sent(Bindings.new_LDKThirtyTwoBytes(array: payment_preimage), Bindings.new_LDKThirtyTwoBytes(array: payment_hash)));
166175
}
167176

168-
public class func payment_path_failed(payment_hash: [UInt8], rejected_by_dest: Bool, network_update: Option_NetworkUpdateZ, all_paths_failed: Bool, path: [RouteHop]) -> Event {
177+
public class func payment_path_failed(payment_hash: [UInt8], rejected_by_dest: Bool, network_update: Option_NetworkUpdateZ, all_paths_failed: Bool, path: [RouteHop], short_channel_id: Option_u64Z) -> Event {
169178

170179
let pathUnwrapped = path.map { (pathCurrentValue) in
171180
pathCurrentValue
@@ -177,7 +186,7 @@ Event_clone(origPointer)
177186
pathWrapper.noOpRetain()
178187
}
179188

180-
return Event(pointer: Event_payment_path_failed(Bindings.new_LDKThirtyTwoBytes(array: payment_hash), rejected_by_dest, network_update.danglingClone().cOpaqueStruct!, all_paths_failed, pathWrapper.dangle().cOpaqueStruct!));
189+
return Event(pointer: Event_payment_path_failed(Bindings.new_LDKThirtyTwoBytes(array: payment_hash), rejected_by_dest, network_update.danglingClone().cOpaqueStruct!, all_paths_failed, pathWrapper.dangle().cOpaqueStruct!, short_channel_id.danglingClone().cOpaqueStruct!));
181190
}
182191

183192
public class func pending_htlcs_forwardable(time_forwardable: UInt64) -> Event {
@@ -205,9 +214,19 @@ Event_clone(origPointer)
205214
return Event(pointer: Event_payment_forwarded(fee_earned_msat.danglingClone().cOpaqueStruct!, claim_from_onchain_tx));
206215
}
207216

208-
public class func channel_closed(channel_id: [UInt8], reason: ClosureReason) -> Event {
217+
public class func channel_closed(channel_id: [UInt8], user_channel_id: UInt64, reason: ClosureReason) -> Event {
209218

210-
return Event(pointer: Event_channel_closed(Bindings.new_LDKThirtyTwoBytes(array: channel_id), reason.danglingClone().cOpaqueStruct!));
219+
return Event(pointer: Event_channel_closed(Bindings.new_LDKThirtyTwoBytes(array: channel_id), user_channel_id, reason.danglingClone().cOpaqueStruct!));
220+
}
221+
222+
public class func discard_funding(channel_id: [UInt8], transaction: [UInt8]) -> Event {
223+
224+
let transactionWrapper = Bindings.new_LDKTransactionWrapper(array: transaction)
225+
defer {
226+
transactionWrapper.noOpRetain()
227+
}
228+
229+
return Event(pointer: Event_discard_funding(Bindings.new_LDKThirtyTwoBytes(array: channel_id), transactionWrapper.dangle().cOpaqueStruct!));
211230
}
212231

213232
public func write() -> [UInt8] {
@@ -312,6 +331,10 @@ Event_write(objPointer)
312331
return Bindings.LDKThirtyTwoBytes_to_array(nativeType: self.cOpaqueStruct!.payment_preimage)
313332
}
314333

334+
public func getPayment_hash() -> [UInt8] {
335+
return Bindings.LDKThirtyTwoBytes_to_array(nativeType: self.cOpaqueStruct!.payment_hash)
336+
}
337+
315338

316339
}
317340

@@ -358,6 +381,10 @@ Event_write(objPointer)
358381

359382
}
360383

384+
public func getShort_channel_id() -> Option_u64Z {
385+
return Option_u64Z(pointer: self.cOpaqueStruct!.short_channel_id, anchor: self)
386+
}
387+
361388

362389
}
363390

@@ -467,11 +494,44 @@ Event_write(objPointer)
467494
return Bindings.LDKThirtyTwoBytes_to_array(nativeType: self.cOpaqueStruct!.channel_id)
468495
}
469496

497+
public func getUser_channel_id() -> UInt64 {
498+
return self.cOpaqueStruct!.user_channel_id
499+
}
500+
470501
public func getReason() -> ClosureReason {
471502
return ClosureReason(pointer: self.cOpaqueStruct!.reason, anchor: self)
472503
}
473504

474505

475506
}
476507

508+
509+
public class DiscardFunding: NativeTypeWrapper {
510+
511+
512+
var cOpaqueStruct: LDKEvent_LDKDiscardFunding_Body?;
513+
fileprivate init(pointer: LDKEvent_LDKDiscardFunding_Body) {
514+
self.cOpaqueStruct = pointer
515+
super.init(conflictAvoidingVariableName: 0)
516+
}
517+
fileprivate init(pointer: LDKEvent_LDKDiscardFunding_Body, anchor: NativeTypeWrapper) {
518+
self.cOpaqueStruct = pointer
519+
super.init(conflictAvoidingVariableName: 0)
520+
self.dangling = true
521+
try! self.addAnchor(anchor: anchor)
522+
}
523+
524+
525+
526+
public func getChannel_id() -> [UInt8] {
527+
return Bindings.LDKThirtyTwoBytes_to_array(nativeType: self.cOpaqueStruct!.channel_id)
528+
}
529+
530+
public func getTransaction() -> [UInt8] {
531+
return Bindings.LDKTransaction_to_array(nativeType: self.cOpaqueStruct!.transaction, deallocate: false)
532+
}
533+
534+
535+
}
536+
477537
}

0 commit comments

Comments
 (0)