|
| 1 | +public class EffectiveCapacity: NativeTypeWrapper { |
| 2 | + |
| 3 | + private static var instanceCounter: UInt = 0 |
| 4 | + internal let instanceNumber: UInt |
| 5 | + |
| 6 | + internal var cOpaqueStruct: LDKEffectiveCapacity? |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + public init(pointer: LDKEffectiveCapacity){ |
| 11 | + Self.instanceCounter += 1 |
| 12 | + self.instanceNumber = Self.instanceCounter |
| 13 | + self.cOpaqueStruct = pointer |
| 14 | + super.init(conflictAvoidingVariableName: 0) |
| 15 | + } |
| 16 | + |
| 17 | + public init(pointer: LDKEffectiveCapacity, anchor: NativeTypeWrapper){ |
| 18 | + Self.instanceCounter += 1 |
| 19 | + self.instanceNumber = Self.instanceCounter |
| 20 | + self.cOpaqueStruct = pointer |
| 21 | + super.init(conflictAvoidingVariableName: 0) |
| 22 | + self.dangling = true |
| 23 | + try! self.addAnchor(anchor: anchor) |
| 24 | + } |
| 25 | + |
| 26 | + /* OPTION_METHODS_START */ |
| 27 | + |
| 28 | + public enum EffectiveCapacityValueType { |
| 29 | + case ExactLiquidity, MaximumHTLC, Total |
| 30 | + } |
| 31 | + |
| 32 | + public func getValueType() -> EffectiveCapacityValueType? { |
| 33 | + switch self.cOpaqueStruct?.tag { |
| 34 | + |
| 35 | + case LDKEffectiveCapacity_ExactLiquidity: |
| 36 | + return .ExactLiquidity |
| 37 | + case LDKEffectiveCapacity_MaximumHTLC: |
| 38 | + return .MaximumHTLC |
| 39 | + case LDKEffectiveCapacity_Total: |
| 40 | + return .Total |
| 41 | + default: |
| 42 | + return nil |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + public func getValueAsExactLiquidity() -> ExactLiquidity? { |
| 48 | + if self.cOpaqueStruct?.tag != LDKEffectiveCapacity_ExactLiquidity { |
| 49 | + return nil |
| 50 | + } |
| 51 | + return ExactLiquidity(pointer: self.cOpaqueStruct!.exact_liquidity, anchor: self) |
| 52 | + } |
| 53 | + |
| 54 | + public func getValueAsMaximumHTLC() -> MaximumHTLC? { |
| 55 | + if self.cOpaqueStruct?.tag != LDKEffectiveCapacity_MaximumHTLC { |
| 56 | + return nil |
| 57 | + } |
| 58 | + return MaximumHTLC(pointer: self.cOpaqueStruct!.maximum_htlc, anchor: self) |
| 59 | + } |
| 60 | + |
| 61 | + public func getValueAsTotal() -> Total? { |
| 62 | + if self.cOpaqueStruct?.tag != LDKEffectiveCapacity_Total { |
| 63 | + return nil |
| 64 | + } |
| 65 | + return Total(pointer: self.cOpaqueStruct!.total, anchor: self) |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + internal func free() -> Void { |
| 70 | + |
| 71 | + return EffectiveCapacity_free(self.cOpaqueStruct!); |
| 72 | + } |
| 73 | + |
| 74 | + internal func dangle() -> EffectiveCapacity { |
| 75 | + self.dangling = true |
| 76 | + return self |
| 77 | + } |
| 78 | + |
| 79 | + deinit { |
| 80 | + if !self.dangling { |
| 81 | + Bindings.print("Freeing EffectiveCapacity \(self.instanceNumber).") |
| 82 | + self.free() |
| 83 | + } else { |
| 84 | + Bindings.print("Not freeing EffectiveCapacity \(self.instanceNumber) due to dangle.") |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + |
| 89 | + public func clone() -> EffectiveCapacity { |
| 90 | + |
| 91 | + return EffectiveCapacity(pointer: withUnsafePointer(to: self.cOpaqueStruct!) { (origPointer: UnsafePointer<LDKEffectiveCapacity>) in |
| 92 | +EffectiveCapacity_clone(origPointer) |
| 93 | +}); |
| 94 | + } |
| 95 | + |
| 96 | + internal func danglingClone() -> EffectiveCapacity { |
| 97 | + let dangledClone = self.clone() |
| 98 | + dangledClone.dangling = true |
| 99 | + return dangledClone |
| 100 | + } |
| 101 | + |
| 102 | + |
| 103 | + public class func exact_liquidity(liquidity_msat: UInt64) -> EffectiveCapacity { |
| 104 | + |
| 105 | + return EffectiveCapacity(pointer: EffectiveCapacity_exact_liquidity(liquidity_msat)); |
| 106 | + } |
| 107 | + |
| 108 | + public class func maximum_htlc(amount_msat: UInt64) -> EffectiveCapacity { |
| 109 | + |
| 110 | + return EffectiveCapacity(pointer: EffectiveCapacity_maximum_htlc(amount_msat)); |
| 111 | + } |
| 112 | + |
| 113 | + public class func total(capacity_msat: UInt64) -> EffectiveCapacity { |
| 114 | + |
| 115 | + return EffectiveCapacity(pointer: EffectiveCapacity_total(capacity_msat)); |
| 116 | + } |
| 117 | + |
| 118 | + public class func infinite() -> EffectiveCapacity { |
| 119 | + |
| 120 | + return EffectiveCapacity(pointer: EffectiveCapacity_infinite()); |
| 121 | + } |
| 122 | + |
| 123 | + public class func unknown() -> EffectiveCapacity { |
| 124 | + |
| 125 | + return EffectiveCapacity(pointer: EffectiveCapacity_unknown()); |
| 126 | + } |
| 127 | + |
| 128 | + public func as_msat() -> UInt64 { |
| 129 | + |
| 130 | + return withUnsafePointer(to: self.cOpaqueStruct!) { (this_argPointer: UnsafePointer<LDKEffectiveCapacity>) in |
| 131 | +EffectiveCapacity_as_msat(this_argPointer) |
| 132 | +}; |
| 133 | + } |
| 134 | + |
| 135 | + /* OPTION_METHODS_END */ |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + public class ExactLiquidity: NativeTypeWrapper { |
| 140 | + |
| 141 | + |
| 142 | + var cOpaqueStruct: LDKEffectiveCapacity_LDKExactLiquidity_Body?; |
| 143 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKExactLiquidity_Body) { |
| 144 | + self.cOpaqueStruct = pointer |
| 145 | + super.init(conflictAvoidingVariableName: 0) |
| 146 | + } |
| 147 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKExactLiquidity_Body, anchor: NativeTypeWrapper) { |
| 148 | + self.cOpaqueStruct = pointer |
| 149 | + super.init(conflictAvoidingVariableName: 0) |
| 150 | + self.dangling = true |
| 151 | + try! self.addAnchor(anchor: anchor) |
| 152 | + } |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + public func getLiquidity_msat() -> UInt64 { |
| 157 | + return self.cOpaqueStruct!.liquidity_msat |
| 158 | + } |
| 159 | + |
| 160 | + |
| 161 | + } |
| 162 | + |
| 163 | + |
| 164 | + public class MaximumHTLC: NativeTypeWrapper { |
| 165 | + |
| 166 | + |
| 167 | + var cOpaqueStruct: LDKEffectiveCapacity_LDKMaximumHTLC_Body?; |
| 168 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKMaximumHTLC_Body) { |
| 169 | + self.cOpaqueStruct = pointer |
| 170 | + super.init(conflictAvoidingVariableName: 0) |
| 171 | + } |
| 172 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKMaximumHTLC_Body, anchor: NativeTypeWrapper) { |
| 173 | + self.cOpaqueStruct = pointer |
| 174 | + super.init(conflictAvoidingVariableName: 0) |
| 175 | + self.dangling = true |
| 176 | + try! self.addAnchor(anchor: anchor) |
| 177 | + } |
| 178 | + |
| 179 | + |
| 180 | + |
| 181 | + public func getAmount_msat() -> UInt64 { |
| 182 | + return self.cOpaqueStruct!.amount_msat |
| 183 | + } |
| 184 | + |
| 185 | + |
| 186 | + } |
| 187 | + |
| 188 | + |
| 189 | + public class Total: NativeTypeWrapper { |
| 190 | + |
| 191 | + |
| 192 | + var cOpaqueStruct: LDKEffectiveCapacity_LDKTotal_Body?; |
| 193 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKTotal_Body) { |
| 194 | + self.cOpaqueStruct = pointer |
| 195 | + super.init(conflictAvoidingVariableName: 0) |
| 196 | + } |
| 197 | + fileprivate init(pointer: LDKEffectiveCapacity_LDKTotal_Body, anchor: NativeTypeWrapper) { |
| 198 | + self.cOpaqueStruct = pointer |
| 199 | + super.init(conflictAvoidingVariableName: 0) |
| 200 | + self.dangling = true |
| 201 | + try! self.addAnchor(anchor: anchor) |
| 202 | + } |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + public func getCapacity_msat() -> UInt64 { |
| 207 | + return self.cOpaqueStruct!.capacity_msat |
| 208 | + } |
| 209 | + |
| 210 | + |
| 211 | + } |
| 212 | + |
| 213 | +} |
0 commit comments