1
+
2
+ #if SWIFT_PACKAGE
3
+ import LDKHeaders
4
+ #endif
5
+
6
+ import Foundation
7
+
8
+ ///
9
+ public typealias Hints = Bindings . Hints
10
+
11
+ extension Bindings {
12
+
13
+ /// Routing hints for the tail of the route.
14
+ public class Hints : NativeTypeWrapper {
15
+
16
+
17
+ /// Set to false to suppress an individual type's deinit log statements.
18
+ /// Only applicable when log threshold is set to `.Debug`.
19
+ public static var enableDeinitLogging = true
20
+
21
+ /// Set to true to suspend the freeing of this type's associated Rust memory.
22
+ /// Should only ever be used for debugging purposes, and will likely be
23
+ /// deprecated soon.
24
+ public static var suspendFreedom = false
25
+
26
+ private static var instanceCounter : UInt = 0
27
+ internal let instanceNumber : UInt
28
+
29
+ internal var cType : LDKHints ?
30
+
31
+ internal init ( cType: LDKHints , instantiationContext: String ) {
32
+ Self . instanceCounter += 1
33
+ self . instanceNumber = Self . instanceCounter
34
+ self . cType = cType
35
+
36
+ super. init ( conflictAvoidingVariableName: 0 , instantiationContext: instantiationContext)
37
+ }
38
+
39
+ internal init ( cType: LDKHints , instantiationContext: String , anchor: NativeTypeWrapper ) {
40
+ Self . instanceCounter += 1
41
+ self . instanceNumber = Self . instanceCounter
42
+ self . cType = cType
43
+
44
+ super. init ( conflictAvoidingVariableName: 0 , instantiationContext: instantiationContext)
45
+ self . dangling = true
46
+ try ! self . addAnchor ( anchor: anchor)
47
+ }
48
+
49
+ internal init ( cType: LDKHints , instantiationContext: String , anchor: NativeTypeWrapper , dangle: Bool = false ) {
50
+ Self . instanceCounter += 1
51
+ self . instanceNumber = Self . instanceCounter
52
+ self . cType = cType
53
+
54
+ super. init ( conflictAvoidingVariableName: 0 , instantiationContext: instantiationContext)
55
+ self . dangling = dangle
56
+ try ! self . addAnchor ( anchor: anchor)
57
+ }
58
+
59
+
60
+ public enum HintsType {
61
+
62
+ /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
63
+ /// will be included in the final [`Route`].
64
+ case Blinded
65
+
66
+ /// The recipient included these route hints in their BOLT11 invoice.
67
+ case Clear
68
+
69
+ }
70
+
71
+ public func getValueType( ) -> HintsType {
72
+ switch self . cType!. tag {
73
+ case LDKHints_Blinded:
74
+ return . Blinded
75
+
76
+ case LDKHints_Clear:
77
+ return . Clear
78
+
79
+ default :
80
+ Bindings . print ( " Error: Invalid value type for Hints! Aborting. " , severity: . ERROR)
81
+ abort ( )
82
+ }
83
+
84
+ }
85
+
86
+
87
+ /// Frees any resources used by the Hints
88
+ internal func free( ) {
89
+ // native call variable prep
90
+
91
+
92
+ // native method call
93
+ let nativeCallResult = Hints_free ( self . cType!)
94
+
95
+ // cleanup
96
+
97
+
98
+
99
+ // return value (do some wrapping)
100
+ let returnValue = nativeCallResult
101
+
102
+
103
+ return returnValue
104
+ }
105
+
106
+ /// Creates a copy of the Hints
107
+ internal func clone( ) -> Hints {
108
+ // native call variable prep
109
+
110
+
111
+ // native method call
112
+ let nativeCallResult =
113
+ withUnsafePointer ( to: self . cType!) { ( origPointer: UnsafePointer < LDKHints > ) in
114
+ Hints_clone ( origPointer)
115
+ }
116
+
117
+
118
+ // cleanup
119
+
120
+
121
+
122
+ // return value (do some wrapping)
123
+ let returnValue = Hints ( cType: nativeCallResult, instantiationContext: " Hints.swift:: \( #function) : \( #line) " )
124
+
125
+
126
+ return returnValue
127
+ }
128
+
129
+ /// Utility method to constructs a new Blinded-variant Hints
130
+ public class func initWithBlinded( a: [ ( BlindedPayInfo , BlindedPath ) ] ) -> Hints {
131
+ // native call variable prep
132
+
133
+ let aVector = Vec_C2Tuple_BlindedPayInfoBlindedPathZZ ( array: a, instantiationContext: " Hints.swift:: \( #function) : \( #line) " ) . dangle ( )
134
+
135
+
136
+ // native method call
137
+ let nativeCallResult = Hints_blinded ( aVector. cType!)
138
+
139
+ // cleanup
140
+
141
+ // aVector.noOpRetain()
142
+
143
+
144
+
145
+ // return value (do some wrapping)
146
+ let returnValue = Hints ( cType: nativeCallResult, instantiationContext: " Hints.swift:: \( #function) : \( #line) " )
147
+
148
+
149
+ return returnValue
150
+ }
151
+
152
+ /// Utility method to constructs a new Clear-variant Hints
153
+ public class func initWithClear( a: [ RouteHint ] ) -> Hints {
154
+ // native call variable prep
155
+
156
+ let aVector = Vec_RouteHintZ ( array: a, instantiationContext: " Hints.swift:: \( #function) : \( #line) " ) . dangle ( )
157
+
158
+
159
+ // native method call
160
+ let nativeCallResult = Hints_clear ( aVector. cType!)
161
+
162
+ // cleanup
163
+
164
+ // aVector.noOpRetain()
165
+
166
+
167
+
168
+ // return value (do some wrapping)
169
+ let returnValue = Hints ( cType: nativeCallResult, instantiationContext: " Hints.swift:: \( #function) : \( #line) " )
170
+
171
+
172
+ return returnValue
173
+ }
174
+
175
+ /// Generates a non-cryptographic 64-bit hash of the Hints.
176
+ public func hash( ) -> UInt64 {
177
+ // native call variable prep
178
+
179
+
180
+ // native method call
181
+ let nativeCallResult =
182
+ withUnsafePointer ( to: self . cType!) { ( oPointer: UnsafePointer < LDKHints > ) in
183
+ Hints_hash ( oPointer)
184
+ }
185
+
186
+
187
+ // cleanup
188
+
189
+
190
+
191
+ // return value (do some wrapping)
192
+ let returnValue = nativeCallResult
193
+
194
+
195
+ return returnValue
196
+ }
197
+
198
+ /// Checks if two Hintss contain equal inner contents.
199
+ /// This ignores pointers and is_owned flags and looks at the values in fields.
200
+ public class func eq( a: Hints , b: Hints ) -> Bool {
201
+ // native call variable prep
202
+
203
+
204
+ // native method call
205
+ let nativeCallResult =
206
+ withUnsafePointer ( to: a. cType!) { ( aPointer: UnsafePointer < LDKHints > ) in
207
+
208
+ withUnsafePointer ( to: b. cType!) { ( bPointer: UnsafePointer < LDKHints > ) in
209
+ Hints_eq ( aPointer, bPointer)
210
+ }
211
+
212
+ }
213
+
214
+
215
+ // cleanup
216
+
217
+
218
+
219
+ // return value (do some wrapping)
220
+ let returnValue = nativeCallResult
221
+
222
+
223
+ return returnValue
224
+ }
225
+
226
+
227
+
228
+ public func getValueAsBlinded( ) -> [ ( BlindedPayInfo , BlindedPath ) ] ? {
229
+ if self . cType? . tag != LDKHints_Blinded {
230
+ return nil
231
+ }
232
+
233
+ return Vec_C2Tuple_BlindedPayInfoBlindedPathZZ ( cType: self . cType!. blinded, instantiationContext: " Hints.swift:: \( #function) : \( #line) " , anchor: self ) . getValue ( )
234
+ }
235
+
236
+ public func getValueAsClear( ) -> [ RouteHint ] ? {
237
+ if self . cType? . tag != LDKHints_Clear {
238
+ return nil
239
+ }
240
+
241
+ return Vec_RouteHintZ ( cType: self . cType!. clear, instantiationContext: " Hints.swift:: \( #function) : \( #line) " , anchor: self ) . getValue ( )
242
+ }
243
+
244
+
245
+ internal func dangle( _ shouldDangle: Bool = true ) -> Hints {
246
+ self . dangling = shouldDangle
247
+ return self
248
+ }
249
+
250
+
251
+ internal func danglingClone( ) -> Hints {
252
+ let dangledClone = self . clone ( )
253
+ dangledClone. dangling = true
254
+ return dangledClone
255
+ }
256
+
257
+ deinit {
258
+ if Bindings . suspendFreedom || Self . suspendFreedom {
259
+ return
260
+ }
261
+
262
+ if !self . dangling {
263
+ if Self . enableDeinitLogging {
264
+ Bindings . print ( " Freeing Hints \( self . instanceNumber) . (Origin: \( self . instantiationContext) ) " )
265
+ }
266
+
267
+ self . free ( )
268
+ } else if Self . enableDeinitLogging {
269
+ Bindings . print ( " Not freeing Hints \( self . instanceNumber) due to dangle. (Origin: \( self . instantiationContext) ) " )
270
+ }
271
+ }
272
+
273
+
274
+
275
+
276
+ }
277
+
278
+ }
279
+
0 commit comments