|
| 1 | +#if SWIFT_PACKAGE |
| 2 | +import LDKHeaders |
| 3 | +#endif |
| 4 | + |
| 5 | +public class APIError: NativeTypeWrapper { |
| 6 | + |
| 7 | + private static var instanceCounter: UInt = 0 |
| 8 | + internal let instanceNumber: UInt |
| 9 | + |
| 10 | + internal var cOpaqueStruct: LDKAPIError? |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + public init(pointer: LDKAPIError){ |
| 15 | + Self.instanceCounter += 1 |
| 16 | + self.instanceNumber = Self.instanceCounter |
| 17 | + self.cOpaqueStruct = pointer |
| 18 | + super.init(conflictAvoidingVariableName: 0) |
| 19 | + } |
| 20 | + |
| 21 | + public init(pointer: LDKAPIError, anchor: NativeTypeWrapper){ |
| 22 | + Self.instanceCounter += 1 |
| 23 | + self.instanceNumber = Self.instanceCounter |
| 24 | + self.cOpaqueStruct = pointer |
| 25 | + super.init(conflictAvoidingVariableName: 0) |
| 26 | + self.dangling = true |
| 27 | + try! self.addAnchor(anchor: anchor) |
| 28 | + } |
| 29 | + |
| 30 | + /* OPTION_METHODS_START */ |
| 31 | + |
| 32 | + public enum APIErrorValueType { |
| 33 | + case APIMisuseError, FeeRateTooHigh, RouteError, ChannelUnavailable, IncompatibleShutdownScript |
| 34 | + } |
| 35 | + |
| 36 | + public func getValueType() -> APIErrorValueType? { |
| 37 | + switch self.cOpaqueStruct?.tag { |
| 38 | + |
| 39 | + case LDKAPIError_APIMisuseError: |
| 40 | + return .APIMisuseError |
| 41 | + case LDKAPIError_FeeRateTooHigh: |
| 42 | + return .FeeRateTooHigh |
| 43 | + case LDKAPIError_RouteError: |
| 44 | + return .RouteError |
| 45 | + case LDKAPIError_ChannelUnavailable: |
| 46 | + return .ChannelUnavailable |
| 47 | + case LDKAPIError_IncompatibleShutdownScript: |
| 48 | + return .IncompatibleShutdownScript |
| 49 | + default: |
| 50 | + return nil |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | + public func getValueAsAPIMisuseError() -> APIMisuseError? { |
| 56 | + if self.cOpaqueStruct?.tag != LDKAPIError_APIMisuseError { |
| 57 | + return nil |
| 58 | + } |
| 59 | + return APIMisuseError(pointer: self.cOpaqueStruct!.api_misuse_error, anchor: self) |
| 60 | + } |
| 61 | + |
| 62 | + public func getValueAsFeeRateTooHigh() -> FeeRateTooHigh? { |
| 63 | + if self.cOpaqueStruct?.tag != LDKAPIError_FeeRateTooHigh { |
| 64 | + return nil |
| 65 | + } |
| 66 | + return FeeRateTooHigh(pointer: self.cOpaqueStruct!.fee_rate_too_high, anchor: self) |
| 67 | + } |
| 68 | + |
| 69 | + public func getValueAsRouteError() -> RouteError? { |
| 70 | + if self.cOpaqueStruct?.tag != LDKAPIError_RouteError { |
| 71 | + return nil |
| 72 | + } |
| 73 | + return RouteError(pointer: self.cOpaqueStruct!.route_error, anchor: self) |
| 74 | + } |
| 75 | + |
| 76 | + public func getValueAsChannelUnavailable() -> ChannelUnavailable? { |
| 77 | + if self.cOpaqueStruct?.tag != LDKAPIError_ChannelUnavailable { |
| 78 | + return nil |
| 79 | + } |
| 80 | + return ChannelUnavailable(pointer: self.cOpaqueStruct!.channel_unavailable, anchor: self) |
| 81 | + } |
| 82 | + |
| 83 | + public func getValueAsIncompatibleShutdownScript() -> IncompatibleShutdownScript? { |
| 84 | + if self.cOpaqueStruct?.tag != LDKAPIError_IncompatibleShutdownScript { |
| 85 | + return nil |
| 86 | + } |
| 87 | + return IncompatibleShutdownScript(pointer: self.cOpaqueStruct!.incompatible_shutdown_script, anchor: self) |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + internal func free() -> Void { |
| 92 | + |
| 93 | + return APIError_free(self.cOpaqueStruct!); |
| 94 | + } |
| 95 | + |
| 96 | + internal func dangle() -> APIError { |
| 97 | + self.dangling = true |
| 98 | + return self |
| 99 | + } |
| 100 | + |
| 101 | + deinit { |
| 102 | + if !self.dangling { |
| 103 | + Bindings.print("Freeing APIError \(self.instanceNumber).") |
| 104 | + self.free() |
| 105 | + } else { |
| 106 | + Bindings.print("Not freeing APIError \(self.instanceNumber) due to dangle.") |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + |
| 111 | + public func clone() -> APIError { |
| 112 | + |
| 113 | + return APIError(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (origPointer: UnsafePointer<LDKAPIError>) in |
| 114 | +APIError_clone(origPointer) |
| 115 | +}); |
| 116 | + } |
| 117 | + |
| 118 | + internal func danglingClone() -> APIError { |
| 119 | + let dangledClone = self.clone() |
| 120 | + dangledClone.dangling = true |
| 121 | + return dangledClone |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + public class func apimisuse_error(err: String) -> APIError { |
| 126 | + |
| 127 | + return APIError(pointer: APIError_apimisuse_error(Bindings.new_LDKStr(string: err, chars_is_owned: true))); |
| 128 | + } |
| 129 | + |
| 130 | + public class func fee_rate_too_high(err: String, feerate: UInt32) -> APIError { |
| 131 | + |
| 132 | + return APIError(pointer: APIError_fee_rate_too_high(Bindings.new_LDKStr(string: err, chars_is_owned: true), feerate)); |
| 133 | + } |
| 134 | + |
| 135 | + public class func route_error(err: String) -> APIError { |
| 136 | + |
| 137 | + return APIError(pointer: APIError_route_error(Bindings.new_LDKStr(string: err, chars_is_owned: true))); |
| 138 | + } |
| 139 | + |
| 140 | + public class func channel_unavailable(err: String) -> APIError { |
| 141 | + |
| 142 | + return APIError(pointer: APIError_channel_unavailable(Bindings.new_LDKStr(string: err, chars_is_owned: true))); |
| 143 | + } |
| 144 | + |
| 145 | + public class func monitor_update_failed() -> APIError { |
| 146 | + |
| 147 | + return APIError(pointer: APIError_monitor_update_failed()); |
| 148 | + } |
| 149 | + |
| 150 | + public class func incompatible_shutdown_script(script: ShutdownScript) -> APIError { |
| 151 | + |
| 152 | + return APIError(pointer: APIError_incompatible_shutdown_script(script.danglingClone().cOpaqueStruct!)); |
| 153 | + } |
| 154 | + |
| 155 | + /* OPTION_METHODS_END */ |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + public class APIMisuseError: NativeTypeWrapper { |
| 160 | + |
| 161 | + |
| 162 | + var cOpaqueStruct: LDKAPIError_LDKAPIMisuseError_Body?; |
| 163 | + fileprivate init(pointer: LDKAPIError_LDKAPIMisuseError_Body) { |
| 164 | + self.cOpaqueStruct = pointer |
| 165 | + super.init(conflictAvoidingVariableName: 0) |
| 166 | + } |
| 167 | + fileprivate init(pointer: LDKAPIError_LDKAPIMisuseError_Body, anchor: NativeTypeWrapper) { |
| 168 | + self.cOpaqueStruct = pointer |
| 169 | + super.init(conflictAvoidingVariableName: 0) |
| 170 | + self.dangling = true |
| 171 | + try! self.addAnchor(anchor: anchor) |
| 172 | + } |
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + public func getErr() -> String { |
| 177 | + return Bindings.LDKStr_to_string(nativeType: self.cOpaqueStruct!.err) |
| 178 | + } |
| 179 | + |
| 180 | + |
| 181 | + } |
| 182 | + |
| 183 | + |
| 184 | + public class FeeRateTooHigh: NativeTypeWrapper { |
| 185 | + |
| 186 | + |
| 187 | + var cOpaqueStruct: LDKAPIError_LDKFeeRateTooHigh_Body?; |
| 188 | + fileprivate init(pointer: LDKAPIError_LDKFeeRateTooHigh_Body) { |
| 189 | + self.cOpaqueStruct = pointer |
| 190 | + super.init(conflictAvoidingVariableName: 0) |
| 191 | + } |
| 192 | + fileprivate init(pointer: LDKAPIError_LDKFeeRateTooHigh_Body, anchor: NativeTypeWrapper) { |
| 193 | + self.cOpaqueStruct = pointer |
| 194 | + super.init(conflictAvoidingVariableName: 0) |
| 195 | + self.dangling = true |
| 196 | + try! self.addAnchor(anchor: anchor) |
| 197 | + } |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + public func getErr() -> String { |
| 202 | + return Bindings.LDKStr_to_string(nativeType: self.cOpaqueStruct!.err) |
| 203 | + } |
| 204 | + |
| 205 | + public func getFeerate() -> UInt32 { |
| 206 | + return self.cOpaqueStruct!.feerate |
| 207 | + } |
| 208 | + |
| 209 | + |
| 210 | + } |
| 211 | + |
| 212 | + |
| 213 | + public class RouteError: NativeTypeWrapper { |
| 214 | + |
| 215 | + |
| 216 | + var cOpaqueStruct: LDKAPIError_LDKRouteError_Body?; |
| 217 | + fileprivate init(pointer: LDKAPIError_LDKRouteError_Body) { |
| 218 | + self.cOpaqueStruct = pointer |
| 219 | + super.init(conflictAvoidingVariableName: 0) |
| 220 | + } |
| 221 | + fileprivate init(pointer: LDKAPIError_LDKRouteError_Body, anchor: NativeTypeWrapper) { |
| 222 | + self.cOpaqueStruct = pointer |
| 223 | + super.init(conflictAvoidingVariableName: 0) |
| 224 | + self.dangling = true |
| 225 | + try! self.addAnchor(anchor: anchor) |
| 226 | + } |
| 227 | + |
| 228 | + |
| 229 | + |
| 230 | + public func getErr() -> String { |
| 231 | + return Bindings.LDKStr_to_string(nativeType: self.cOpaqueStruct!.err) |
| 232 | + } |
| 233 | + |
| 234 | + |
| 235 | + } |
| 236 | + |
| 237 | + |
| 238 | + public class ChannelUnavailable: NativeTypeWrapper { |
| 239 | + |
| 240 | + |
| 241 | + var cOpaqueStruct: LDKAPIError_LDKChannelUnavailable_Body?; |
| 242 | + fileprivate init(pointer: LDKAPIError_LDKChannelUnavailable_Body) { |
| 243 | + self.cOpaqueStruct = pointer |
| 244 | + super.init(conflictAvoidingVariableName: 0) |
| 245 | + } |
| 246 | + fileprivate init(pointer: LDKAPIError_LDKChannelUnavailable_Body, anchor: NativeTypeWrapper) { |
| 247 | + self.cOpaqueStruct = pointer |
| 248 | + super.init(conflictAvoidingVariableName: 0) |
| 249 | + self.dangling = true |
| 250 | + try! self.addAnchor(anchor: anchor) |
| 251 | + } |
| 252 | + |
| 253 | + |
| 254 | + |
| 255 | + public func getErr() -> String { |
| 256 | + return Bindings.LDKStr_to_string(nativeType: self.cOpaqueStruct!.err) |
| 257 | + } |
| 258 | + |
| 259 | + |
| 260 | + } |
| 261 | + |
| 262 | + |
| 263 | + public class IncompatibleShutdownScript: NativeTypeWrapper { |
| 264 | + |
| 265 | + |
| 266 | + var cOpaqueStruct: LDKAPIError_LDKIncompatibleShutdownScript_Body?; |
| 267 | + fileprivate init(pointer: LDKAPIError_LDKIncompatibleShutdownScript_Body) { |
| 268 | + self.cOpaqueStruct = pointer |
| 269 | + super.init(conflictAvoidingVariableName: 0) |
| 270 | + } |
| 271 | + fileprivate init(pointer: LDKAPIError_LDKIncompatibleShutdownScript_Body, anchor: NativeTypeWrapper) { |
| 272 | + self.cOpaqueStruct = pointer |
| 273 | + super.init(conflictAvoidingVariableName: 0) |
| 274 | + self.dangling = true |
| 275 | + try! self.addAnchor(anchor: anchor) |
| 276 | + } |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + public func getScript() -> ShutdownScript { |
| 281 | + return ShutdownScript(pointer: self.cOpaqueStruct!.script, anchor: self) |
| 282 | + } |
| 283 | + |
| 284 | + |
| 285 | + } |
| 286 | + |
| 287 | +} |
0 commit comments