diff --git a/bindings/swift/Sources/OrangeSDK/OrangeSDK.swift b/bindings/swift/Sources/OrangeSDK/OrangeSDK.swift new file mode 100644 index 0000000..0114dcd --- /dev/null +++ b/bindings/swift/Sources/OrangeSDK/OrangeSDK.swift @@ -0,0 +1,6072 @@ +// This file was autogenerated by some hot garbage in the `uniffi` crate. +// Trust me, you don't want to mess with it! + +import SystemConfiguration +// swiftlint:disable all +import Foundation + +// Depending on the consumer's build setup, the low-level FFI code +// might be in a separate module, or it might be compiled inline into +// this module. This is a bit of light hackery to work with both. +#if canImport(OrangeSDKFFI) +import OrangeSDKFFI +#endif + +fileprivate extension RustBuffer { + // Allocate a new buffer, copying the contents of a `UInt8` array. + init(bytes: [UInt8]) { + let rbuf = bytes.withUnsafeBufferPointer { ptr in + RustBuffer.from(ptr) + } + self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data) + } + + static func empty() -> RustBuffer { + RustBuffer(capacity: 0, len:0, data: nil) + } + + static func from(_ ptr: UnsafeBufferPointer) -> RustBuffer { + try! rustCall { ffi_orange_sdk_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) } + } + + // Frees the buffer in place. + // The buffer must not be used after this is called. + func deallocate() { + try! rustCall { ffi_orange_sdk_rustbuffer_free(self, $0) } + } +} + +fileprivate extension ForeignBytes { + init(bufferPointer: UnsafeBufferPointer) { + self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress) + } +} + +// For every type used in the interface, we provide helper methods for conveniently +// lifting and lowering that type from C-compatible data, and for reading and writing +// values of that type in a buffer. + +// Helper classes/extensions that don't change. +// Someday, this will be in a library of its own. + +fileprivate extension Data { + init(rustBuffer: RustBuffer) { + self.init( + bytesNoCopy: rustBuffer.data!, + count: Int(rustBuffer.len), + deallocator: .none + ) + } +} + +// Define reader functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. +// +// With external types, one swift source file needs to be able to call the read +// method on another source file's FfiConverter, but then what visibility +// should Reader have? +// - If Reader is fileprivate, then this means the read() must also +// be fileprivate, which doesn't work with external types. +// - If Reader is internal/public, we'll get compile errors since both source +// files will try define the same type. +// +// Instead, the read() method and these helper functions input a tuple of data + +fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) { + (data: data, offset: 0) +} + +// Reads an integer at the current offset, in big-endian order, and advances +// the offset on success. Throws if reading the integer would move the +// offset past the end of the buffer. +fileprivate func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { + let range = reader.offset...size + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + if T.self == UInt8.self { + let value = reader.data[reader.offset] + reader.offset += 1 + return value as! T + } + var value: T = 0 + let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)}) + reader.offset = range.upperBound + return value.bigEndian +} + +// Reads an arbitrary number of bytes, to be used to read +// raw bytes, this is useful when lifting strings +fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array { + let range = reader.offset..<(reader.offset+count) + guard reader.data.count >= range.upperBound else { + throw UniffiInternalError.bufferOverflow + } + var value = [UInt8](repeating: 0, count: count) + value.withUnsafeMutableBufferPointer({ buffer in + reader.data.copyBytes(to: buffer, from: range) + }) + reader.offset = range.upperBound + return value +} + +// Reads a float at the current offset. +fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { + return Float(bitPattern: try readInt(&reader)) +} + +// Reads a float at the current offset. +fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { + return Double(bitPattern: try readInt(&reader)) +} + +// Indicates if the offset has reached the end of the buffer. +fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool { + return reader.offset < reader.data.count +} + +// Define writer functionality. Normally this would be defined in a class or +// struct, but we use standalone functions instead in order to make external +// types work. See the above discussion on Readers for details. + +fileprivate func createWriter() -> [UInt8] { + return [] +} + +fileprivate func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 { + writer.append(contentsOf: byteArr) +} + +// Writes an integer in big-endian order. +// +// Warning: make sure what you are trying to write +// is in the correct type! +fileprivate func writeInt(_ writer: inout [UInt8], _ value: T) { + var value = value.bigEndian + withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } +} + +fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) { + writeInt(&writer, value.bitPattern) +} + +fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) { + writeInt(&writer, value.bitPattern) +} + +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. +fileprivate protocol FfiConverter { + associatedtype FfiType + associatedtype SwiftType + + static func lift(_ value: FfiType) throws -> SwiftType + static func lower(_ value: SwiftType) -> FfiType + static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType + static func write(_ value: SwiftType, into buf: inout [UInt8]) +} + +// Types conforming to `Primitive` pass themselves directly over the FFI. +fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { } + +extension FfiConverterPrimitive { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lift(_ value: FfiType) throws -> SwiftType { + return value + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lower(_ value: SwiftType) -> FfiType { + return value + } +} + +// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. +// Used for complex types where it's hard to write a custom lift/lower. +fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} + +extension FfiConverterRustBuffer { +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lift(_ buf: RustBuffer) throws -> SwiftType { + var reader = createReader(data: Data(rustBuffer: buf)) + let value = try read(from: &reader) + if hasRemaining(reader) { + throw UniffiInternalError.incompleteData + } + buf.deallocate() + return value + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public static func lower(_ value: SwiftType) -> RustBuffer { + var writer = createWriter() + write(value, into: &writer) + return RustBuffer(bytes: writer) + } +} +// An error type for FFI errors. These errors occur at the UniFFI level, not +// the library level. +fileprivate enum UniffiInternalError: LocalizedError { + case bufferOverflow + case incompleteData + case unexpectedOptionalTag + case unexpectedEnumCase + case unexpectedNullPointer + case unexpectedRustCallStatusCode + case unexpectedRustCallError + case unexpectedStaleHandle + case rustPanic(_ message: String) + + public var errorDescription: String? { + switch self { + case .bufferOverflow: return "Reading the requested value would read past the end of the buffer" + case .incompleteData: return "The buffer still has data after lifting its containing value" + case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1" + case .unexpectedEnumCase: return "Raw enum value doesn't match any cases" + case .unexpectedNullPointer: return "Raw pointer value was null" + case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code" + case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified" + case .unexpectedStaleHandle: return "The object in the handle map has been dropped already" + case let .rustPanic(message): return message + } + } +} + +fileprivate extension NSLock { + func withLock(f: () throws -> T) rethrows -> T { + self.lock() + defer { self.unlock() } + return try f() + } +} + +fileprivate let CALL_SUCCESS: Int8 = 0 +fileprivate let CALL_ERROR: Int8 = 1 +fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2 +fileprivate let CALL_CANCELLED: Int8 = 3 + +fileprivate extension RustCallStatus { + init() { + self.init( + code: CALL_SUCCESS, + errorBuf: RustBuffer.init( + capacity: 0, + len: 0, + data: nil + ) + ) + } +} + +private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { + let neverThrow: ((RustBuffer) throws -> Never)? = nil + return try makeRustCall(callback, errorHandler: neverThrow) +} + +private func rustCallWithError( + _ errorHandler: @escaping (RustBuffer) throws -> E, + _ callback: (UnsafeMutablePointer) -> T) throws -> T { + try makeRustCall(callback, errorHandler: errorHandler) +} + +private func makeRustCall( + _ callback: (UnsafeMutablePointer) -> T, + errorHandler: ((RustBuffer) throws -> E)? +) throws -> T { + uniffiEnsureOrangeSdkInitialized() + var callStatus = RustCallStatus.init() + let returnedVal = callback(&callStatus) + try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler) + return returnedVal +} + +private func uniffiCheckCallStatus( + callStatus: RustCallStatus, + errorHandler: ((RustBuffer) throws -> E)? +) throws { + switch callStatus.code { + case CALL_SUCCESS: + return + + case CALL_ERROR: + if let errorHandler = errorHandler { + throw try errorHandler(callStatus.errorBuf) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.unexpectedRustCallError + } + + case CALL_UNEXPECTED_ERROR: + // When the rust code sees a panic, it tries to construct a RustBuffer + // with the message. But if that code panics, then it just sends back + // an empty buffer. + if callStatus.errorBuf.len > 0 { + throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf)) + } else { + callStatus.errorBuf.deallocate() + throw UniffiInternalError.rustPanic("Rust panic") + } + + case CALL_CANCELLED: + fatalError("Cancellation not supported yet") + + default: + throw UniffiInternalError.unexpectedRustCallStatusCode + } +} + +private func uniffiTraitInterfaceCall( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> () +) { + do { + try writeReturn(makeCall()) + } catch let error { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} + +private func uniffiTraitInterfaceCallWithError( + callStatus: UnsafeMutablePointer, + makeCall: () throws -> T, + writeReturn: (T) -> (), + lowerError: (E) -> RustBuffer +) { + do { + try writeReturn(makeCall()) + } catch let error as E { + callStatus.pointee.code = CALL_ERROR + callStatus.pointee.errorBuf = lowerError(error) + } catch { + callStatus.pointee.code = CALL_UNEXPECTED_ERROR + callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error)) + } +} +fileprivate final class UniffiHandleMap: @unchecked Sendable { + // All mutation happens with this lock held, which is why we implement @unchecked Sendable. + private let lock = NSLock() + private var map: [UInt64: T] = [:] + private var currentHandle: UInt64 = 1 + + func insert(obj: T) -> UInt64 { + lock.withLock { + let handle = currentHandle + currentHandle += 1 + map[handle] = obj + return handle + } + } + + func get(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map[handle] else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + @discardableResult + func remove(handle: UInt64) throws -> T { + try lock.withLock { + guard let obj = map.removeValue(forKey: handle) else { + throw UniffiInternalError.unexpectedStaleHandle + } + return obj + } + } + + var count: Int { + get { + map.count + } + } +} + + +// Public interface members begin here. + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt16: FfiConverterPrimitive { + typealias FfiType = UInt16 + typealias SwiftType = UInt16 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt16 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt32: FfiConverterPrimitive { + typealias FfiType = UInt32 + typealias SwiftType = UInt32 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterUInt64: FfiConverterPrimitive { + typealias FfiType = UInt64 + typealias SwiftType = UInt64 + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 { + return try lift(readInt(&buf)) + } + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterBool : FfiConverter { + typealias FfiType = Int8 + typealias SwiftType = Bool + + public static func lift(_ value: Int8) throws -> Bool { + return value != 0 + } + + public static func lower(_ value: Bool) -> Int8 { + return value ? 1 : 0 + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool { + return try lift(readInt(&buf)) + } + + public static func write(_ value: Bool, into buf: inout [UInt8]) { + writeInt(&buf, lower(value)) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterString: FfiConverter { + typealias SwiftType = String + typealias FfiType = RustBuffer + + public static func lift(_ value: RustBuffer) throws -> String { + defer { + value.deallocate() + } + if value.data == nil { + return String() + } + let bytes = UnsafeBufferPointer(start: value.data!, count: Int(value.len)) + return String(bytes: bytes, encoding: String.Encoding.utf8)! + } + + public static func lower(_ value: String) -> RustBuffer { + return value.utf8CString.withUnsafeBufferPointer { ptr in + // The swift string gives us int8_t, we want uint8_t. + ptr.withMemoryRebound(to: UInt8.self) { ptr in + // The swift string gives us a trailing null byte, we don't want it. + let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1)) + return RustBuffer.from(buf) + } + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String { + let len: Int32 = try readInt(&buf) + return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)! + } + + public static func write(_ value: String, into buf: inout [UInt8]) { + let len = Int32(value.utf8.count) + writeInt(&buf, len) + writeBytes(&buf, value.utf8) + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterData: FfiConverterRustBuffer { + typealias SwiftType = Data + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Data { + let len: Int32 = try readInt(&buf) + return Data(try readBytes(&buf, count: Int(len))) + } + + public static func write(_ value: Data, into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + writeBytes(&buf, value) + } +} + + + + +public protocol AmountProtocol: AnyObject, Sendable { + + func milliSats() -> UInt64 + + func sats() throws -> UInt64 + + func satsRoundingUp() -> UInt64 + + func saturatingAdd(rhs: Amount) -> Amount + + func saturatingSub(rhs: Amount) -> Amount + +} +open class Amount: AmountProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_amount(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_amount(pointer, $0) } + } + + +public static func fromMilliSats(msats: UInt64)throws -> Amount { + return try FfiConverterTypeAmount_lift(try rustCallWithError(FfiConverterTypeAmountError_lift) { + uniffi_orange_sdk_fn_constructor_amount_from_milli_sats( + FfiConverterUInt64.lower(msats),$0 + ) +}) +} + +public static func fromSats(sats: UInt64)throws -> Amount { + return try FfiConverterTypeAmount_lift(try rustCallWithError(FfiConverterTypeAmountError_lift) { + uniffi_orange_sdk_fn_constructor_amount_from_sats( + FfiConverterUInt64.lower(sats),$0 + ) +}) +} + + + +open func milliSats() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_amount_milli_sats(self.uniffiClonePointer(),$0 + ) +}) +} + +open func sats()throws -> UInt64 { + return try FfiConverterUInt64.lift(try rustCallWithError(FfiConverterTypeAmountError_lift) { + uniffi_orange_sdk_fn_method_amount_sats(self.uniffiClonePointer(),$0 + ) +}) +} + +open func satsRoundingUp() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_amount_sats_rounding_up(self.uniffiClonePointer(),$0 + ) +}) +} + +open func saturatingAdd(rhs: Amount) -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_amount_saturating_add(self.uniffiClonePointer(), + FfiConverterTypeAmount_lower(rhs),$0 + ) +}) +} + +open func saturatingSub(rhs: Amount) -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_amount_saturating_sub(self.uniffiClonePointer(), + FfiConverterTypeAmount_lower(rhs),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeAmount: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Amount + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { + return Amount(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Amount) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Amount { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Amount, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeAmount_lift(_ pointer: UnsafeMutableRawPointer) throws -> Amount { + return try FfiConverterTypeAmount.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeAmount_lower(_ value: Amount) -> UnsafeMutableRawPointer { + return FfiConverterTypeAmount.lower(value) +} + + + + + + +/** + * Represents the balances of the wallet, including available and pending balances. + */ +public protocol BalancesProtocol: AnyObject, Sendable { + + /** + * Returns the total available balance, which is the sum of the lightning and trusted balances. + */ + func availableBalance() -> Amount + + /** + * Returns the lightning balance. + */ + func lightningBalance() -> Amount + + /** + * Returns the pending balance. + */ + func pendingBalance() -> Amount + + /** + * Returns the trusted balance. + */ + func trustedBalance() -> Amount + +} +/** + * Represents the balances of the wallet, including available and pending balances. + */ +open class Balances: BalancesProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_balances(self.pointer, $0) } + } +public convenience init(lightning: Amount, trusted: Amount, pendingBalance: Amount) { + let pointer = + try! rustCall() { + uniffi_orange_sdk_fn_constructor_balances_new( + FfiConverterTypeAmount_lower(lightning), + FfiConverterTypeAmount_lower(trusted), + FfiConverterTypeAmount_lower(pendingBalance),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_balances(pointer, $0) } + } + + + + + /** + * Returns the total available balance, which is the sum of the lightning and trusted balances. + */ +open func availableBalance() -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_balances_available_balance(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Returns the lightning balance. + */ +open func lightningBalance() -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_balances_lightning_balance(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Returns the pending balance. + */ +open func pendingBalance() -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_balances_pending_balance(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Returns the trusted balance. + */ +open func trustedBalance() -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_balances_trusted_balance(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeBalances: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Balances + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Balances { + return Balances(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Balances) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Balances { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Balances, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeBalances_lift(_ pointer: UnsafeMutableRawPointer) throws -> Balances { + return try FfiConverterTypeBalances.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeBalances_lower(_ value: Balances) -> UnsafeMutableRawPointer { + return FfiConverterTypeBalances.lower(value) +} + + + + + + +/** + * Configuration for the Cashu wallet + */ +public protocol CashuConfigProtocol: AnyObject, Sendable { + +} +/** + * Configuration for the Cashu wallet + */ +open class CashuConfig: CashuConfigProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_cashuconfig(self.pointer, $0) } + } +public convenience init(mintUrl: String, unit: CurrencyUnit, npubcashUrl: String?) { + let pointer = + try! rustCall() { + uniffi_orange_sdk_fn_constructor_cashuconfig_new( + FfiConverterString.lower(mintUrl), + FfiConverterTypeCurrencyUnit_lower(unit), + FfiConverterOptionString.lower(npubcashUrl),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_cashuconfig(pointer, $0) } + } + + + + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeCashuConfig: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = CashuConfig + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> CashuConfig { + return CashuConfig(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: CashuConfig) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CashuConfig { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: CashuConfig, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeCashuConfig_lift(_ pointer: UnsafeMutableRawPointer) throws -> CashuConfig { + return try FfiConverterTypeCashuConfig.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeCashuConfig_lower(_ value: CashuConfig) -> UnsafeMutableRawPointer { + return FfiConverterTypeCashuConfig.lower(value) +} + + + + + + +public protocol ChannelDetailsProtocol: AnyObject, Sendable { + + /** + * The channel ID (used for identification purposes). + */ + func channelId() -> Data + + /** + * The value, in satoshis, of this channel as it appears in the funding transaction. + */ + func channelValueSats() -> UInt64 + + /** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel. + */ + func cltvExpiryDelta() -> UInt16? + + /** + * The number of confirmations the funding transaction has. + */ + func confirmations() -> UInt32? + + /** + * The number of required confirmations on the funding transaction before the funding will be + * considered confirmed. + */ + func confirmationsRequired() -> UInt32? + + /** + * The node ID of the counterparty. + */ + func counterpartyNodeId() -> String + + /** + * The currently negotiated fee rate denominated in satoshi per 1000 weight units. + */ + func feerateSatPer1000Weight() -> UInt32 + + /** + * The funding transaction output. + */ + func fundingTxo() -> String? + + /** + * The available inbound capacity for receiving HTLCs from the remote peer. + */ + func inboundCapacityMsat() -> UInt64 + + /** + * True if the channel is confirmed, channel_ready messages have been exchanged, and the channel + * is not currently being shut down. + */ + func isChannelReady() -> Bool + + /** + * True if the channel was initiated (and thus funded) by us. + */ + func isOutbound() -> Bool + + /** + * True if this channel is (or will be) publicly-announced. + */ + func isPublic() -> Bool + + /** + * True if the channel is (a) confirmed and channel_ready messages have been exchanged, + * and (b) the peer is connected and up-to-date. + */ + func isUsable() -> Bool + + /** + * The available outbound capacity for sending HTLCs to the remote peer. + */ + func outboundCapacityMsat() -> UInt64 + + /** + * The short channel ID if the channel has been announced and is publicly-addressable. + */ + func shortChannelId() -> UInt64? + + /** + * The value, in msat, that must always be held in the channel for us. + * This value ensures that if we close the channel, we will have some spendable balance. + */ + func unspendablePunishmentReserve() -> UInt64? + + /** + * A unique u128 identifier for this channel. + */ + func userChannelId() -> String + +} +open class ChannelDetails: ChannelDetailsProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_channeldetails(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_channeldetails(pointer, $0) } + } + + + + + /** + * The channel ID (used for identification purposes). + */ +open func channelId() -> Data { + return try! FfiConverterData.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_channel_id(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The value, in satoshis, of this channel as it appears in the funding transaction. + */ +open func channelValueSats() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_channel_value_sats(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel. + */ +open func cltvExpiryDelta() -> UInt16? { + return try! FfiConverterOptionUInt16.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_cltv_expiry_delta(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The number of confirmations the funding transaction has. + */ +open func confirmations() -> UInt32? { + return try! FfiConverterOptionUInt32.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_confirmations(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The number of required confirmations on the funding transaction before the funding will be + * considered confirmed. + */ +open func confirmationsRequired() -> UInt32? { + return try! FfiConverterOptionUInt32.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_confirmations_required(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The node ID of the counterparty. + */ +open func counterpartyNodeId() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_counterparty_node_id(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The currently negotiated fee rate denominated in satoshi per 1000 weight units. + */ +open func feerateSatPer1000Weight() -> UInt32 { + return try! FfiConverterUInt32.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_feerate_sat_per_1000_weight(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The funding transaction output. + */ +open func fundingTxo() -> String? { + return try! FfiConverterOptionString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_funding_txo(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The available inbound capacity for receiving HTLCs from the remote peer. + */ +open func inboundCapacityMsat() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_inbound_capacity_msat(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * True if the channel is confirmed, channel_ready messages have been exchanged, and the channel + * is not currently being shut down. + */ +open func isChannelReady() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_is_channel_ready(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * True if the channel was initiated (and thus funded) by us. + */ +open func isOutbound() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_is_outbound(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * True if this channel is (or will be) publicly-announced. + */ +open func isPublic() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_is_public(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * True if the channel is (a) confirmed and channel_ready messages have been exchanged, + * and (b) the peer is connected and up-to-date. + */ +open func isUsable() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_is_usable(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The available outbound capacity for sending HTLCs to the remote peer. + */ +open func outboundCapacityMsat() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_outbound_capacity_msat(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The short channel ID if the channel has been announced and is publicly-addressable. + */ +open func shortChannelId() -> UInt64? { + return try! FfiConverterOptionUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_short_channel_id(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The value, in msat, that must always be held in the channel for us. + * This value ensures that if we close the channel, we will have some spendable balance. + */ +open func unspendablePunishmentReserve() -> UInt64? { + return try! FfiConverterOptionUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_unspendable_punishment_reserve(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * A unique u128 identifier for this channel. + */ +open func userChannelId() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_channeldetails_user_channel_id(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeChannelDetails: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = ChannelDetails + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> ChannelDetails { + return ChannelDetails(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: ChannelDetails) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChannelDetails { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: ChannelDetails, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeChannelDetails_lift(_ pointer: UnsafeMutableRawPointer) throws -> ChannelDetails { + return try FfiConverterTypeChannelDetails.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeChannelDetails_lower(_ value: ChannelDetails) -> UnsafeMutableRawPointer { + return FfiConverterTypeChannelDetails.lower(value) +} + + + + + + +public protocol MnemonicProtocol: AnyObject, Sendable { + +} +open class Mnemonic: MnemonicProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_mnemonic(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_mnemonic(pointer, $0) } + } + + +public static func fromEntropy(entropy: Data)throws -> Mnemonic { + return try FfiConverterTypeMnemonic_lift(try rustCallWithError(FfiConverterTypeConfigError_lift) { + uniffi_orange_sdk_fn_constructor_mnemonic_from_entropy( + FfiConverterData.lower(entropy),$0 + ) +}) +} + +public static func fromStr(str: String)throws -> Mnemonic { + return try FfiConverterTypeMnemonic_lift(try rustCallWithError(FfiConverterTypeConfigError_lift) { + uniffi_orange_sdk_fn_constructor_mnemonic_from_str( + FfiConverterString.lower(str),$0 + ) +}) +} + +public static func generate()throws -> Mnemonic { + return try FfiConverterTypeMnemonic_lift(try rustCallWithError(FfiConverterTypeConfigError_lift) { + uniffi_orange_sdk_fn_constructor_mnemonic_generate($0 + ) +}) +} + + + + open var description: String { + return try! FfiConverterString.lift( + try! rustCall() { + uniffi_orange_sdk_fn_method_mnemonic_uniffi_trait_display(self.uniffiClonePointer(),$0 + ) +} + ) + } + +} +extension Mnemonic: CustomStringConvertible {} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeMnemonic: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Mnemonic + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Mnemonic { + return Mnemonic(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Mnemonic) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Mnemonic { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Mnemonic, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMnemonic_lift(_ pointer: UnsafeMutableRawPointer) throws -> Mnemonic { + return try FfiConverterTypeMnemonic.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeMnemonic_lower(_ value: Mnemonic) -> UnsafeMutableRawPointer { + return FfiConverterTypeMnemonic.lower(value) +} + + + + + + +public protocol PaymentInfoProtocol: AnyObject, Sendable { + + /** + * Get the payment amount + */ + func amount() -> Amount + + /** + * Get the payment instructions + */ + func instructions() -> PaymentInstructions + +} +open class PaymentInfo: PaymentInfoProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_paymentinfo(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_paymentinfo(pointer, $0) } + } + + + /** + * Build a PaymentInfo from PaymentInstructions and an optional amount + * + * For configurable amount instructions, an amount must be provided and must be within + * any specified range. For fixed amount instructions, the amount is optional and must + * match the fixed amount if provided. + */ +public static func build(instructions: PaymentInstructions, amount: Amount?)throws -> PaymentInfo { + return try FfiConverterTypePaymentInfo_lift(try rustCallWithError(FfiConverterTypePaymentInfoBuildError_lift) { + uniffi_orange_sdk_fn_constructor_paymentinfo_build( + FfiConverterTypePaymentInstructions_lower(instructions), + FfiConverterOptionTypeAmount.lower(amount),$0 + ) +}) +} + + + + /** + * Get the payment amount + */ +open func amount() -> Amount { + return try! FfiConverterTypeAmount_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinfo_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the payment instructions + */ +open func instructions() -> PaymentInstructions { + return try! FfiConverterTypePaymentInstructions_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinfo_instructions(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePaymentInfo: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = PaymentInfo + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PaymentInfo { + return PaymentInfo(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: PaymentInfo) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentInfo { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: PaymentInfo, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInfo_lift(_ pointer: UnsafeMutableRawPointer) throws -> PaymentInfo { + return try FfiConverterTypePaymentInfo.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInfo_lower(_ value: PaymentInfo) -> UnsafeMutableRawPointer { + return FfiConverterTypePaymentInfo.lower(value) +} + + + + + + +public protocol PaymentInstructionsProtocol: AnyObject, Sendable { + + /** + * Check if these are configurable amount payment instructions + */ + func isConfigurableAmount() -> Bool + + /** + * Check if these are fixed amount payment instructions + */ + func isFixedAmount() -> Bool + + /** + * Get the lightning payment amount for fixed amount instructions + * + * Returns the specific amount required for lightning payments. + * Only applies to fixed amount payment instructions. + */ + func lnPaymentAmount() -> Amount? + + /** + * Get the maximum amount for payment instructions + * + * For configurable amount instructions, returns the maximum allowed amount. + * For fixed amount instructions, returns the fixed payment amount. + */ + func maxAmount() -> Amount? + + /** + * Get the minimum amount for configurable amount payment instructions + * + * Returns the minimum amount the recipient will accept, if specified. + * Only applies to configurable amount payment instructions. + */ + func minAmount() -> Amount? + + /** + * Get the on-chain payment amount for fixed amount instructions + * + * Returns the specific amount required for on-chain payments. + * Only applies to fixed amount payment instructions. + */ + func onchainPaymentAmount() -> Amount? + + /** + * Get the proof-of-payment callback URI if available + */ + func popCallback() -> String? + + /** + * Get the recipient-provided description of the payment instructions + */ + func recipientDescription() -> String? + +} +open class PaymentInstructions: PaymentInstructionsProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_paymentinstructions(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_paymentinstructions(pointer, $0) } + } + + + + + /** + * Check if these are configurable amount payment instructions + */ +open func isConfigurableAmount() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_is_configurable_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Check if these are fixed amount payment instructions + */ +open func isFixedAmount() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_is_fixed_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the lightning payment amount for fixed amount instructions + * + * Returns the specific amount required for lightning payments. + * Only applies to fixed amount payment instructions. + */ +open func lnPaymentAmount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_ln_payment_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the maximum amount for payment instructions + * + * For configurable amount instructions, returns the maximum allowed amount. + * For fixed amount instructions, returns the fixed payment amount. + */ +open func maxAmount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_max_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the minimum amount for configurable amount payment instructions + * + * Returns the minimum amount the recipient will accept, if specified. + * Only applies to configurable amount payment instructions. + */ +open func minAmount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_min_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the on-chain payment amount for fixed amount instructions + * + * Returns the specific amount required for on-chain payments. + * Only applies to fixed amount payment instructions. + */ +open func onchainPaymentAmount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_onchain_payment_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the proof-of-payment callback URI if available + */ +open func popCallback() -> String? { + return try! FfiConverterOptionString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_pop_callback(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Get the recipient-provided description of the payment instructions + */ +open func recipientDescription() -> String? { + return try! FfiConverterOptionString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_paymentinstructions_recipient_description(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePaymentInstructions: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = PaymentInstructions + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> PaymentInstructions { + return PaymentInstructions(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: PaymentInstructions) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentInstructions { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: PaymentInstructions, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInstructions_lift(_ pointer: UnsafeMutableRawPointer) throws -> PaymentInstructions { + return try FfiConverterTypePaymentInstructions.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInstructions_lower(_ value: PaymentInstructions) -> UnsafeMutableRawPointer { + return FfiConverterTypePaymentInstructions.lower(value) +} + + + + + + +/** + * Represents a single-use Bitcoin URI for receiving payments. + */ +public protocol SingleUseReceiveUriProtocol: AnyObject, Sendable { + + func address() -> String? + + func amount() -> Amount? + + func bip21Uri() -> String + + func fromTrusted() -> Bool + + func invoice() -> String + + func paymentHash() -> String + +} +/** + * Represents a single-use Bitcoin URI for receiving payments. + */ +open class SingleUseReceiveUri: SingleUseReceiveUriProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_singleusereceiveuri(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_singleusereceiveuri(pointer, $0) } + } + + + + +open func address() -> String? { + return try! FfiConverterOptionString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_address(self.uniffiClonePointer(),$0 + ) +}) +} + +open func amount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_amount(self.uniffiClonePointer(),$0 + ) +}) +} + +open func bip21Uri() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_bip21_uri(self.uniffiClonePointer(),$0 + ) +}) +} + +open func fromTrusted() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_from_trusted(self.uniffiClonePointer(),$0 + ) +}) +} + +open func invoice() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_invoice(self.uniffiClonePointer(),$0 + ) +}) +} + +open func paymentHash() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_singleusereceiveuri_payment_hash(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeSingleUseReceiveUri: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = SingleUseReceiveUri + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SingleUseReceiveUri { + return SingleUseReceiveUri(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: SingleUseReceiveUri) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SingleUseReceiveUri { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: SingleUseReceiveUri, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSingleUseReceiveUri_lift(_ pointer: UnsafeMutableRawPointer) throws -> SingleUseReceiveUri { + return try FfiConverterTypeSingleUseReceiveUri.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSingleUseReceiveUri_lower(_ value: SingleUseReceiveUri) -> UnsafeMutableRawPointer { + return FfiConverterTypeSingleUseReceiveUri.lower(value) +} + + + + + + +public protocol SparkWalletConfigProtocol: AnyObject, Sendable { + +} +open class SparkWalletConfig: SparkWalletConfigProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_sparkwalletconfig(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_sparkwalletconfig(pointer, $0) } + } + + +public static func defaultConfig() -> SparkWalletConfig { + return try! FfiConverterTypeSparkWalletConfig_lift(try! rustCall() { + uniffi_orange_sdk_fn_constructor_sparkwalletconfig_default_config($0 + ) +}) +} + + + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeSparkWalletConfig: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = SparkWalletConfig + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SparkWalletConfig { + return SparkWalletConfig(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: SparkWalletConfig) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SparkWalletConfig { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: SparkWalletConfig, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSparkWalletConfig_lift(_ pointer: UnsafeMutableRawPointer) throws -> SparkWalletConfig { + return try FfiConverterTypeSparkWalletConfig.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSparkWalletConfig_lower(_ value: SparkWalletConfig) -> UnsafeMutableRawPointer { + return FfiConverterTypeSparkWalletConfig.lower(value) +} + + + + + + +/** + * A transaction is a record of a payment made or received. It contains information about the + * transaction, such as the amount, fee, and status. It is used to track the state of a payment + * and to provide information about the payment to the user. + */ +public protocol TransactionProtocol: AnyObject, Sendable { + + /** + * The amount of the payment + * + * None if the payment is not yet completed + */ + func amount() -> Amount? + + /** + * The fee paid for the payment + * + * None if the payment is not yet completed + */ + func fee() -> Amount? + + func id() -> PaymentId + + func outbound() -> Bool + + /** + * The type of payment being made + */ + func paymentType() -> PaymentType + + /** + * The timestamp of the transaction + */ + func secsSinceEpoch() -> UInt64 + + func status() -> TxStatus + +} +/** + * A transaction is a record of a payment made or received. It contains information about the + * transaction, such as the amount, fee, and status. It is used to track the state of a payment + * and to provide information about the payment to the user. + */ +open class Transaction: TransactionProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_transaction(self.pointer, $0) } + } + // No primary constructor declared for this class. + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_transaction(pointer, $0) } + } + + + + + /** + * The amount of the payment + * + * None if the payment is not yet completed + */ +open func amount() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_amount(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The fee paid for the payment + * + * None if the payment is not yet completed + */ +open func fee() -> Amount? { + return try! FfiConverterOptionTypeAmount.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_fee(self.uniffiClonePointer(),$0 + ) +}) +} + +open func id() -> PaymentId { + return try! FfiConverterTypePaymentId_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_id(self.uniffiClonePointer(),$0 + ) +}) +} + +open func outbound() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_outbound(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The type of payment being made + */ +open func paymentType() -> PaymentType { + return try! FfiConverterTypePaymentType_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_payment_type(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * The timestamp of the transaction + */ +open func secsSinceEpoch() -> UInt64 { + return try! FfiConverterUInt64.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_secs_since_epoch(self.uniffiClonePointer(),$0 + ) +}) +} + +open func status() -> TxStatus { + return try! FfiConverterTypeTxStatus_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_transaction_status(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeTransaction: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Transaction + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Transaction { + return Transaction(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Transaction) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Transaction { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Transaction, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTransaction_lift(_ pointer: UnsafeMutableRawPointer) throws -> Transaction { + return try FfiConverterTypeTransaction.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTransaction_lower(_ value: Transaction) -> UnsafeMutableRawPointer { + return FfiConverterTypeTransaction.lower(value) +} + + + + + + +/** + * Represents the balances of the wallet, including available and pending balances. + */ +public protocol TunablesProtocol: AnyObject, Sendable { + +} +/** + * Represents the balances of the wallet, including available and pending balances. + */ +open class Tunables: TunablesProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_tunables(self.pointer, $0) } + } +public convenience init(trustedBalanceLimit: Amount, rebalanceMin: Amount, onchainReceiveThreshold: Amount, enableAmountlessReceiveOnChain: Bool) { + let pointer = + try! rustCall() { + uniffi_orange_sdk_fn_constructor_tunables_new( + FfiConverterTypeAmount_lower(trustedBalanceLimit), + FfiConverterTypeAmount_lower(rebalanceMin), + FfiConverterTypeAmount_lower(onchainReceiveThreshold), + FfiConverterBool.lower(enableAmountlessReceiveOnChain),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_tunables(pointer, $0) } + } + + +public static func `default`() -> Tunables { + return try! FfiConverterTypeTunables_lift(try! rustCall() { + uniffi_orange_sdk_fn_constructor_tunables_default($0 + ) +}) +} + + + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeTunables: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Tunables + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Tunables { + return Tunables(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Tunables) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Tunables { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Tunables, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTunables_lift(_ pointer: UnsafeMutableRawPointer) throws -> Tunables { + return try FfiConverterTypeTunables.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTunables_lower(_ value: Tunables) -> UnsafeMutableRawPointer { + return FfiConverterTypeTunables.lower(value) +} + + + + + + +/** + * Configuration for a Versioned Storage Service (VSS). + */ +public protocol VssConfigProtocol: AnyObject, Sendable { + +} +/** + * Configuration for a Versioned Storage Service (VSS). + */ +open class VssConfig: VssConfigProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_vssconfig(self.pointer, $0) } + } +public convenience init(vssUrl: String, storeId: String, headers: VssAuth) { + let pointer = + try! rustCall() { + uniffi_orange_sdk_fn_constructor_vssconfig_new( + FfiConverterString.lower(vssUrl), + FfiConverterString.lower(storeId), + FfiConverterTypeVssAuth_lower(headers),$0 + ) +} + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_vssconfig(pointer, $0) } + } + + + + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeVssConfig: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = VssConfig + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> VssConfig { + return VssConfig(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: VssConfig) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VssConfig { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: VssConfig, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeVssConfig_lift(_ pointer: UnsafeMutableRawPointer) throws -> VssConfig { + return try FfiConverterTypeVssConfig.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeVssConfig_lower(_ value: VssConfig) -> UnsafeMutableRawPointer { + return FfiConverterTypeVssConfig.lower(value) +} + + + + + + +public protocol WalletProtocol: AnyObject, Sendable { + + /** + * List our current channels + */ + func closeChannels() async throws + + /** + * Estimates the fees required to pay using the provided PaymentInfo + * + * This will estimate fees for the optimal payment method based on the current wallet state, + * including whether the payment would be routed through the trusted wallet or lightning wallet. + */ + func estimateFee(paymentInfo: PaymentInfo) async throws -> Amount + + /** + * Confirm the last retrieved event handled. Returns true if successful. + * + * **Note:** This **MUST** be called after each event has been handled. + */ + func eventHandled() -> Bool + + func getBalance() async throws -> Balances + + /** + * Gets the lightning address for this wallet, if one is set. + */ + func getLightningAddress() async throws -> String? + + /** + * Whether the wallet should automatically rebalance from trusted/onchain to lightning. + */ + func getRebalanceEnabled() async -> Bool + + func getSingleUseReceiveUri(amount: Amount?) async throws -> SingleUseReceiveUri + + /** + * Authenticates the user via [LNURL-auth] for the given LNURL string. + * + * [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md + * Returns the wallet's configured tunables. + */ + func getTunables() -> Tunables + + func isConnectedToLsp() -> Bool + + /** + * List our current channels + */ + func listChannels() -> [ChannelDetails] + + func listTransactions() async throws -> [Transaction] + + /** + * Returns the next event in the event queue, if currently available. + * + * Will return `Some(...)` if an event is available and `None` otherwise. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ + func nextEvent() -> Event? + + /** + * Returns the next event in the event queue. + * + * Will asynchronously poll the event queue until the next event is ready. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ + func nextEventAsync() async -> Event + + func nodeId() -> String + + /** + * Parse payment instructions from a string (e.g., BOLT 11 invoice, BOLT 12 offer, on-chain address) + * + * This method supports parsing various payment instruction formats including: + * - Lightning BOLT 11 invoices + * - Lightning BOLT 12 offers + * - On-chain Bitcoin addresses + * - BIP 21 URIs + */ + func parsePaymentInstructions(instructions: String) async throws -> PaymentInstructions + + /** + * Initiate a payment using the provided PaymentInfo + * + * This will attempt to pay from the trusted wallet if possible, otherwise it will pay + * from the lightning wallet. The function will also initiate automatic rebalancing + * from trusted to lightning wallet based on the resulting balance and configured tunables. + * + * Returns once the payment is pending. This does not mean the payment has completed - + * it may still fail. Use event handlers or transaction listing to monitor payment status. + */ + func pay(paymentInfo: PaymentInfo) async throws -> PaymentId + + /** + * Attempts to register the lightning address for this wallet. + */ + func registerLightningAddress(name: String) async throws + + /** + * Sets whether the wallet should automatically rebalance from trusted/onchain to lightning. + */ + func setRebalanceEnabled(value: Bool) async + + func stop() async + + /** + * Returns the next event in the event queue. + * + * Will block the current thread until the next event is available. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ + func waitNextEvent() -> Event + +} +open class Wallet: WalletProtocol, @unchecked Sendable { + fileprivate let pointer: UnsafeMutableRawPointer! + + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public struct NoPointer { + public init() {} + } + + // TODO: We'd like this to be `private` but for Swifty reasons, + // we can't implement `FfiConverter` without making this `required` and we can't + // make it `required` without making it `public`. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { + self.pointer = pointer + } + + // This constructor can be used to instantiate a fake object. + // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject]. + // + // - Warning: + // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash. +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public init(noPointer: NoPointer) { + self.pointer = nil + } + +#if swift(>=5.8) + @_documentation(visibility: private) +#endif + public func uniffiClonePointer() -> UnsafeMutableRawPointer { + return try! rustCall { uniffi_orange_sdk_fn_clone_wallet(self.pointer, $0) } + } +public convenience init(config: WalletConfig)async throws { + let pointer = + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_constructor_wallet_new(FfiConverterTypeWalletConfig_lower(config) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_pointer, + completeFunc: ffi_orange_sdk_rust_future_complete_pointer, + freeFunc: ffi_orange_sdk_rust_future_free_pointer, + liftFunc: FfiConverterTypeWallet_lift, + errorHandler: FfiConverterTypeInitFailure_lift + ) + + .uniffiClonePointer() + self.init(unsafeFromRawPointer: pointer) +} + + deinit { + guard let pointer = pointer else { + return + } + + try! rustCall { uniffi_orange_sdk_fn_free_wallet(pointer, $0) } + } + + + + + /** + * List our current channels + */ +open func closeChannels()async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_close_channels( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_void, + completeFunc: ffi_orange_sdk_rust_future_complete_void, + freeFunc: ffi_orange_sdk_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Estimates the fees required to pay using the provided PaymentInfo + * + * This will estimate fees for the optimal payment method based on the current wallet state, + * including whether the payment would be routed through the trusted wallet or lightning wallet. + */ +open func estimateFee(paymentInfo: PaymentInfo)async throws -> Amount { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_estimate_fee( + self.uniffiClonePointer(), + FfiConverterTypePaymentInfo_lower(paymentInfo) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_pointer, + completeFunc: ffi_orange_sdk_rust_future_complete_pointer, + freeFunc: ffi_orange_sdk_rust_future_free_pointer, + liftFunc: FfiConverterTypeAmount_lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Confirm the last retrieved event handled. Returns true if successful. + * + * **Note:** This **MUST** be called after each event has been handled. + */ +open func eventHandled() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_event_handled(self.uniffiClonePointer(),$0 + ) +}) +} + +open func getBalance()async throws -> Balances { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_get_balance( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_pointer, + completeFunc: ffi_orange_sdk_rust_future_complete_pointer, + freeFunc: ffi_orange_sdk_rust_future_free_pointer, + liftFunc: FfiConverterTypeBalances_lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Gets the lightning address for this wallet, if one is set. + */ +open func getLightningAddress()async throws -> String? { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_get_lightning_address( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_rust_buffer, + completeFunc: ffi_orange_sdk_rust_future_complete_rust_buffer, + freeFunc: ffi_orange_sdk_rust_future_free_rust_buffer, + liftFunc: FfiConverterOptionString.lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Whether the wallet should automatically rebalance from trusted/onchain to lightning. + */ +open func getRebalanceEnabled()async -> Bool { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_get_rebalance_enabled( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_i8, + completeFunc: ffi_orange_sdk_rust_future_complete_i8, + freeFunc: ffi_orange_sdk_rust_future_free_i8, + liftFunc: FfiConverterBool.lift, + errorHandler: nil + + ) +} + +open func getSingleUseReceiveUri(amount: Amount?)async throws -> SingleUseReceiveUri { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_get_single_use_receive_uri( + self.uniffiClonePointer(), + FfiConverterOptionTypeAmount.lower(amount) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_pointer, + completeFunc: ffi_orange_sdk_rust_future_complete_pointer, + freeFunc: ffi_orange_sdk_rust_future_free_pointer, + liftFunc: FfiConverterTypeSingleUseReceiveUri_lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Authenticates the user via [LNURL-auth] for the given LNURL string. + * + * [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md + * Returns the wallet's configured tunables. + */ +open func getTunables() -> Tunables { + return try! FfiConverterTypeTunables_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_get_tunables(self.uniffiClonePointer(),$0 + ) +}) +} + +open func isConnectedToLsp() -> Bool { + return try! FfiConverterBool.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_is_connected_to_lsp(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * List our current channels + */ +open func listChannels() -> [ChannelDetails] { + return try! FfiConverterSequenceTypeChannelDetails.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_list_channels(self.uniffiClonePointer(),$0 + ) +}) +} + +open func listTransactions()async throws -> [Transaction] { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_list_transactions( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_rust_buffer, + completeFunc: ffi_orange_sdk_rust_future_complete_rust_buffer, + freeFunc: ffi_orange_sdk_rust_future_free_rust_buffer, + liftFunc: FfiConverterSequenceTypeTransaction.lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Returns the next event in the event queue, if currently available. + * + * Will return `Some(...)` if an event is available and `None` otherwise. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ +open func nextEvent() -> Event? { + return try! FfiConverterOptionTypeEvent.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_next_event(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Returns the next event in the event queue. + * + * Will asynchronously poll the event queue until the next event is ready. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ +open func nextEventAsync()async -> Event { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_next_event_async( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_rust_buffer, + completeFunc: ffi_orange_sdk_rust_future_complete_rust_buffer, + freeFunc: ffi_orange_sdk_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypeEvent_lift, + errorHandler: nil + + ) +} + +open func nodeId() -> String { + return try! FfiConverterString.lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_node_id(self.uniffiClonePointer(),$0 + ) +}) +} + + /** + * Parse payment instructions from a string (e.g., BOLT 11 invoice, BOLT 12 offer, on-chain address) + * + * This method supports parsing various payment instruction formats including: + * - Lightning BOLT 11 invoices + * - Lightning BOLT 12 offers + * - On-chain Bitcoin addresses + * - BIP 21 URIs + */ +open func parsePaymentInstructions(instructions: String)async throws -> PaymentInstructions { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_parse_payment_instructions( + self.uniffiClonePointer(), + FfiConverterString.lower(instructions) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_pointer, + completeFunc: ffi_orange_sdk_rust_future_complete_pointer, + freeFunc: ffi_orange_sdk_rust_future_free_pointer, + liftFunc: FfiConverterTypePaymentInstructions_lift, + errorHandler: FfiConverterTypeParseError_lift + ) +} + + /** + * Initiate a payment using the provided PaymentInfo + * + * This will attempt to pay from the trusted wallet if possible, otherwise it will pay + * from the lightning wallet. The function will also initiate automatic rebalancing + * from trusted to lightning wallet based on the resulting balance and configured tunables. + * + * Returns once the payment is pending. This does not mean the payment has completed - + * it may still fail. Use event handlers or transaction listing to monitor payment status. + */ +open func pay(paymentInfo: PaymentInfo)async throws -> PaymentId { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_pay( + self.uniffiClonePointer(), + FfiConverterTypePaymentInfo_lower(paymentInfo) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_rust_buffer, + completeFunc: ffi_orange_sdk_rust_future_complete_rust_buffer, + freeFunc: ffi_orange_sdk_rust_future_free_rust_buffer, + liftFunc: FfiConverterTypePaymentId_lift, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Attempts to register the lightning address for this wallet. + */ +open func registerLightningAddress(name: String)async throws { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_register_lightning_address( + self.uniffiClonePointer(), + FfiConverterString.lower(name) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_void, + completeFunc: ffi_orange_sdk_rust_future_complete_void, + freeFunc: ffi_orange_sdk_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: FfiConverterTypeWalletError_lift + ) +} + + /** + * Sets whether the wallet should automatically rebalance from trusted/onchain to lightning. + */ +open func setRebalanceEnabled(value: Bool)async { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_set_rebalance_enabled( + self.uniffiClonePointer(), + FfiConverterBool.lower(value) + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_void, + completeFunc: ffi_orange_sdk_rust_future_complete_void, + freeFunc: ffi_orange_sdk_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: nil + + ) +} + +open func stop()async { + return + try! await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_orange_sdk_fn_method_wallet_stop( + self.uniffiClonePointer() + + ) + }, + pollFunc: ffi_orange_sdk_rust_future_poll_void, + completeFunc: ffi_orange_sdk_rust_future_complete_void, + freeFunc: ffi_orange_sdk_rust_future_free_void, + liftFunc: { $0 }, + errorHandler: nil + + ) +} + + /** + * Returns the next event in the event queue. + * + * Will block the current thread until the next event is available. + * + * **Note:** this will always return the same event until handling is confirmed via [`crate::Wallet::event_handled`]. + * + * **Caution:** Users must handle events as quickly as possible to prevent a large event backlog, + * which can increase the memory footprint of [`crate::Wallet`]. + */ +open func waitNextEvent() -> Event { + return try! FfiConverterTypeEvent_lift(try! rustCall() { + uniffi_orange_sdk_fn_method_wallet_wait_next_event(self.uniffiClonePointer(),$0 + ) +}) +} + + +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeWallet: FfiConverter { + + typealias FfiType = UnsafeMutableRawPointer + typealias SwiftType = Wallet + + public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet { + return Wallet(unsafeFromRawPointer: pointer) + } + + public static func lower(_ value: Wallet) -> UnsafeMutableRawPointer { + return value.uniffiClonePointer() + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Wallet { + let v: UInt64 = try readInt(&buf) + // The Rust code won't compile if a pointer won't fit in a UInt64. + // We have to go via `UInt` because that's the thing that's the size of a pointer. + let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v)) + if (ptr == nil) { + throw UniffiInternalError.unexpectedNullPointer + } + return try lift(ptr!) + } + + public static func write(_ value: Wallet, into buf: inout [UInt8]) { + // This fiddling is because `Int` is the thing that's the same size as a pointer. + // The Rust code won't compile if a pointer won't fit in a `UInt64`. + writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value))))) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWallet_lift(_ pointer: UnsafeMutableRawPointer) throws -> Wallet { + return try FfiConverterTypeWallet.lift(pointer) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWallet_lower(_ value: Wallet) -> UnsafeMutableRawPointer { + return FfiConverterTypeWallet.lower(value) +} + + + + +/** + * Configuration for initializing the wallet. + */ +public struct WalletConfig { + /** + * Configuration for wallet storage. + */ + public var storageConfig: StorageConfig + /** + * Location of the wallet's log file. + */ + public var logFile: String + /** + * Configuration for the blockchain data source. + */ + public var chainSource: ChainSource + /** + * Lightning Service Provider (LSP) configuration. + * The address to connect to the LSP, the LSP node id, and an optional auth token. + */ + public var lspAddress: String + public var lspNodeId: String + public var lspToken: String? + /** + * URL to download a scorer from. This is for the lightning node to get its route + * scorer from a remote server instead of having to probe and find optimal routes + * locally. + */ + public var scorerUrl: String? + /** + * URL to Rapid Gossip Sync server to get gossip data from. + */ + public var rgsUrl: String? + /** + * The Bitcoin network the wallet operates on. + */ + public var network: Network + /** + * The seed used for wallet generation. + */ + public var seed: Seed + /** + * Configuration parameters for when the wallet decides to use the lightning or trusted wallet. + */ + public var tunables: Tunables + /** + * Extra configuration specific to the trusted wallet implementation. + */ + public var extraConfig: ExtraConfig + + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init( + /** + * Configuration for wallet storage. + */storageConfig: StorageConfig, + /** + * Location of the wallet's log file. + */logFile: String, + /** + * Configuration for the blockchain data source. + */chainSource: ChainSource, + /** + * Lightning Service Provider (LSP) configuration. + * The address to connect to the LSP, the LSP node id, and an optional auth token. + */lspAddress: String, lspNodeId: String, lspToken: String?, + /** + * URL to download a scorer from. This is for the lightning node to get its route + * scorer from a remote server instead of having to probe and find optimal routes + * locally. + */scorerUrl: String?, + /** + * URL to Rapid Gossip Sync server to get gossip data from. + */rgsUrl: String?, + /** + * The Bitcoin network the wallet operates on. + */network: Network, + /** + * The seed used for wallet generation. + */seed: Seed, + /** + * Configuration parameters for when the wallet decides to use the lightning or trusted wallet. + */tunables: Tunables, + /** + * Extra configuration specific to the trusted wallet implementation. + */extraConfig: ExtraConfig) { + self.storageConfig = storageConfig + self.logFile = logFile + self.chainSource = chainSource + self.lspAddress = lspAddress + self.lspNodeId = lspNodeId + self.lspToken = lspToken + self.scorerUrl = scorerUrl + self.rgsUrl = rgsUrl + self.network = network + self.seed = seed + self.tunables = tunables + self.extraConfig = extraConfig + } +} + +#if compiler(>=6) +extension WalletConfig: Sendable {} +#endif + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeWalletConfig: FfiConverterRustBuffer { + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WalletConfig { + return + try WalletConfig( + storageConfig: FfiConverterTypeStorageConfig.read(from: &buf), + logFile: FfiConverterString.read(from: &buf), + chainSource: FfiConverterTypeChainSource.read(from: &buf), + lspAddress: FfiConverterString.read(from: &buf), + lspNodeId: FfiConverterString.read(from: &buf), + lspToken: FfiConverterOptionString.read(from: &buf), + scorerUrl: FfiConverterOptionString.read(from: &buf), + rgsUrl: FfiConverterOptionString.read(from: &buf), + network: FfiConverterTypeNetwork.read(from: &buf), + seed: FfiConverterTypeSeed.read(from: &buf), + tunables: FfiConverterTypeTunables.read(from: &buf), + extraConfig: FfiConverterTypeExtraConfig.read(from: &buf) + ) + } + + public static func write(_ value: WalletConfig, into buf: inout [UInt8]) { + FfiConverterTypeStorageConfig.write(value.storageConfig, into: &buf) + FfiConverterString.write(value.logFile, into: &buf) + FfiConverterTypeChainSource.write(value.chainSource, into: &buf) + FfiConverterString.write(value.lspAddress, into: &buf) + FfiConverterString.write(value.lspNodeId, into: &buf) + FfiConverterOptionString.write(value.lspToken, into: &buf) + FfiConverterOptionString.write(value.scorerUrl, into: &buf) + FfiConverterOptionString.write(value.rgsUrl, into: &buf) + FfiConverterTypeNetwork.write(value.network, into: &buf) + FfiConverterTypeSeed.write(value.seed, into: &buf) + FfiConverterTypeTunables.write(value.tunables, into: &buf) + FfiConverterTypeExtraConfig.write(value.extraConfig, into: &buf) + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWalletConfig_lift(_ buf: RustBuffer) throws -> WalletConfig { + return try FfiConverterTypeWalletConfig.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWalletConfig_lower(_ value: WalletConfig) -> RustBuffer { + return FfiConverterTypeWalletConfig.lower(value) +} + + +public enum AmountError: Swift.Error { + + + + case FractionalAmountOfSats(UInt64 + ) + case MoreThanTwentyOneMillionBitcoin(UInt64 + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeAmountError: FfiConverterRustBuffer { + typealias SwiftType = AmountError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> AmountError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .FractionalAmountOfSats( + try FfiConverterUInt64.read(from: &buf) + ) + case 2: return .MoreThanTwentyOneMillionBitcoin( + try FfiConverterUInt64.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: AmountError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .FractionalAmountOfSats(v1): + writeInt(&buf, Int32(1)) + FfiConverterUInt64.write(v1, into: &buf) + + + case let .MoreThanTwentyOneMillionBitcoin(v1): + writeInt(&buf, Int32(2)) + FfiConverterUInt64.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeAmountError_lift(_ buf: RustBuffer) throws -> AmountError { + return try FfiConverterTypeAmountError.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeAmountError_lower(_ value: AmountError) -> RustBuffer { + return FfiConverterTypeAmountError.lower(value) +} + + +extension AmountError: Equatable, Hashable {} + + + + +extension AmountError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * Configuration for the blockchain data source. + */ + +public enum ChainSource { + + /** + * Electrum server configuration. + */ + case electrum(String + ) + /** + * Esplora server configuration. + */ + case esplora( + /** + * Esplora url + */url: String, + /** + * Optional for Basic authentication for the Esplora server. + */username: String?, + /** + * Optional for Basic authentication for the Esplora server. + */password: String? + ) + /** + * Bitcoind RPC configuration. + */ + case bitcoindRpc( + /** + * The host of the Bitcoind rpc server (e.g. 127.0.0.1). + */host: String, + /** + * The port of the Bitcoind rpc server (e.g. 8332). + */port: UInt16, + /** + * The username for the Bitcoind rpc server. + */user: String, + /** + * The password for the Bitcoind rpc server. + */password: String + ) +} + + +#if compiler(>=6) +extension ChainSource: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeChainSource: FfiConverterRustBuffer { + typealias SwiftType = ChainSource + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChainSource { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .electrum(try FfiConverterString.read(from: &buf) + ) + + case 2: return .esplora(url: try FfiConverterString.read(from: &buf), username: try FfiConverterOptionString.read(from: &buf), password: try FfiConverterOptionString.read(from: &buf) + ) + + case 3: return .bitcoindRpc(host: try FfiConverterString.read(from: &buf), port: try FfiConverterUInt16.read(from: &buf), user: try FfiConverterString.read(from: &buf), password: try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: ChainSource, into buf: inout [UInt8]) { + switch value { + + + case let .electrum(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .esplora(url,username,password): + writeInt(&buf, Int32(2)) + FfiConverterString.write(url, into: &buf) + FfiConverterOptionString.write(username, into: &buf) + FfiConverterOptionString.write(password, into: &buf) + + + case let .bitcoindRpc(host,port,user,password): + writeInt(&buf, Int32(3)) + FfiConverterString.write(host, into: &buf) + FfiConverterUInt16.write(port, into: &buf) + FfiConverterString.write(user, into: &buf) + FfiConverterString.write(password, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeChainSource_lift(_ buf: RustBuffer) throws -> ChainSource { + return try FfiConverterTypeChainSource.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeChainSource_lower(_ value: ChainSource) -> RustBuffer { + return FfiConverterTypeChainSource.lower(value) +} + + +extension ChainSource: Equatable, Hashable {} + + + + + + + +public enum ConfigError: Swift.Error { + + + + case InvalidEntropySize(UInt32 + ) + case InvalidMnemonic + case InvalidLspAddress(String + ) + case InvalidLspNodeId(String + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeConfigError: FfiConverterRustBuffer { + typealias SwiftType = ConfigError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ConfigError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .InvalidEntropySize( + try FfiConverterUInt32.read(from: &buf) + ) + case 2: return .InvalidMnemonic + case 3: return .InvalidLspAddress( + try FfiConverterString.read(from: &buf) + ) + case 4: return .InvalidLspNodeId( + try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: ConfigError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .InvalidEntropySize(v1): + writeInt(&buf, Int32(1)) + FfiConverterUInt32.write(v1, into: &buf) + + + case .InvalidMnemonic: + writeInt(&buf, Int32(2)) + + + case let .InvalidLspAddress(v1): + writeInt(&buf, Int32(3)) + FfiConverterString.write(v1, into: &buf) + + + case let .InvalidLspNodeId(v1): + writeInt(&buf, Int32(4)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeConfigError_lift(_ buf: RustBuffer) throws -> ConfigError { + return try FfiConverterTypeConfigError.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeConfigError_lower(_ value: ConfigError) -> RustBuffer { + return FfiConverterTypeConfigError.lower(value) +} + + +extension ConfigError: Equatable, Hashable {} + + + + +extension ConfigError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum CurrencyUnit { + + case sat + case msat + case usd + case eur + case auth + case custom(String + ) +} + + +#if compiler(>=6) +extension CurrencyUnit: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeCurrencyUnit: FfiConverterRustBuffer { + typealias SwiftType = CurrencyUnit + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> CurrencyUnit { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .sat + + case 2: return .msat + + case 3: return .usd + + case 4: return .eur + + case 5: return .auth + + case 6: return .custom(try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: CurrencyUnit, into buf: inout [UInt8]) { + switch value { + + + case .sat: + writeInt(&buf, Int32(1)) + + + case .msat: + writeInt(&buf, Int32(2)) + + + case .usd: + writeInt(&buf, Int32(3)) + + + case .eur: + writeInt(&buf, Int32(4)) + + + case .auth: + writeInt(&buf, Int32(5)) + + + case let .custom(v1): + writeInt(&buf, Int32(6)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeCurrencyUnit_lift(_ buf: RustBuffer) throws -> CurrencyUnit { + return try FfiConverterTypeCurrencyUnit.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeCurrencyUnit_lower(_ value: CurrencyUnit) -> RustBuffer { + return FfiConverterTypeCurrencyUnit.lower(value) +} + + +extension CurrencyUnit: Equatable, Hashable {} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * An event emitted by [`Wallet`], which should be handled by the user. + * + * [`Wallet`]: [`crate::Wallet`] + */ + +public enum Event { + + /** + * An outgoing payment was successful. + */ + case paymentSuccessful( + /** + * A local identifier used to track the payment. + */paymentId: PaymentId, + /** + * The hash of the payment. + */paymentHash: Data, + /** + * The preimage to the `payment_hash`. + * + * Note that this serves as a payment receipt. + */paymentPreimage: Data, + /** + * The total fee which was spent at intermediate hops in this payment. + */feePaidMsat: UInt64? + ) + /** + * An outgoing payment has failed. + */ + case paymentFailed( + /** + * A local identifier used to track the payment. + */paymentId: PaymentId, + /** + * The hash of the payment. + * + * This will be `None` if the payment failed before receiving an invoice when paying a + * BOLT12 [`Offer`]. + * + * [`Offer`]: ldk_node::lightning::offers::offer::Offer + */paymentHash: Data?, + /** + * The reason why the payment failed. + * + * Will be `None` if the failure reason is not known. + */reason: String? + ) + /** + * A payment has been received. + */ + case paymentReceived( + /** + * A local identifier used to track the payment. + */paymentId: PaymentId, + /** + * The hash of the payment. + */paymentHash: Data, + /** + * The value, in msats, that has been received. + */amountMsat: UInt64, + /** + * Custom TLV records received on the payment + */customRecords: [Data], + /** + * The value, in msats, that was skimmed off of this payment as an extra fee taken by LSP. + * Typically, this is only present for payments that result in opening a channel. + */lspFeeMsats: UInt64? + ) + /** + * A payment has been received. + */ + case onchainPaymentReceived( + /** + * A local identifier used to track the payment. + */paymentId: PaymentId, + /** + * The transaction ID. + */txid: Data, + /** + * The value, in sats, that has been received. + */amountSat: UInt64 + ) + /** + * A channel is ready to be used. + */ + case channelOpened( + /** + * The `channel_id` of the channel. + */channelId: Data, + /** + * The `user_channel_id` of the channel. + */userChannelId: Data, + /** + * The `node_id` of the channel counterparty. + */counterpartyNodeId: Data, + /** + * The outpoint of the channel's funding transaction. + */fundingTxo: String + ) + /** + * A channel has been closed. + * + * When a channel is closed, we will disable automatic rebalancing + * so new channels will not be opened until it is explicitly enabled again. + */ + case channelClosed( + /** + * The `channel_id` of the channel. + */channelId: Data, + /** + * The `user_channel_id` of the channel. + */userChannelId: Data, + /** + * The `node_id` of the channel counterparty. + */counterpartyNodeId: Data, + /** + * Why the channel was closed. + * + * Will be `None` if the closure reason is not known. + */reason: String? + ) + /** + * A rebalance from our trusted wallet has been initiated. + */ + case rebalanceInitiated( + /** + * The `payment_id` of the transaction that triggered the rebalance. + */triggerPaymentId: PaymentId, + /** + * The `payment_id` of the rebalance payment sent from the trusted wallet. + */trustedRebalancePaymentId: Data, + /** + * The amount, in msats, of the rebalance payment. + */amountMsat: UInt64 + ) + /** + * A rebalance from our trusted wallet was successful. + */ + case rebalanceSuccessful( + /** + * The `payment_id` of the transaction that triggered the rebalance. + */triggerPaymentId: PaymentId, + /** + * The `payment_id` of the rebalance payment sent from the trusted wallet. + */trustedRebalancePaymentId: Data, + /** + * The `payment_id` of the rebalance payment sent to the LN wallet. + */lnRebalancePaymentId: Data, + /** + * The amount, in msats, of the rebalance payment. + */amountMsat: UInt64, + /** + * The fee paid, in msats, for the rebalance payment. + */feeMsat: UInt64 + ) + /** + * We have initiated a splice and are waiting for it to confirm. + */ + case splicePending( + /** + * The `channel_id` of the channel. + */channelId: Data, + /** + * The `user_channel_id` of the channel. + */userChannelId: Data, + /** + * The `node_id` of the channel counterparty. + */counterpartyNodeId: Data, + /** + * The outpoint of the channel's splice funding transaction. + */newFundingTxo: String + ) +} + + +#if compiler(>=6) +extension Event: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeEvent: FfiConverterRustBuffer { + typealias SwiftType = Event + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Event { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .paymentSuccessful(paymentId: try FfiConverterTypePaymentId.read(from: &buf), paymentHash: try FfiConverterData.read(from: &buf), paymentPreimage: try FfiConverterData.read(from: &buf), feePaidMsat: try FfiConverterOptionUInt64.read(from: &buf) + ) + + case 2: return .paymentFailed(paymentId: try FfiConverterTypePaymentId.read(from: &buf), paymentHash: try FfiConverterOptionData.read(from: &buf), reason: try FfiConverterOptionString.read(from: &buf) + ) + + case 3: return .paymentReceived(paymentId: try FfiConverterTypePaymentId.read(from: &buf), paymentHash: try FfiConverterData.read(from: &buf), amountMsat: try FfiConverterUInt64.read(from: &buf), customRecords: try FfiConverterSequenceData.read(from: &buf), lspFeeMsats: try FfiConverterOptionUInt64.read(from: &buf) + ) + + case 4: return .onchainPaymentReceived(paymentId: try FfiConverterTypePaymentId.read(from: &buf), txid: try FfiConverterData.read(from: &buf), amountSat: try FfiConverterUInt64.read(from: &buf) + ) + + case 5: return .channelOpened(channelId: try FfiConverterData.read(from: &buf), userChannelId: try FfiConverterData.read(from: &buf), counterpartyNodeId: try FfiConverterData.read(from: &buf), fundingTxo: try FfiConverterString.read(from: &buf) + ) + + case 6: return .channelClosed(channelId: try FfiConverterData.read(from: &buf), userChannelId: try FfiConverterData.read(from: &buf), counterpartyNodeId: try FfiConverterData.read(from: &buf), reason: try FfiConverterOptionString.read(from: &buf) + ) + + case 7: return .rebalanceInitiated(triggerPaymentId: try FfiConverterTypePaymentId.read(from: &buf), trustedRebalancePaymentId: try FfiConverterData.read(from: &buf), amountMsat: try FfiConverterUInt64.read(from: &buf) + ) + + case 8: return .rebalanceSuccessful(triggerPaymentId: try FfiConverterTypePaymentId.read(from: &buf), trustedRebalancePaymentId: try FfiConverterData.read(from: &buf), lnRebalancePaymentId: try FfiConverterData.read(from: &buf), amountMsat: try FfiConverterUInt64.read(from: &buf), feeMsat: try FfiConverterUInt64.read(from: &buf) + ) + + case 9: return .splicePending(channelId: try FfiConverterData.read(from: &buf), userChannelId: try FfiConverterData.read(from: &buf), counterpartyNodeId: try FfiConverterData.read(from: &buf), newFundingTxo: try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: Event, into buf: inout [UInt8]) { + switch value { + + + case let .paymentSuccessful(paymentId,paymentHash,paymentPreimage,feePaidMsat): + writeInt(&buf, Int32(1)) + FfiConverterTypePaymentId.write(paymentId, into: &buf) + FfiConverterData.write(paymentHash, into: &buf) + FfiConverterData.write(paymentPreimage, into: &buf) + FfiConverterOptionUInt64.write(feePaidMsat, into: &buf) + + + case let .paymentFailed(paymentId,paymentHash,reason): + writeInt(&buf, Int32(2)) + FfiConverterTypePaymentId.write(paymentId, into: &buf) + FfiConverterOptionData.write(paymentHash, into: &buf) + FfiConverterOptionString.write(reason, into: &buf) + + + case let .paymentReceived(paymentId,paymentHash,amountMsat,customRecords,lspFeeMsats): + writeInt(&buf, Int32(3)) + FfiConverterTypePaymentId.write(paymentId, into: &buf) + FfiConverterData.write(paymentHash, into: &buf) + FfiConverterUInt64.write(amountMsat, into: &buf) + FfiConverterSequenceData.write(customRecords, into: &buf) + FfiConverterOptionUInt64.write(lspFeeMsats, into: &buf) + + + case let .onchainPaymentReceived(paymentId,txid,amountSat): + writeInt(&buf, Int32(4)) + FfiConverterTypePaymentId.write(paymentId, into: &buf) + FfiConverterData.write(txid, into: &buf) + FfiConverterUInt64.write(amountSat, into: &buf) + + + case let .channelOpened(channelId,userChannelId,counterpartyNodeId,fundingTxo): + writeInt(&buf, Int32(5)) + FfiConverterData.write(channelId, into: &buf) + FfiConverterData.write(userChannelId, into: &buf) + FfiConverterData.write(counterpartyNodeId, into: &buf) + FfiConverterString.write(fundingTxo, into: &buf) + + + case let .channelClosed(channelId,userChannelId,counterpartyNodeId,reason): + writeInt(&buf, Int32(6)) + FfiConverterData.write(channelId, into: &buf) + FfiConverterData.write(userChannelId, into: &buf) + FfiConverterData.write(counterpartyNodeId, into: &buf) + FfiConverterOptionString.write(reason, into: &buf) + + + case let .rebalanceInitiated(triggerPaymentId,trustedRebalancePaymentId,amountMsat): + writeInt(&buf, Int32(7)) + FfiConverterTypePaymentId.write(triggerPaymentId, into: &buf) + FfiConverterData.write(trustedRebalancePaymentId, into: &buf) + FfiConverterUInt64.write(amountMsat, into: &buf) + + + case let .rebalanceSuccessful(triggerPaymentId,trustedRebalancePaymentId,lnRebalancePaymentId,amountMsat,feeMsat): + writeInt(&buf, Int32(8)) + FfiConverterTypePaymentId.write(triggerPaymentId, into: &buf) + FfiConverterData.write(trustedRebalancePaymentId, into: &buf) + FfiConverterData.write(lnRebalancePaymentId, into: &buf) + FfiConverterUInt64.write(amountMsat, into: &buf) + FfiConverterUInt64.write(feeMsat, into: &buf) + + + case let .splicePending(channelId,userChannelId,counterpartyNodeId,newFundingTxo): + writeInt(&buf, Int32(9)) + FfiConverterData.write(channelId, into: &buf) + FfiConverterData.write(userChannelId, into: &buf) + FfiConverterData.write(counterpartyNodeId, into: &buf) + FfiConverterString.write(newFundingTxo, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeEvent_lift(_ buf: RustBuffer) throws -> Event { + return try FfiConverterTypeEvent.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeEvent_lower(_ value: Event) -> RustBuffer { + return FfiConverterTypeEvent.lower(value) +} + + +extension Event: Equatable, Hashable {} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * Extra configuration needed for different types of wallets. + */ + +public enum ExtraConfig { + + /** + * Configuration for Spark wallet. + */ + case spark(SparkWalletConfig + ) + /** + * Configuration for Cashu wallet. + */ + case cashu(CashuConfig + ) +} + + +#if compiler(>=6) +extension ExtraConfig: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeExtraConfig: FfiConverterRustBuffer { + typealias SwiftType = ExtraConfig + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ExtraConfig { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .spark(try FfiConverterTypeSparkWalletConfig.read(from: &buf) + ) + + case 2: return .cashu(try FfiConverterTypeCashuConfig.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: ExtraConfig, into buf: inout [UInt8]) { + switch value { + + + case let .spark(v1): + writeInt(&buf, Int32(1)) + FfiConverterTypeSparkWalletConfig.write(v1, into: &buf) + + + case let .cashu(v1): + writeInt(&buf, Int32(2)) + FfiConverterTypeCashuConfig.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeExtraConfig_lift(_ buf: RustBuffer) throws -> ExtraConfig { + return try FfiConverterTypeExtraConfig.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeExtraConfig_lower(_ value: ExtraConfig) -> RustBuffer { + return FfiConverterTypeExtraConfig.lower(value) +} + + + + + + + +/** + * Represents possible failures during wallet initialization. + */ +public enum InitFailure: Swift.Error { + + + + /** + * I/O error during initialization. + */ + case IoError(String + ) + case ConfigError(String + ) + /** + * Failure to build the LDK node. + */ + case LdkNodeBuildFailure(String + ) + /** + * Failure to start the LDK node. + */ + case LdkNodeStartFailure(String + ) + /** + * Failure in the trusted wallet implementation. + */ + case TrustedFailure(String + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeInitFailure: FfiConverterRustBuffer { + typealias SwiftType = InitFailure + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> InitFailure { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .IoError( + try FfiConverterString.read(from: &buf) + ) + case 2: return .ConfigError( + try FfiConverterString.read(from: &buf) + ) + case 3: return .LdkNodeBuildFailure( + try FfiConverterString.read(from: &buf) + ) + case 4: return .LdkNodeStartFailure( + try FfiConverterString.read(from: &buf) + ) + case 5: return .TrustedFailure( + try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: InitFailure, into buf: inout [UInt8]) { + switch value { + + + + + + case let .IoError(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .ConfigError(v1): + writeInt(&buf, Int32(2)) + FfiConverterString.write(v1, into: &buf) + + + case let .LdkNodeBuildFailure(v1): + writeInt(&buf, Int32(3)) + FfiConverterString.write(v1, into: &buf) + + + case let .LdkNodeStartFailure(v1): + writeInt(&buf, Int32(4)) + FfiConverterString.write(v1, into: &buf) + + + case let .TrustedFailure(v1): + writeInt(&buf, Int32(5)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeInitFailure_lift(_ buf: RustBuffer) throws -> InitFailure { + return try FfiConverterTypeInitFailure.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeInitFailure_lower(_ value: InitFailure) -> RustBuffer { + return FfiConverterTypeInitFailure.lower(value) +} + + +extension InitFailure: Equatable, Hashable {} + + + + +extension InitFailure: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum Network { + + case mainnet + case regtest + case testnet + case signet +} + + +#if compiler(>=6) +extension Network: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeNetwork: FfiConverterRustBuffer { + typealias SwiftType = Network + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Network { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .mainnet + + case 2: return .regtest + + case 3: return .testnet + + case 4: return .signet + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: Network, into buf: inout [UInt8]) { + switch value { + + + case .mainnet: + writeInt(&buf, Int32(1)) + + + case .regtest: + writeInt(&buf, Int32(2)) + + + case .testnet: + writeInt(&buf, Int32(3)) + + + case .signet: + writeInt(&buf, Int32(4)) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeNetwork_lift(_ buf: RustBuffer) throws -> Network { + return try FfiConverterTypeNetwork.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeNetwork_lower(_ value: Network) -> RustBuffer { + return FfiConverterTypeNetwork.lower(value) +} + + +extension Network: Equatable, Hashable {} + + + + + + + +public enum ParseError: Swift.Error { + + + + case InvalidBolt11(String + ) + case InvalidBolt12(String + ) + case InvalidOnChain(String + ) + case WrongNetwork + case InconsistentInstructions(String + ) + case InvalidInstructions(String + ) + case UnknownPaymentInstructions + case UnknownRequiredParameter + case HrnResolutionError(String + ) + case InstructionsExpired + case InvalidLnurl(String + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeParseError: FfiConverterRustBuffer { + typealias SwiftType = ParseError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ParseError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .InvalidBolt11( + try FfiConverterString.read(from: &buf) + ) + case 2: return .InvalidBolt12( + try FfiConverterString.read(from: &buf) + ) + case 3: return .InvalidOnChain( + try FfiConverterString.read(from: &buf) + ) + case 4: return .WrongNetwork + case 5: return .InconsistentInstructions( + try FfiConverterString.read(from: &buf) + ) + case 6: return .InvalidInstructions( + try FfiConverterString.read(from: &buf) + ) + case 7: return .UnknownPaymentInstructions + case 8: return .UnknownRequiredParameter + case 9: return .HrnResolutionError( + try FfiConverterString.read(from: &buf) + ) + case 10: return .InstructionsExpired + case 11: return .InvalidLnurl( + try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: ParseError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .InvalidBolt11(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .InvalidBolt12(v1): + writeInt(&buf, Int32(2)) + FfiConverterString.write(v1, into: &buf) + + + case let .InvalidOnChain(v1): + writeInt(&buf, Int32(3)) + FfiConverterString.write(v1, into: &buf) + + + case .WrongNetwork: + writeInt(&buf, Int32(4)) + + + case let .InconsistentInstructions(v1): + writeInt(&buf, Int32(5)) + FfiConverterString.write(v1, into: &buf) + + + case let .InvalidInstructions(v1): + writeInt(&buf, Int32(6)) + FfiConverterString.write(v1, into: &buf) + + + case .UnknownPaymentInstructions: + writeInt(&buf, Int32(7)) + + + case .UnknownRequiredParameter: + writeInt(&buf, Int32(8)) + + + case let .HrnResolutionError(v1): + writeInt(&buf, Int32(9)) + FfiConverterString.write(v1, into: &buf) + + + case .InstructionsExpired: + writeInt(&buf, Int32(10)) + + + case let .InvalidLnurl(v1): + writeInt(&buf, Int32(11)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeParseError_lift(_ buf: RustBuffer) throws -> ParseError { + return try FfiConverterTypeParseError.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeParseError_lower(_ value: ParseError) -> RustBuffer { + return FfiConverterTypeParseError.lower(value) +} + + +extension ParseError: Equatable, Hashable {} + + + + +extension ParseError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * A PaymentId is a unique identifier for a payment. It can be either a Lightning payment or a + * Trusted payment. It is used to track the state of a payment and to provide information about + * the payment to the user. + */ + +public enum PaymentId { + + case lightning(String + ) + case trusted(String + ) +} + + +#if compiler(>=6) +extension PaymentId: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePaymentId: FfiConverterRustBuffer { + typealias SwiftType = PaymentId + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentId { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .lightning(try FfiConverterString.read(from: &buf) + ) + + case 2: return .trusted(try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: PaymentId, into buf: inout [UInt8]) { + switch value { + + + case let .lightning(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .trusted(v1): + writeInt(&buf, Int32(2)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentId_lift(_ buf: RustBuffer) throws -> PaymentId { + return try FfiConverterTypePaymentId.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentId_lower(_ value: PaymentId) -> RustBuffer { + return FfiConverterTypePaymentId.lower(value) +} + + +extension PaymentId: Equatable, Hashable {} + + + + + + + +public enum PaymentInfoBuildError: Swift.Error { + + + + case AmountMismatch(given: Amount, lnAmount: Amount?, onchainAmount: Amount? + ) + case MissingAmount + case AmountOutOfRange(given: Amount, min: Amount?, max: Amount? + ) +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePaymentInfoBuildError: FfiConverterRustBuffer { + typealias SwiftType = PaymentInfoBuildError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentInfoBuildError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .AmountMismatch( + given: try FfiConverterTypeAmount.read(from: &buf), + lnAmount: try FfiConverterOptionTypeAmount.read(from: &buf), + onchainAmount: try FfiConverterOptionTypeAmount.read(from: &buf) + ) + case 2: return .MissingAmount + case 3: return .AmountOutOfRange( + given: try FfiConverterTypeAmount.read(from: &buf), + min: try FfiConverterOptionTypeAmount.read(from: &buf), + max: try FfiConverterOptionTypeAmount.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: PaymentInfoBuildError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .AmountMismatch(given,lnAmount,onchainAmount): + writeInt(&buf, Int32(1)) + FfiConverterTypeAmount.write(given, into: &buf) + FfiConverterOptionTypeAmount.write(lnAmount, into: &buf) + FfiConverterOptionTypeAmount.write(onchainAmount, into: &buf) + + + case .MissingAmount: + writeInt(&buf, Int32(2)) + + + case let .AmountOutOfRange(given,min,max): + writeInt(&buf, Int32(3)) + FfiConverterTypeAmount.write(given, into: &buf) + FfiConverterOptionTypeAmount.write(min, into: &buf) + FfiConverterOptionTypeAmount.write(max, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInfoBuildError_lift(_ buf: RustBuffer) throws -> PaymentInfoBuildError { + return try FfiConverterTypePaymentInfoBuildError.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentInfoBuildError_lower(_ value: PaymentInfoBuildError) -> RustBuffer { + return FfiConverterTypePaymentInfoBuildError.lower(value) +} + + + + +extension PaymentInfoBuildError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * The type of payment being made. This indicates whether the payment is incoming or outgoing, + * and what method is being used (Lightning, on-chain, etc.) + */ + +public enum PaymentType { + + /** + * An outgoing Lightning payment paying a BOLT 12 offer. + */ + case outgoingLightningBolt12( + /** + * The lightning "payment preimage" which represents proof that the payment completed. + * Will be set for any completed payments. + */paymentPreimage: Data? + ) + /** + * An outgoing Lightning payment paying a BOLT 11 invoice. + */ + case outgoingLightningBolt11( + /** + * The lightning "payment preimage" which represents proof that the payment completed. + * Will be set for any completed payments. + */paymentPreimage: Data? + ) + /** + * An outgoing on-chain Bitcoin payment. + */ + case outgoingOnChain( + /** + * The optional transaction ID of the on-chain payment. + * Will be set for any completed payments. + */txid: Data? + ) + /** + * An incoming on-chain Bitcoin payment. + */ + case incomingOnChain( + /** + * The optional transaction ID of the on-chain payment. + * Will be set for any completed payments. + */txid: Data? + ) + /** + * An incoming Lightning payment. + */ + case incomingLightning + /** + * A payment that is internal to the trusted service. + */ + case trustedInternal +} + + +#if compiler(>=6) +extension PaymentType: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypePaymentType: FfiConverterRustBuffer { + typealias SwiftType = PaymentType + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentType { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .outgoingLightningBolt12(paymentPreimage: try FfiConverterOptionData.read(from: &buf) + ) + + case 2: return .outgoingLightningBolt11(paymentPreimage: try FfiConverterOptionData.read(from: &buf) + ) + + case 3: return .outgoingOnChain(txid: try FfiConverterOptionData.read(from: &buf) + ) + + case 4: return .incomingOnChain(txid: try FfiConverterOptionData.read(from: &buf) + ) + + case 5: return .incomingLightning + + case 6: return .trustedInternal + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: PaymentType, into buf: inout [UInt8]) { + switch value { + + + case let .outgoingLightningBolt12(paymentPreimage): + writeInt(&buf, Int32(1)) + FfiConverterOptionData.write(paymentPreimage, into: &buf) + + + case let .outgoingLightningBolt11(paymentPreimage): + writeInt(&buf, Int32(2)) + FfiConverterOptionData.write(paymentPreimage, into: &buf) + + + case let .outgoingOnChain(txid): + writeInt(&buf, Int32(3)) + FfiConverterOptionData.write(txid, into: &buf) + + + case let .incomingOnChain(txid): + writeInt(&buf, Int32(4)) + FfiConverterOptionData.write(txid, into: &buf) + + + case .incomingLightning: + writeInt(&buf, Int32(5)) + + + case .trustedInternal: + writeInt(&buf, Int32(6)) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentType_lift(_ buf: RustBuffer) throws -> PaymentType { + return try FfiConverterTypePaymentType.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypePaymentType_lower(_ value: PaymentType) -> RustBuffer { + return FfiConverterTypePaymentType.lower(value) +} + + +extension PaymentType: Equatable, Hashable {} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. + +public enum Seed { + + /** + * A BIP 39 mnemonic seed. + */ + case mnemonicSeed( + /** + * The mnemonic phrase. + */mnemonic: Mnemonic, + /** + * The passphrase for the mnemonic. + */passphrase: String? + ) + /** + * A 64-byte seed for the wallet. + */ + case seed64(Data + ) +} + + +#if compiler(>=6) +extension Seed: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeSeed: FfiConverterRustBuffer { + typealias SwiftType = Seed + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Seed { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .mnemonicSeed(mnemonic: try FfiConverterTypeMnemonic.read(from: &buf), passphrase: try FfiConverterOptionString.read(from: &buf) + ) + + case 2: return .seed64(try FfiConverterData.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: Seed, into buf: inout [UInt8]) { + switch value { + + + case let .mnemonicSeed(mnemonic,passphrase): + writeInt(&buf, Int32(1)) + FfiConverterTypeMnemonic.write(mnemonic, into: &buf) + FfiConverterOptionString.write(passphrase, into: &buf) + + + case let .seed64(v1): + writeInt(&buf, Int32(2)) + FfiConverterData.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSeed_lift(_ buf: RustBuffer) throws -> Seed { + return try FfiConverterTypeSeed.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeSeed_lower(_ value: Seed) -> RustBuffer { + return FfiConverterTypeSeed.lower(value) +} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * Configuration for wallet storage, either local SQLite or VSS. + */ + +public enum StorageConfig { + + /** + * Local SQLite database configuration. + */ + case localSqLite(String + ) +} + + +#if compiler(>=6) +extension StorageConfig: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeStorageConfig: FfiConverterRustBuffer { + typealias SwiftType = StorageConfig + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> StorageConfig { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .localSqLite(try FfiConverterString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: StorageConfig, into buf: inout [UInt8]) { + switch value { + + + case let .localSqLite(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeStorageConfig_lift(_ buf: RustBuffer) throws -> StorageConfig { + return try FfiConverterTypeStorageConfig.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeStorageConfig_lower(_ value: StorageConfig) -> RustBuffer { + return FfiConverterTypeStorageConfig.lower(value) +} + + +extension StorageConfig: Equatable, Hashable {} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * The status of a transaction. This is used to track the state of a transaction + */ + +public enum TxStatus { + + /** + * A pending transaction has not yet been paid. + */ + case pending + /** + * A completed transaction has been paid. + */ + case completed + /** + * A transaction that has failed. + */ + case failed +} + + +#if compiler(>=6) +extension TxStatus: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeTxStatus: FfiConverterRustBuffer { + typealias SwiftType = TxStatus + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> TxStatus { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .pending + + case 2: return .completed + + case 3: return .failed + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: TxStatus, into buf: inout [UInt8]) { + switch value { + + + case .pending: + writeInt(&buf, Int32(1)) + + + case .completed: + writeInt(&buf, Int32(2)) + + + case .failed: + writeInt(&buf, Int32(3)) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTxStatus_lift(_ buf: RustBuffer) throws -> TxStatus { + return try FfiConverterTypeTxStatus.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeTxStatus_lower(_ value: TxStatus) -> RustBuffer { + return FfiConverterTypeTxStatus.lower(value) +} + + +extension TxStatus: Equatable, Hashable {} + + + + + + +// Note that we don't yet support `indirect` for enums. +// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. +/** + * Represents the authentication method for a Versioned Storage Service (VSS). + */ + +public enum VssAuth { + + /** + * Authentication using an LNURL-auth server. + */ + case lnurlAuthServer(String + ) + /** + * Authentication using a fixed set of HTTP headers. + */ + case fixedHeaders([String: String] + ) +} + + +#if compiler(>=6) +extension VssAuth: Sendable {} +#endif + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeVssAuth: FfiConverterRustBuffer { + typealias SwiftType = VssAuth + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> VssAuth { + let variant: Int32 = try readInt(&buf) + switch variant { + + case 1: return .lnurlAuthServer(try FfiConverterString.read(from: &buf) + ) + + case 2: return .fixedHeaders(try FfiConverterDictionaryStringString.read(from: &buf) + ) + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: VssAuth, into buf: inout [UInt8]) { + switch value { + + + case let .lnurlAuthServer(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .fixedHeaders(v1): + writeInt(&buf, Int32(2)) + FfiConverterDictionaryStringString.write(v1, into: &buf) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeVssAuth_lift(_ buf: RustBuffer) throws -> VssAuth { + return try FfiConverterTypeVssAuth.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeVssAuth_lower(_ value: VssAuth) -> RustBuffer { + return FfiConverterTypeVssAuth.lower(value) +} + + +extension VssAuth: Equatable, Hashable {} + + + + + + + +/** + * Represents possible errors during wallet operations. + */ +public enum WalletError: Swift.Error { + + + + /** + * Failure in the LDK node. + */ + case LdkNodeFailure(String + ) + /** + * Failure in the trusted wallet implementation. + */ + case TrustedFailure(String + ) + /** + * Failure to parse payment instructions. + */ + case PaymentInstructionsParseError + /** + * Failure to build payment info. + */ + case PaymentInfoBuildError +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public struct FfiConverterTypeWalletError: FfiConverterRustBuffer { + typealias SwiftType = WalletError + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> WalletError { + let variant: Int32 = try readInt(&buf) + switch variant { + + + + + case 1: return .LdkNodeFailure( + try FfiConverterString.read(from: &buf) + ) + case 2: return .TrustedFailure( + try FfiConverterString.read(from: &buf) + ) + case 3: return .PaymentInstructionsParseError + case 4: return .PaymentInfoBuildError + + default: throw UniffiInternalError.unexpectedEnumCase + } + } + + public static func write(_ value: WalletError, into buf: inout [UInt8]) { + switch value { + + + + + + case let .LdkNodeFailure(v1): + writeInt(&buf, Int32(1)) + FfiConverterString.write(v1, into: &buf) + + + case let .TrustedFailure(v1): + writeInt(&buf, Int32(2)) + FfiConverterString.write(v1, into: &buf) + + + case .PaymentInstructionsParseError: + writeInt(&buf, Int32(3)) + + + case .PaymentInfoBuildError: + writeInt(&buf, Int32(4)) + + } + } +} + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWalletError_lift(_ buf: RustBuffer) throws -> WalletError { + return try FfiConverterTypeWalletError.lift(buf) +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +public func FfiConverterTypeWalletError_lower(_ value: WalletError) -> RustBuffer { + return FfiConverterTypeWalletError.lower(value) +} + + +extension WalletError: Equatable, Hashable {} + + + + +extension WalletError: Foundation.LocalizedError { + public var errorDescription: String? { + String(reflecting: self) + } +} + + + + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionUInt16: FfiConverterRustBuffer { + typealias SwiftType = UInt16? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt16.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt16.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionUInt32: FfiConverterRustBuffer { + typealias SwiftType = UInt32? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt32.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt32.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer { + typealias SwiftType = UInt64? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterUInt64.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterUInt64.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer { + typealias SwiftType = String? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterString.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterString.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionData: FfiConverterRustBuffer { + typealias SwiftType = Data? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterData.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterData.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionTypeAmount: FfiConverterRustBuffer { + typealias SwiftType = Amount? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeAmount.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeAmount.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterOptionTypeEvent: FfiConverterRustBuffer { + typealias SwiftType = Event? + + public static func write(_ value: SwiftType, into buf: inout [UInt8]) { + guard let value = value else { + writeInt(&buf, Int8(0)) + return + } + writeInt(&buf, Int8(1)) + FfiConverterTypeEvent.write(value, into: &buf) + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType { + switch try readInt(&buf) as Int8 { + case 0: return nil + case 1: return try FfiConverterTypeEvent.read(from: &buf) + default: throw UniffiInternalError.unexpectedOptionalTag + } + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceData: FfiConverterRustBuffer { + typealias SwiftType = [Data] + + public static func write(_ value: [Data], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterData.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Data] { + let len: Int32 = try readInt(&buf) + var seq = [Data]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterData.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeChannelDetails: FfiConverterRustBuffer { + typealias SwiftType = [ChannelDetails] + + public static func write(_ value: [ChannelDetails], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeChannelDetails.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [ChannelDetails] { + let len: Int32 = try readInt(&buf) + var seq = [ChannelDetails]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeChannelDetails.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterSequenceTypeTransaction: FfiConverterRustBuffer { + typealias SwiftType = [Transaction] + + public static func write(_ value: [Transaction], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for item in value { + FfiConverterTypeTransaction.write(item, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [Transaction] { + let len: Int32 = try readInt(&buf) + var seq = [Transaction]() + seq.reserveCapacity(Int(len)) + for _ in 0 ..< len { + seq.append(try FfiConverterTypeTransaction.read(from: &buf)) + } + return seq + } +} + +#if swift(>=5.8) +@_documentation(visibility: private) +#endif +fileprivate struct FfiConverterDictionaryStringString: FfiConverterRustBuffer { + public static func write(_ value: [String: String], into buf: inout [UInt8]) { + let len = Int32(value.count) + writeInt(&buf, len) + for (key, value) in value { + FfiConverterString.write(key, into: &buf) + FfiConverterString.write(value, into: &buf) + } + } + + public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [String: String] { + let len: Int32 = try readInt(&buf) + var dict = [String: String]() + dict.reserveCapacity(Int(len)) + for _ in 0..>() + +fileprivate func uniffiRustCallAsync( + rustFutureFunc: () -> UInt64, + pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (), + completeFunc: (UInt64, UnsafeMutablePointer) -> F, + freeFunc: (UInt64) -> (), + liftFunc: (F) throws -> T, + errorHandler: ((RustBuffer) throws -> Swift.Error)? +) async throws -> T { + // Make sure to call the ensure init function since future creation doesn't have a + // RustCallStatus param, so doesn't use makeRustCall() + uniffiEnsureOrangeSdkInitialized() + let rustFuture = rustFutureFunc() + defer { + freeFunc(rustFuture) + } + var pollResult: Int8; + repeat { + pollResult = await withUnsafeContinuation { + pollFunc( + rustFuture, + uniffiFutureContinuationCallback, + uniffiContinuationHandleMap.insert(obj: $0) + ) + } + } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY + + return try liftFunc(makeRustCall( + { completeFunc(rustFuture, $0) }, + errorHandler: errorHandler + )) +} + +// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They +// lift the return value or error and resume the suspended function. +fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { + if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { + continuation.resume(returning: pollResult) + } else { + print("uniffiFutureContinuationCallback invalid handle") + } +} + +private enum InitializationResult { + case ok + case contractVersionMismatch + case apiChecksumMismatch +} +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. +private let initializationResult: InitializationResult = { + // Get the bindings contract version from our ComponentInterface + let bindings_contract_version = 29 + // Get the scaffolding contract version by calling the into the dylib + let scaffolding_contract_version = ffi_orange_sdk_uniffi_contract_version() + if bindings_contract_version != scaffolding_contract_version { + return InitializationResult.contractVersionMismatch + } + if (uniffi_orange_sdk_checksum_method_amount_milli_sats() != 55464) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_amount_sats() != 24596) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_amount_sats_rounding_up() != 37049) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_amount_saturating_add() != 54652) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_amount_saturating_sub() != 59950) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_balances_available_balance() != 22059) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_balances_lightning_balance() != 5084) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_balances_pending_balance() != 19480) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_balances_trusted_balance() != 13054) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_channel_id() != 60126) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_channel_value_sats() != 59940) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_cltv_expiry_delta() != 56032) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_confirmations() != 59199) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_confirmations_required() != 53099) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_counterparty_node_id() != 16929) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_feerate_sat_per_1000_weight() != 20107) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_funding_txo() != 40771) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_inbound_capacity_msat() != 12781) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_is_channel_ready() != 4913) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_is_outbound() != 13928) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_is_public() != 2277) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_is_usable() != 63368) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_outbound_capacity_msat() != 49368) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_short_channel_id() != 44292) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_unspendable_punishment_reserve() != 61039) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_channeldetails_user_channel_id() != 40059) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinfo_amount() != 41822) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinfo_instructions() != 3886) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_is_configurable_amount() != 46287) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_is_fixed_amount() != 51475) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_ln_payment_amount() != 58774) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_max_amount() != 28101) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_min_amount() != 3164) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_onchain_payment_amount() != 14156) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_pop_callback() != 49835) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_paymentinstructions_recipient_description() != 52004) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_address() != 50382) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_amount() != 44518) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_bip21_uri() != 19751) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_from_trusted() != 28919) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_invoice() != 55272) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_singleusereceiveuri_payment_hash() != 34169) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_amount() != 51278) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_fee() != 8196) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_id() != 30076) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_outbound() != 55181) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_payment_type() != 13911) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_secs_since_epoch() != 33800) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_transaction_status() != 55729) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_close_channels() != 13697) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_estimate_fee() != 1264) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_event_handled() != 64864) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_get_balance() != 30454) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_get_lightning_address() != 42663) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_get_rebalance_enabled() != 11889) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_get_single_use_receive_uri() != 29885) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_get_tunables() != 38763) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_is_connected_to_lsp() != 54420) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_list_channels() != 38708) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_list_transactions() != 56862) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_next_event() != 15469) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_next_event_async() != 58964) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_node_id() != 31678) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_parse_payment_instructions() != 6192) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_pay() != 1454) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_register_lightning_address() != 39327) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_set_rebalance_enabled() != 18726) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_stop() != 19796) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_method_wallet_wait_next_event() != 20151) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_amount_from_milli_sats() != 16999) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_amount_from_sats() != 5253) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_balances_new() != 65002) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_cashuconfig_new() != 7676) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_mnemonic_from_entropy() != 12170) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_mnemonic_from_str() != 6143) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_mnemonic_generate() != 1334) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_paymentinfo_build() != 10457) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_sparkwalletconfig_default_config() != 8708) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_tunables_default() != 31433) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_tunables_new() != 5567) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_vssconfig_new() != 37600) { + return InitializationResult.apiChecksumMismatch + } + if (uniffi_orange_sdk_checksum_constructor_wallet_new() != 10450) { + return InitializationResult.apiChecksumMismatch + } + + return InitializationResult.ok +}() + +// Make the ensure init function public so that other modules which have external type references to +// our types can call it. +public func uniffiEnsureOrangeSdkInitialized() { + switch initializationResult { + case .ok: + break + case .contractVersionMismatch: + fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project") + case .apiChecksumMismatch: + fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project") + } +} + +// swiftlint:enable all \ No newline at end of file