6
6
//
7
7
8
8
import Foundation
9
- #if canImport(os)
10
- import os
11
- #endif
9
+ // #if canImport(os)
10
+ // import os
11
+ // #endif
12
12
13
13
public typealias LDKTransactionOutputs = LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ
14
14
public typealias TransactionOutputs = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ
@@ -67,9 +67,9 @@ open class NativeTypeWrapper: Hashable {
67
67
public class Bindings {
68
68
69
69
internal static var minimumPrintSeverity : PrintSeverity = . WARNING
70
- #if canImport(os)
71
- internal static let logger = os. Logger ( subsystem: Bundle . main. bundleIdentifier!, category: " ldk " )
72
- #endif
70
+ // #if canImport(os)
71
+ // internal static let logger = os.Logger(subsystem: Bundle.main.bundleIdentifier!, category: "ldk")
72
+ // #endif
73
73
74
74
public enum PrintSeverity : UInt {
75
75
case DEBUG = 0
@@ -79,19 +79,25 @@ public class Bindings {
79
79
80
80
internal class func print( _ string: String , severity: PrintSeverity = . DEBUG) {
81
81
if severity. rawValue >= Self . minimumPrintSeverity. rawValue {
82
- #if canImport(os)
83
- if severity == Self . PrintSeverity. DEBUG {
84
- logger. debug ( " \( string) " )
85
- } else if severity == Self . PrintSeverity. WARNING {
86
- logger. warning ( " \( string) " )
87
- } else if severity == Self . PrintSeverity. ERROR {
88
- logger. error ( " \( string) " )
89
- } else {
90
- logger. log ( " \( string) " )
91
- }
92
- #else
93
- Swift . print ( string)
94
- #endif
82
+ Swift . print ( string)
83
+ // if #available(iOS 14.0, *) {
84
+ // #if canImport(os)
85
+ // if severity == Self.PrintSeverity.DEBUG {
86
+ // logger.debug("\(string)")
87
+ // }else if severity == Self.PrintSeverity.WARNING {
88
+ // logger.warning("\(string)")
89
+ // }else if severity == Self.PrintSeverity.ERROR {
90
+ // logger.error("\(string)")
91
+ // }else {
92
+ // logger.log("\(string)")
93
+ // }
94
+ // #else
95
+ // Swift.print(string)
96
+ // #endif
97
+ // } else {
98
+ // // Fallback on earlier versions
99
+ // Swift.print(string)
100
+ // }
95
101
}
96
102
}
97
103
@@ -927,7 +933,7 @@ public class Bindings {
927
933
/* RUST_TO_SWIFT_END */
928
934
public class func extractNativeLDKC2Tuple_BlockHashChannelMonitorZArray( array: [ C2Tuple_BlockHashChannelMonitorZ ] ) -> [ LDKC2Tuple_BlockHashChannelMonitorZ ] {
929
935
return array. map { entry -> LDKC2Tuple_BlockHashChannelMonitorZ in
930
- entry. cOpaqueStruct!
936
+ entry. danglingClone ( ) . cOpaqueStruct!
931
937
}
932
938
}
933
939
@@ -943,6 +949,13 @@ public class Bindings {
943
949
}
944
950
}
945
951
952
+ internal class func cloneNativeLDKC2Tuple_BlockHashChannelMonitorZArray( array: [ LDKC2Tuple_BlockHashChannelMonitorZ ] ) -> [ LDKC2Tuple_BlockHashChannelMonitorZ ] {
953
+ return array. map { entry -> LDKC2Tuple_BlockHashChannelMonitorZ in
954
+ // create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
955
+ C2Tuple_BlockHashChannelMonitorZ ( pointer: entry) . dangle ( ) . clone ( ) . dangle ( ) . cOpaqueStruct!
956
+ }
957
+ }
958
+
946
959
947
960
/* SWIFT_TO_RUST_START */
948
961
public class func new_LDKCVec_C2Tuple_PublicKeyTypeZZWrapper( array: [ LDKC2Tuple_PublicKeyTypeZ ] ) -> LDKCVec_C2Tuple_PublicKeyTypeZZWrapper {
@@ -2558,6 +2571,108 @@ public class Bindings {
2558
2571
}
2559
2572
2560
2573
2574
+ /* SWIFT_TO_RUST_START */
2575
+ public class func new_LDKCVec_OutPointZWrapper( array: [ LDKOutPoint ] ) -> LDKCVec_OutPointZWrapper {
2576
+ /* DIMENSION_REDUCTION_PREP */
2577
+
2578
+ /*
2579
+ let dataContainer = array.withUnsafeBufferPointer { (pointer: UnsafeBufferPointer<LDKOutPoint>) -> UnsafeMutablePointer<LDKOutPoint> in
2580
+ let mutablePointer = UnsafeMutablePointer<LDKOutPoint>(mutating: pointer.baseAddress!)
2581
+ return mutablePointer
2582
+ }
2583
+ */
2584
+
2585
+ let dataContainer = UnsafeMutablePointer< LDKOutPoint> . allocate( capacity: array. count)
2586
+ dataContainer. initialize ( from: array, count: array. count)
2587
+
2588
+ let vector = LDKCVec_OutPointZ ( data: dataContainer, datalen: UInt ( array. count) )
2589
+ let wrapper = LDKCVec_OutPointZWrapper ( pointer: vector)
2590
+ return wrapper
2591
+ }
2592
+
2593
+ public class LDKCVec_OutPointZWrapper : NativeTypeWrapper {
2594
+ private static var instanceCounter : UInt = 0
2595
+ internal let instanceNumber : UInt
2596
+
2597
+ internal var cOpaqueStruct : LDKCVec_OutPointZ ?
2598
+ internal var subdimensionWrapper : [ AnyObject ] ? = nil
2599
+
2600
+ public init ( pointer: LDKCVec_OutPointZ ) {
2601
+ Self . instanceCounter += 1
2602
+ self . instanceNumber = Self . instanceCounter
2603
+ self . cOpaqueStruct = pointer
2604
+ super. init ( conflictAvoidingVariableName: 0 )
2605
+ }
2606
+
2607
+ internal init ( pointer: LDKCVec_OutPointZ , subdimensionWrapper: [ AnyObject ] ) {
2608
+ Self . instanceCounter += 1
2609
+ self . instanceNumber = Self . instanceCounter
2610
+ self . subdimensionWrapper = subdimensionWrapper
2611
+ self . cOpaqueStruct = pointer
2612
+ super. init ( conflictAvoidingVariableName: 0 )
2613
+ }
2614
+
2615
+ public func noOpRetain( ) { }
2616
+
2617
+ internal func dangle( dangleSubdimensions: Bool = true ) -> LDKCVec_OutPointZWrapper {
2618
+ self . dangling = true
2619
+ /* SUBDIMENSION_DANGLE_PREP */
2620
+ return self
2621
+ }
2622
+
2623
+ deinit {
2624
+ if !self . dangling {
2625
+ print ( " Freeing LDKCVec_OutPointZWrapper \( self . instanceNumber) . " )
2626
+ self . cOpaqueStruct!. data. deallocate ( )
2627
+ } else {
2628
+ print ( " Not freeing LDKCVec_OutPointZWrapper \( self . instanceNumber) due to dangle. " )
2629
+ }
2630
+ }
2631
+ }
2632
+ /* SWIFT_TO_RUST_END */
2633
+
2634
+ /* RUST_TO_SWIFT_START */
2635
+ public class func LDKCVec_OutPointZ_to_array( nativeType: LDKCVec_OutPointZ , deallocate: Bool = true ) -> [ LDKOutPoint ] {
2636
+ var array = [ LDKOutPoint] ( )
2637
+ for index in 0 ..< Int ( nativeType. datalen) {
2638
+ let currentEntry = nativeType. data [ index]
2639
+ /* CONVERSION_PREP */
2640
+ array. append ( currentEntry)
2641
+ }
2642
+
2643
+ if deallocate && nativeType. datalen > 0 {
2644
+ nativeType. data. deallocate ( )
2645
+ }
2646
+
2647
+ return array
2648
+ }
2649
+ /* RUST_TO_SWIFT_END */
2650
+ public class func extractNativeLDKOutPointArray( array: [ OutPoint ] ) -> [ LDKOutPoint ] {
2651
+ return array. map { entry -> LDKOutPoint in
2652
+ entry. danglingClone ( ) . cOpaqueStruct!
2653
+ }
2654
+ }
2655
+
2656
+ public class func wrapNativeLDKOutPointArray( array: [ LDKOutPoint ] ) -> [ OutPoint ] {
2657
+ return array. map { entry -> OutPoint in
2658
+ OutPoint ( pointer: entry)
2659
+ }
2660
+ }
2661
+
2662
+ public class func wrapDanglingNativeLDKOutPointArray( array: [ LDKOutPoint ] ) -> [ OutPoint ] {
2663
+ return array. map { entry -> OutPoint in
2664
+ OutPoint ( pointer: entry) . dangle ( )
2665
+ }
2666
+ }
2667
+
2668
+ internal class func cloneNativeLDKOutPointArray( array: [ LDKOutPoint ] ) -> [ LDKOutPoint ] {
2669
+ return array. map { entry -> LDKOutPoint in
2670
+ // create a wrapper around the native object, dangle it to make it non-destructive, clone it, and then dangle the clone
2671
+ OutPoint ( pointer: entry) . dangle ( ) . clone ( ) . dangle ( ) . cOpaqueStruct!
2672
+ }
2673
+ }
2674
+
2675
+
2561
2676
/* SWIFT_TO_RUST_START */
2562
2677
public class func new_LDKCVec_PrivateRouteZWrapper( array: [ LDKPrivateRoute ] ) -> LDKCVec_PrivateRouteZWrapper {
2563
2678
/* DIMENSION_REDUCTION_PREP */
@@ -4362,7 +4477,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
4362
4477
4363
4478
4364
4479
}
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 {
4480
+ 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 {
4366
4481
4367
4482
4368
4483
var first_hopsPointer : UnsafeMutablePointer < LDKCVec_ChannelDetailsZ > ? = nil
@@ -4388,9 +4503,45 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
4388
4503
}
4389
4504
4390
4505
return withUnsafePointer ( to: network. cOpaqueStruct!) { ( networkPointer: UnsafePointer < LDKNetworkGraph > ) in
4506
+ withUnsafePointer ( to: scorer. cOpaqueStruct!) { ( scorerPointer: UnsafePointer < LDKScore > ) in
4391
4507
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!) )
4508
+ 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 ) )
4393
4509
4510
+ }
4511
+ }
4512
+
4513
+ }
4514
+ public class func swift_get_route( our_node_pubkey: [ UInt8 ] , network: NetworkGraph , payee: [ UInt8 ] , payee_features: InvoiceFeatures , first_hops: [ ChannelDetails ] ? , last_hops: [ RouteHint ] , final_value_msat: UInt64 , final_cltv: UInt32 , logger: Logger , scorer: Score ) -> Result_RouteLightningErrorZ {
4515
+
4516
+
4517
+ var first_hopsPointer : UnsafeMutablePointer < LDKCVec_ChannelDetailsZ > ? = nil
4518
+ if let first_hopsUnwrapped = first_hops {
4519
+
4520
+ let first_hopsUnwrapped = first_hopsUnwrapped. map { ( first_hopsCurrentValue) in
4521
+ first_hopsCurrentValue
4522
+ . danglingClone ( ) . cOpaqueStruct!
4523
+ }
4524
+
4525
+ first_hopsPointer = UnsafeMutablePointer< LDKCVec_ChannelDetailsZ> . allocate( capacity: 1 )
4526
+ first_hopsPointer!. initialize ( to: Bindings . new_LDKCVec_ChannelDetailsZWrapper ( array: first_hopsUnwrapped) . cOpaqueStruct!)
4527
+ }
4528
+
4529
+ let last_hopsUnwrapped = last_hops. map { ( last_hopsCurrentValue) in
4530
+ last_hopsCurrentValue
4531
+ . danglingClone ( ) . cOpaqueStruct!
4532
+ }
4533
+
4534
+ let last_hopsWrapper = Bindings . new_LDKCVec_RouteHintZWrapper ( array: last_hopsUnwrapped)
4535
+ defer {
4536
+ last_hopsWrapper. noOpRetain ( )
4537
+ }
4538
+
4539
+ return withUnsafePointer ( to: network. cOpaqueStruct!) { ( networkPointer: UnsafePointer < LDKNetworkGraph > ) in
4540
+ withUnsafePointer ( to: scorer. cOpaqueStruct!) { ( scorerPointer: UnsafePointer < LDKScore > ) in
4541
+
4542
+ Result_RouteLightningErrorZ ( pointer: get_route ( Bindings . new_LDKPublicKey ( array: our_node_pubkey) , networkPointer, Bindings . new_LDKPublicKey ( array: payee) , payee_features. danglingClone ( ) . cOpaqueStruct!, first_hopsPointer, last_hopsWrapper. dangle ( ) . cOpaqueStruct!, final_value_msat, final_cltv, logger. cOpaqueStruct!, scorerPointer) )
4543
+
4544
+ }
4394
4545
}
4395
4546
4396
4547
}
@@ -4573,6 +4724,7 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
4573
4724
}
4574
4725
}
4575
4726
4727
+ /*
4576
4728
public class func getRoute(our_node_id: [UInt8], network: NetworkGraph, payee: [UInt8], payee_features: InvoiceFeatures, first_hops: [LDKChannelDetails], last_hops: [LDKRouteHint], final_value_msat: UInt64, final_cltv: UInt32, logger: Logger) -> Result_RouteLightningErrorZ {
4577
4729
return withUnsafePointer(to: network.cOpaqueStruct!) { (networkPointer: UnsafePointer<LDKNetworkGraph>) in
4578
4730
var mutableHops = Bindings.new_LDKCVec_ChannelDetailsZWrapper(array: first_hops).cOpaqueStruct!
@@ -4581,9 +4733,10 @@ withUnsafePointer(to: htlc.cOpaqueStruct!) { (htlcPointer: UnsafePointer<LDKHTLC
4581
4733
}
4582
4734
}
4583
4735
}
4736
+ */
4584
4737
4585
4738
public class func get_ldk_swift_bindings_version( ) -> String {
4586
- return " 034c20c8e2a658f53ade8a8350a1aa5f36118992 "
4739
+ return " 49993985ba4f2dd197deef5f62758b2f8bfa11cc "
4587
4740
}
4588
4741
4589
4742
}
0 commit comments