// This file was autogenerated by some hot garbage in the `uniffi` crate. // Trust me, you don't want to mess with it! 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(LDKNodeFFI) import LDKNodeFFI #endif private 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 from(_ ptr: UnsafeBufferPointer) -> RustBuffer { try! rustCall { ffi_ldk_node_3490_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_ldk_node_3490_rustbuffer_free(self, $0) } } } private 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. private extension Data { init(rustBuffer: RustBuffer) { // TODO: This copies the buffer. Can we read directly from a // Rust buffer? self.init(bytes: rustBuffer.data!, count: Int(rustBuffer.len)) } } // 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 private 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. private func readInt(_ reader: inout (data: Data, offset: Data.Index)) throws -> T { let range = reader.offset ..< reader.offset + MemoryLayout.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 private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> [UInt8] { 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. private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { return Float(bitPattern: try readInt(&reader)) } // Reads a float at the current offset. private 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. private 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. private func createWriter() -> [UInt8] { return [] } private 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! private func writeInt(_ writer: inout [UInt8], _ value: T) { var value = value.bigEndian withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) } } private func writeFloat(_ writer: inout [UInt8], _ value: Float) { writeInt(&writer, value.bitPattern) } private func writeDouble(_ writer: inout [UInt8], _ value: Double) { writeInt(&writer, value.bitPattern) } // Protocol for types that transfer other types across the FFI. This is // analogous go the Rust trait of the same name. private 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. private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} extension FfiConverterPrimitive { public static func lift(_ value: FfiType) throws -> SwiftType { return value } 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. private protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {} extension FfiConverterRustBuffer { 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 } 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. private 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 } } } private let CALL_SUCCESS: Int8 = 0 private let CALL_ERROR: Int8 = 1 private let CALL_PANIC: Int8 = 2 private extension RustCallStatus { init() { self.init( code: CALL_SUCCESS, errorBuf: RustBuffer( capacity: 0, len: 0, data: nil ) ) } } private func rustCall(_ callback: (UnsafeMutablePointer) -> T) throws -> T { try makeRustCall(callback, errorHandler: { $0.deallocate() return UniffiInternalError.unexpectedRustCallError }) } private func rustCallWithError (_ errorFfiConverter: F.Type, _ callback: (UnsafeMutablePointer) -> T) throws -> T where F.SwiftType: Error, F.FfiType == RustBuffer { try makeRustCall(callback, errorHandler: { try errorFfiConverter.lift($0) }) } private func makeRustCall(_ callback: (UnsafeMutablePointer) -> T, errorHandler: (RustBuffer) throws -> Error) throws -> T { var callStatus = RustCallStatus() let returnedVal = callback(&callStatus) switch callStatus.code { case CALL_SUCCESS: return returnedVal case CALL_ERROR: throw try errorHandler(callStatus.errorBuf) case CALL_PANIC: // 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") } default: throw UniffiInternalError.unexpectedRustCallStatusCode } } // Public interface members begin here. private struct FfiConverterUInt8: FfiConverterPrimitive { typealias FfiType = UInt8 typealias SwiftType = UInt8 public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt8 { return try lift(readInt(&buf)) } public static func write(_ value: UInt8, into buf: inout [UInt8]) { writeInt(&buf, lower(value)) } } private 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)) } } private 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)) } } private 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)) } } private 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)) } } private 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) } } public protocol BuilderProtocol { func setEntropySeedPath(seedPath: String) func setEntropySeedBytes(seedBytes: [UInt8]) throws func setEntropyBip39Mnemonic(mnemonic: Mnemonic, passphrase: String?) func setEsploraServer(esploraServerUrl: String) func setGossipSourceP2p() func setGossipSourceRgs(rgsServerUrl: String) func setStorageDirPath(storageDirPath: String) func setNetwork(network: Network) func setListeningAddress(listeningAddress: NetAddress) func build() throws -> LdkNode } public class Builder: BuilderProtocol { fileprivate let pointer: UnsafeMutableRawPointer // 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`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } public convenience init() { self.init(unsafeFromRawPointer: try! rustCall { ldk_node_3490_Builder_new($0) }) } deinit { try! rustCall { ffi_ldk_node_3490_Builder_object_free(pointer, $0) } } public static func fromConfig(config: Config) -> Builder { return Builder(unsafeFromRawPointer: try! rustCall { ldk_node_3490_Builder_from_config( FfiConverterTypeConfig.lower(config), $0 ) }) } public func setEntropySeedPath(seedPath: String) { try! rustCall { ldk_node_3490_Builder_set_entropy_seed_path(self.pointer, FfiConverterString.lower(seedPath), $0) } } public func setEntropySeedBytes(seedBytes: [UInt8]) throws { try rustCallWithError(FfiConverterTypeBuildError.self) { ldk_node_3490_Builder_set_entropy_seed_bytes(self.pointer, FfiConverterSequenceUInt8.lower(seedBytes), $0) } } public func setEntropyBip39Mnemonic(mnemonic: Mnemonic, passphrase: String?) { try! rustCall { ldk_node_3490_Builder_set_entropy_bip39_mnemonic(self.pointer, FfiConverterTypeMnemonic.lower(mnemonic), FfiConverterOptionString.lower(passphrase), $0) } } public func setEsploraServer(esploraServerUrl: String) { try! rustCall { ldk_node_3490_Builder_set_esplora_server(self.pointer, FfiConverterString.lower(esploraServerUrl), $0) } } public func setGossipSourceP2p() { try! rustCall { ldk_node_3490_Builder_set_gossip_source_p2p(self.pointer, $0) } } public func setGossipSourceRgs(rgsServerUrl: String) { try! rustCall { ldk_node_3490_Builder_set_gossip_source_rgs(self.pointer, FfiConverterString.lower(rgsServerUrl), $0) } } public func setStorageDirPath(storageDirPath: String) { try! rustCall { ldk_node_3490_Builder_set_storage_dir_path(self.pointer, FfiConverterString.lower(storageDirPath), $0) } } public func setNetwork(network: Network) { try! rustCall { ldk_node_3490_Builder_set_network(self.pointer, FfiConverterTypeNetwork.lower(network), $0) } } public func setListeningAddress(listeningAddress: NetAddress) { try! rustCall { ldk_node_3490_Builder_set_listening_address(self.pointer, FfiConverterTypeNetAddress.lower(listeningAddress), $0) } } public func build() throws -> LdkNode { return try FfiConverterTypeLdkNode.lift( try rustCallWithError(FfiConverterTypeBuildError.self) { ldk_node_3490_Builder_build(self.pointer, $0) } ) } } public struct FfiConverterTypeBuilder: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = Builder public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Builder { 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: Builder, 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))))) } public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> Builder { return Builder(unsafeFromRawPointer: pointer) } public static func lower(_ value: Builder) -> UnsafeMutableRawPointer { return value.pointer } } public protocol LDKNodeProtocol { func start() throws func stop() throws func nextEvent() -> Event? func waitNextEvent() -> Event func eventHandled() func nodeId() -> PublicKey func listeningAddress() -> NetAddress? func newOnchainAddress() throws -> Address func sendToOnchainAddress(address: Address, amountMsat: UInt64) throws -> Txid func sendAllToOnchainAddress(address: Address) throws -> Txid func spendableOnchainBalanceSats() throws -> UInt64 func totalOnchainBalanceSats() throws -> UInt64 func connect(nodeId: PublicKey, address: NetAddress, persist: Bool) throws func disconnect(nodeId: PublicKey) throws func connectOpenChannel(nodeId: PublicKey, address: NetAddress, channelAmountSats: UInt64, pushToCounterpartyMsat: UInt64?, channelConfig: ChannelConfig?, announceChannel: Bool) throws func closeChannel(channelId: ChannelId, counterpartyNodeId: PublicKey) throws func updateChannelConfig(channelId: ChannelId, counterpartyNodeId: PublicKey, channelConfig: ChannelConfig) throws func syncWallets() throws func sendPayment(invoice: Invoice) throws -> PaymentHash func sendPaymentUsingAmount(invoice: Invoice, amountMsat: UInt64) throws -> PaymentHash func sendSpontaneousPayment(amountMsat: UInt64, nodeId: PublicKey) throws -> PaymentHash func receivePayment(amountMsat: UInt64, description: String, expirySecs: UInt32) throws -> Invoice func receiveVariableAmountPayment(description: String, expirySecs: UInt32) throws -> Invoice func payment(paymentHash: PaymentHash) -> PaymentDetails? func removePayment(paymentHash: PaymentHash) throws -> Bool func listPayments() -> [PaymentDetails] func listPeers() -> [PeerDetails] func listChannels() -> [ChannelDetails] func signMessage(msg: [UInt8]) throws -> String func verifySignature(msg: [UInt8], sig: String, pkey: PublicKey) -> Bool } public class LdkNode: LDKNodeProtocol { fileprivate let pointer: UnsafeMutableRawPointer // 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`. required init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) { self.pointer = pointer } deinit { try! rustCall { ffi_ldk_node_3490_LDKNode_object_free(pointer, $0) } } public func start() throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_start(self.pointer, $0) } } public func stop() throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_stop(self.pointer, $0) } } public func nextEvent() -> Event? { return try! FfiConverterOptionTypeEvent.lift( try! rustCall { ldk_node_3490_LDKNode_next_event(self.pointer, $0) } ) } public func waitNextEvent() -> Event { return try! FfiConverterTypeEvent.lift( try! rustCall { ldk_node_3490_LDKNode_wait_next_event(self.pointer, $0) } ) } public func eventHandled() { try! rustCall { ldk_node_3490_LDKNode_event_handled(self.pointer, $0) } } public func nodeId() -> PublicKey { return try! FfiConverterTypePublicKey.lift( try! rustCall { ldk_node_3490_LDKNode_node_id(self.pointer, $0) } ) } public func listeningAddress() -> NetAddress? { return try! FfiConverterOptionTypeNetAddress.lift( try! rustCall { ldk_node_3490_LDKNode_listening_address(self.pointer, $0) } ) } public func newOnchainAddress() throws -> Address { return try FfiConverterTypeAddress.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_new_onchain_address(self.pointer, $0) } ) } public func sendToOnchainAddress(address: Address, amountMsat: UInt64) throws -> Txid { return try FfiConverterTypeTxid.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_send_to_onchain_address(self.pointer, FfiConverterTypeAddress.lower(address), FfiConverterUInt64.lower(amountMsat), $0) } ) } public func sendAllToOnchainAddress(address: Address) throws -> Txid { return try FfiConverterTypeTxid.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_send_all_to_onchain_address(self.pointer, FfiConverterTypeAddress.lower(address), $0) } ) } public func spendableOnchainBalanceSats() throws -> UInt64 { return try FfiConverterUInt64.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_spendable_onchain_balance_sats(self.pointer, $0) } ) } public func totalOnchainBalanceSats() throws -> UInt64 { return try FfiConverterUInt64.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_total_onchain_balance_sats(self.pointer, $0) } ) } public func connect(nodeId: PublicKey, address: NetAddress, persist: Bool) throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_connect(self.pointer, FfiConverterTypePublicKey.lower(nodeId), FfiConverterTypeNetAddress.lower(address), FfiConverterBool.lower(persist), $0) } } public func disconnect(nodeId: PublicKey) throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_disconnect(self.pointer, FfiConverterTypePublicKey.lower(nodeId), $0) } } public func connectOpenChannel(nodeId: PublicKey, address: NetAddress, channelAmountSats: UInt64, pushToCounterpartyMsat: UInt64?, channelConfig: ChannelConfig?, announceChannel: Bool) throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_connect_open_channel(self.pointer, FfiConverterTypePublicKey.lower(nodeId), FfiConverterTypeNetAddress.lower(address), FfiConverterUInt64.lower(channelAmountSats), FfiConverterOptionUInt64.lower(pushToCounterpartyMsat), FfiConverterOptionTypeChannelConfig.lower(channelConfig), FfiConverterBool.lower(announceChannel), $0) } } public func closeChannel(channelId: ChannelId, counterpartyNodeId: PublicKey) throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_close_channel(self.pointer, FfiConverterTypeChannelId.lower(channelId), FfiConverterTypePublicKey.lower(counterpartyNodeId), $0) } } public func updateChannelConfig(channelId: ChannelId, counterpartyNodeId: PublicKey, channelConfig: ChannelConfig) throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_update_channel_config(self.pointer, FfiConverterTypeChannelId.lower(channelId), FfiConverterTypePublicKey.lower(counterpartyNodeId), FfiConverterTypeChannelConfig.lower(channelConfig), $0) } } public func syncWallets() throws { try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_sync_wallets(self.pointer, $0) } } public func sendPayment(invoice: Invoice) throws -> PaymentHash { return try FfiConverterTypePaymentHash.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_send_payment(self.pointer, FfiConverterTypeInvoice.lower(invoice), $0) } ) } public func sendPaymentUsingAmount(invoice: Invoice, amountMsat: UInt64) throws -> PaymentHash { return try FfiConverterTypePaymentHash.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_send_payment_using_amount(self.pointer, FfiConverterTypeInvoice.lower(invoice), FfiConverterUInt64.lower(amountMsat), $0) } ) } public func sendSpontaneousPayment(amountMsat: UInt64, nodeId: PublicKey) throws -> PaymentHash { return try FfiConverterTypePaymentHash.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_send_spontaneous_payment(self.pointer, FfiConverterUInt64.lower(amountMsat), FfiConverterTypePublicKey.lower(nodeId), $0) } ) } public func receivePayment(amountMsat: UInt64, description: String, expirySecs: UInt32) throws -> Invoice { return try FfiConverterTypeInvoice.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_receive_payment(self.pointer, FfiConverterUInt64.lower(amountMsat), FfiConverterString.lower(description), FfiConverterUInt32.lower(expirySecs), $0) } ) } public func receiveVariableAmountPayment(description: String, expirySecs: UInt32) throws -> Invoice { return try FfiConverterTypeInvoice.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_receive_variable_amount_payment(self.pointer, FfiConverterString.lower(description), FfiConverterUInt32.lower(expirySecs), $0) } ) } public func payment(paymentHash: PaymentHash) -> PaymentDetails? { return try! FfiConverterOptionTypePaymentDetails.lift( try! rustCall { ldk_node_3490_LDKNode_payment(self.pointer, FfiConverterTypePaymentHash.lower(paymentHash), $0) } ) } public func removePayment(paymentHash: PaymentHash) throws -> Bool { return try FfiConverterBool.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_remove_payment(self.pointer, FfiConverterTypePaymentHash.lower(paymentHash), $0) } ) } public func listPayments() -> [PaymentDetails] { return try! FfiConverterSequenceTypePaymentDetails.lift( try! rustCall { ldk_node_3490_LDKNode_list_payments(self.pointer, $0) } ) } public func listPeers() -> [PeerDetails] { return try! FfiConverterSequenceTypePeerDetails.lift( try! rustCall { ldk_node_3490_LDKNode_list_peers(self.pointer, $0) } ) } public func listChannels() -> [ChannelDetails] { return try! FfiConverterSequenceTypeChannelDetails.lift( try! rustCall { ldk_node_3490_LDKNode_list_channels(self.pointer, $0) } ) } public func signMessage(msg: [UInt8]) throws -> String { return try FfiConverterString.lift( try rustCallWithError(FfiConverterTypeNodeError.self) { ldk_node_3490_LDKNode_sign_message(self.pointer, FfiConverterSequenceUInt8.lower(msg), $0) } ) } public func verifySignature(msg: [UInt8], sig: String, pkey: PublicKey) -> Bool { return try! FfiConverterBool.lift( try! rustCall { ldk_node_3490_LDKNode_verify_signature(self.pointer, FfiConverterSequenceUInt8.lower(msg), FfiConverterString.lower(sig), FfiConverterTypePublicKey.lower(pkey), $0) } ) } } public struct FfiConverterTypeLdkNode: FfiConverter { typealias FfiType = UnsafeMutableRawPointer typealias SwiftType = LdkNode public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LdkNode { 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: LdkNode, 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))))) } public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> LdkNode { return LdkNode(unsafeFromRawPointer: pointer) } public static func lower(_ value: LdkNode) -> UnsafeMutableRawPointer { return value.pointer } } public struct ChannelConfig { public var forwardingFeeProportionalMillionths: UInt32 public var forwardingFeeBaseMsat: UInt32 public var cltvExpiryDelta: UInt16 public var maxDustHtlcExposureMsat: UInt64 public var forceCloseAvoidanceMaxFeeSatoshis: UInt64 // Default memberwise initializers are never public by default, so we // declare one manually. public init(forwardingFeeProportionalMillionths: UInt32, forwardingFeeBaseMsat: UInt32, cltvExpiryDelta: UInt16, maxDustHtlcExposureMsat: UInt64, forceCloseAvoidanceMaxFeeSatoshis: UInt64) { self.forwardingFeeProportionalMillionths = forwardingFeeProportionalMillionths self.forwardingFeeBaseMsat = forwardingFeeBaseMsat self.cltvExpiryDelta = cltvExpiryDelta self.maxDustHtlcExposureMsat = maxDustHtlcExposureMsat self.forceCloseAvoidanceMaxFeeSatoshis = forceCloseAvoidanceMaxFeeSatoshis } } extension ChannelConfig: Equatable, Hashable { public static func == (lhs: ChannelConfig, rhs: ChannelConfig) -> Bool { if lhs.forwardingFeeProportionalMillionths != rhs.forwardingFeeProportionalMillionths { return false } if lhs.forwardingFeeBaseMsat != rhs.forwardingFeeBaseMsat { return false } if lhs.cltvExpiryDelta != rhs.cltvExpiryDelta { return false } if lhs.maxDustHtlcExposureMsat != rhs.maxDustHtlcExposureMsat { return false } if lhs.forceCloseAvoidanceMaxFeeSatoshis != rhs.forceCloseAvoidanceMaxFeeSatoshis { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(forwardingFeeProportionalMillionths) hasher.combine(forwardingFeeBaseMsat) hasher.combine(cltvExpiryDelta) hasher.combine(maxDustHtlcExposureMsat) hasher.combine(forceCloseAvoidanceMaxFeeSatoshis) } } public struct FfiConverterTypeChannelConfig: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChannelConfig { return try ChannelConfig( forwardingFeeProportionalMillionths: FfiConverterUInt32.read(from: &buf), forwardingFeeBaseMsat: FfiConverterUInt32.read(from: &buf), cltvExpiryDelta: FfiConverterUInt16.read(from: &buf), maxDustHtlcExposureMsat: FfiConverterUInt64.read(from: &buf), forceCloseAvoidanceMaxFeeSatoshis: FfiConverterUInt64.read(from: &buf) ) } public static func write(_ value: ChannelConfig, into buf: inout [UInt8]) { FfiConverterUInt32.write(value.forwardingFeeProportionalMillionths, into: &buf) FfiConverterUInt32.write(value.forwardingFeeBaseMsat, into: &buf) FfiConverterUInt16.write(value.cltvExpiryDelta, into: &buf) FfiConverterUInt64.write(value.maxDustHtlcExposureMsat, into: &buf) FfiConverterUInt64.write(value.forceCloseAvoidanceMaxFeeSatoshis, into: &buf) } } public func FfiConverterTypeChannelConfig_lift(_ buf: RustBuffer) throws -> ChannelConfig { return try FfiConverterTypeChannelConfig.lift(buf) } public func FfiConverterTypeChannelConfig_lower(_ value: ChannelConfig) -> RustBuffer { return FfiConverterTypeChannelConfig.lower(value) } public struct ChannelDetails { public var channelId: ChannelId public var counterpartyNodeId: PublicKey public var fundingTxo: OutPoint? public var channelValueSats: UInt64 public var unspendablePunishmentReserve: UInt64? public var userChannelId: UserChannelId public var feerateSatPer1000Weight: UInt32 public var balanceMsat: UInt64 public var outboundCapacityMsat: UInt64 public var inboundCapacityMsat: UInt64 public var confirmationsRequired: UInt32? public var confirmations: UInt32? public var isOutbound: Bool public var isChannelReady: Bool public var isUsable: Bool public var isPublic: Bool public var cltvExpiryDelta: UInt16? // Default memberwise initializers are never public by default, so we // declare one manually. public init(channelId: ChannelId, counterpartyNodeId: PublicKey, fundingTxo: OutPoint?, channelValueSats: UInt64, unspendablePunishmentReserve: UInt64?, userChannelId: UserChannelId, feerateSatPer1000Weight: UInt32, balanceMsat: UInt64, outboundCapacityMsat: UInt64, inboundCapacityMsat: UInt64, confirmationsRequired: UInt32?, confirmations: UInt32?, isOutbound: Bool, isChannelReady: Bool, isUsable: Bool, isPublic: Bool, cltvExpiryDelta: UInt16?) { self.channelId = channelId self.counterpartyNodeId = counterpartyNodeId self.fundingTxo = fundingTxo self.channelValueSats = channelValueSats self.unspendablePunishmentReserve = unspendablePunishmentReserve self.userChannelId = userChannelId self.feerateSatPer1000Weight = feerateSatPer1000Weight self.balanceMsat = balanceMsat self.outboundCapacityMsat = outboundCapacityMsat self.inboundCapacityMsat = inboundCapacityMsat self.confirmationsRequired = confirmationsRequired self.confirmations = confirmations self.isOutbound = isOutbound self.isChannelReady = isChannelReady self.isUsable = isUsable self.isPublic = isPublic self.cltvExpiryDelta = cltvExpiryDelta } } extension ChannelDetails: Equatable, Hashable { public static func == (lhs: ChannelDetails, rhs: ChannelDetails) -> Bool { if lhs.channelId != rhs.channelId { return false } if lhs.counterpartyNodeId != rhs.counterpartyNodeId { return false } if lhs.fundingTxo != rhs.fundingTxo { return false } if lhs.channelValueSats != rhs.channelValueSats { return false } if lhs.unspendablePunishmentReserve != rhs.unspendablePunishmentReserve { return false } if lhs.userChannelId != rhs.userChannelId { return false } if lhs.feerateSatPer1000Weight != rhs.feerateSatPer1000Weight { return false } if lhs.balanceMsat != rhs.balanceMsat { return false } if lhs.outboundCapacityMsat != rhs.outboundCapacityMsat { return false } if lhs.inboundCapacityMsat != rhs.inboundCapacityMsat { return false } if lhs.confirmationsRequired != rhs.confirmationsRequired { return false } if lhs.confirmations != rhs.confirmations { return false } if lhs.isOutbound != rhs.isOutbound { return false } if lhs.isChannelReady != rhs.isChannelReady { return false } if lhs.isUsable != rhs.isUsable { return false } if lhs.isPublic != rhs.isPublic { return false } if lhs.cltvExpiryDelta != rhs.cltvExpiryDelta { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(channelId) hasher.combine(counterpartyNodeId) hasher.combine(fundingTxo) hasher.combine(channelValueSats) hasher.combine(unspendablePunishmentReserve) hasher.combine(userChannelId) hasher.combine(feerateSatPer1000Weight) hasher.combine(balanceMsat) hasher.combine(outboundCapacityMsat) hasher.combine(inboundCapacityMsat) hasher.combine(confirmationsRequired) hasher.combine(confirmations) hasher.combine(isOutbound) hasher.combine(isChannelReady) hasher.combine(isUsable) hasher.combine(isPublic) hasher.combine(cltvExpiryDelta) } } public struct FfiConverterTypeChannelDetails: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChannelDetails { return try ChannelDetails( channelId: FfiConverterTypeChannelId.read(from: &buf), counterpartyNodeId: FfiConverterTypePublicKey.read(from: &buf), fundingTxo: FfiConverterOptionTypeOutPoint.read(from: &buf), channelValueSats: FfiConverterUInt64.read(from: &buf), unspendablePunishmentReserve: FfiConverterOptionUInt64.read(from: &buf), userChannelId: FfiConverterTypeUserChannelId.read(from: &buf), feerateSatPer1000Weight: FfiConverterUInt32.read(from: &buf), balanceMsat: FfiConverterUInt64.read(from: &buf), outboundCapacityMsat: FfiConverterUInt64.read(from: &buf), inboundCapacityMsat: FfiConverterUInt64.read(from: &buf), confirmationsRequired: FfiConverterOptionUInt32.read(from: &buf), confirmations: FfiConverterOptionUInt32.read(from: &buf), isOutbound: FfiConverterBool.read(from: &buf), isChannelReady: FfiConverterBool.read(from: &buf), isUsable: FfiConverterBool.read(from: &buf), isPublic: FfiConverterBool.read(from: &buf), cltvExpiryDelta: FfiConverterOptionUInt16.read(from: &buf) ) } public static func write(_ value: ChannelDetails, into buf: inout [UInt8]) { FfiConverterTypeChannelId.write(value.channelId, into: &buf) FfiConverterTypePublicKey.write(value.counterpartyNodeId, into: &buf) FfiConverterOptionTypeOutPoint.write(value.fundingTxo, into: &buf) FfiConverterUInt64.write(value.channelValueSats, into: &buf) FfiConverterOptionUInt64.write(value.unspendablePunishmentReserve, into: &buf) FfiConverterTypeUserChannelId.write(value.userChannelId, into: &buf) FfiConverterUInt32.write(value.feerateSatPer1000Weight, into: &buf) FfiConverterUInt64.write(value.balanceMsat, into: &buf) FfiConverterUInt64.write(value.outboundCapacityMsat, into: &buf) FfiConverterUInt64.write(value.inboundCapacityMsat, into: &buf) FfiConverterOptionUInt32.write(value.confirmationsRequired, into: &buf) FfiConverterOptionUInt32.write(value.confirmations, into: &buf) FfiConverterBool.write(value.isOutbound, into: &buf) FfiConverterBool.write(value.isChannelReady, into: &buf) FfiConverterBool.write(value.isUsable, into: &buf) FfiConverterBool.write(value.isPublic, into: &buf) FfiConverterOptionUInt16.write(value.cltvExpiryDelta, into: &buf) } } public func FfiConverterTypeChannelDetails_lift(_ buf: RustBuffer) throws -> ChannelDetails { return try FfiConverterTypeChannelDetails.lift(buf) } public func FfiConverterTypeChannelDetails_lower(_ value: ChannelDetails) -> RustBuffer { return FfiConverterTypeChannelDetails.lower(value) } public struct Config { public var storageDirPath: String public var network: Network public var listeningAddress: NetAddress? public var defaultCltvExpiryDelta: UInt32 public var onchainWalletSyncIntervalSecs: UInt64 public var walletSyncIntervalSecs: UInt64 public var feeRateCacheUpdateIntervalSecs: UInt64 public var logLevel: LogLevel public var trustedPeers0conf: [PublicKey] // Default memberwise initializers are never public by default, so we // declare one manually. public init(storageDirPath: String = "/tmp/ldk_node/", network: Network = .bitcoin, listeningAddress: NetAddress? = nil, defaultCltvExpiryDelta: UInt32 = UInt32(144), onchainWalletSyncIntervalSecs: UInt64 = UInt64(80), walletSyncIntervalSecs: UInt64 = UInt64(30), feeRateCacheUpdateIntervalSecs: UInt64 = UInt64(600), logLevel: LogLevel = .debug, trustedPeers0conf: [PublicKey] = []) { self.storageDirPath = storageDirPath self.network = network self.listeningAddress = listeningAddress self.defaultCltvExpiryDelta = defaultCltvExpiryDelta self.onchainWalletSyncIntervalSecs = onchainWalletSyncIntervalSecs self.walletSyncIntervalSecs = walletSyncIntervalSecs self.feeRateCacheUpdateIntervalSecs = feeRateCacheUpdateIntervalSecs self.logLevel = logLevel self.trustedPeers0conf = trustedPeers0conf } } extension Config: Equatable, Hashable { public static func == (lhs: Config, rhs: Config) -> Bool { if lhs.storageDirPath != rhs.storageDirPath { return false } if lhs.network != rhs.network { return false } if lhs.listeningAddress != rhs.listeningAddress { return false } if lhs.defaultCltvExpiryDelta != rhs.defaultCltvExpiryDelta { return false } if lhs.onchainWalletSyncIntervalSecs != rhs.onchainWalletSyncIntervalSecs { return false } if lhs.walletSyncIntervalSecs != rhs.walletSyncIntervalSecs { return false } if lhs.feeRateCacheUpdateIntervalSecs != rhs.feeRateCacheUpdateIntervalSecs { return false } if lhs.logLevel != rhs.logLevel { return false } if lhs.trustedPeers0conf != rhs.trustedPeers0conf { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(storageDirPath) hasher.combine(network) hasher.combine(listeningAddress) hasher.combine(defaultCltvExpiryDelta) hasher.combine(onchainWalletSyncIntervalSecs) hasher.combine(walletSyncIntervalSecs) hasher.combine(feeRateCacheUpdateIntervalSecs) hasher.combine(logLevel) hasher.combine(trustedPeers0conf) } } public struct FfiConverterTypeConfig: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Config { return try Config( storageDirPath: FfiConverterString.read(from: &buf), network: FfiConverterTypeNetwork.read(from: &buf), listeningAddress: FfiConverterOptionTypeNetAddress.read(from: &buf), defaultCltvExpiryDelta: FfiConverterUInt32.read(from: &buf), onchainWalletSyncIntervalSecs: FfiConverterUInt64.read(from: &buf), walletSyncIntervalSecs: FfiConverterUInt64.read(from: &buf), feeRateCacheUpdateIntervalSecs: FfiConverterUInt64.read(from: &buf), logLevel: FfiConverterTypeLogLevel.read(from: &buf), trustedPeers0conf: FfiConverterSequenceTypePublicKey.read(from: &buf) ) } public static func write(_ value: Config, into buf: inout [UInt8]) { FfiConverterString.write(value.storageDirPath, into: &buf) FfiConverterTypeNetwork.write(value.network, into: &buf) FfiConverterOptionTypeNetAddress.write(value.listeningAddress, into: &buf) FfiConverterUInt32.write(value.defaultCltvExpiryDelta, into: &buf) FfiConverterUInt64.write(value.onchainWalletSyncIntervalSecs, into: &buf) FfiConverterUInt64.write(value.walletSyncIntervalSecs, into: &buf) FfiConverterUInt64.write(value.feeRateCacheUpdateIntervalSecs, into: &buf) FfiConverterTypeLogLevel.write(value.logLevel, into: &buf) FfiConverterSequenceTypePublicKey.write(value.trustedPeers0conf, into: &buf) } } public func FfiConverterTypeConfig_lift(_ buf: RustBuffer) throws -> Config { return try FfiConverterTypeConfig.lift(buf) } public func FfiConverterTypeConfig_lower(_ value: Config) -> RustBuffer { return FfiConverterTypeConfig.lower(value) } public struct OutPoint { public var txid: Txid public var vout: UInt32 // Default memberwise initializers are never public by default, so we // declare one manually. public init(txid: Txid, vout: UInt32) { self.txid = txid self.vout = vout } } extension OutPoint: Equatable, Hashable { public static func == (lhs: OutPoint, rhs: OutPoint) -> Bool { if lhs.txid != rhs.txid { return false } if lhs.vout != rhs.vout { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(txid) hasher.combine(vout) } } public struct FfiConverterTypeOutPoint: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> OutPoint { return try OutPoint( txid: FfiConverterTypeTxid.read(from: &buf), vout: FfiConverterUInt32.read(from: &buf) ) } public static func write(_ value: OutPoint, into buf: inout [UInt8]) { FfiConverterTypeTxid.write(value.txid, into: &buf) FfiConverterUInt32.write(value.vout, into: &buf) } } public func FfiConverterTypeOutPoint_lift(_ buf: RustBuffer) throws -> OutPoint { return try FfiConverterTypeOutPoint.lift(buf) } public func FfiConverterTypeOutPoint_lower(_ value: OutPoint) -> RustBuffer { return FfiConverterTypeOutPoint.lower(value) } public struct PaymentDetails { public var hash: PaymentHash public var preimage: PaymentPreimage? public var secret: PaymentSecret? public var amountMsat: UInt64? public var direction: PaymentDirection public var status: PaymentStatus // Default memberwise initializers are never public by default, so we // declare one manually. public init(hash: PaymentHash, preimage: PaymentPreimage?, secret: PaymentSecret?, amountMsat: UInt64?, direction: PaymentDirection, status: PaymentStatus) { self.hash = hash self.preimage = preimage self.secret = secret self.amountMsat = amountMsat self.direction = direction self.status = status } } extension PaymentDetails: Equatable, Hashable { public static func == (lhs: PaymentDetails, rhs: PaymentDetails) -> Bool { if lhs.hash != rhs.hash { return false } if lhs.preimage != rhs.preimage { return false } if lhs.secret != rhs.secret { return false } if lhs.amountMsat != rhs.amountMsat { return false } if lhs.direction != rhs.direction { return false } if lhs.status != rhs.status { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(hash) hasher.combine(preimage) hasher.combine(secret) hasher.combine(amountMsat) hasher.combine(direction) hasher.combine(status) } } public struct FfiConverterTypePaymentDetails: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentDetails { return try PaymentDetails( hash: FfiConverterTypePaymentHash.read(from: &buf), preimage: FfiConverterOptionTypePaymentPreimage.read(from: &buf), secret: FfiConverterOptionTypePaymentSecret.read(from: &buf), amountMsat: FfiConverterOptionUInt64.read(from: &buf), direction: FfiConverterTypePaymentDirection.read(from: &buf), status: FfiConverterTypePaymentStatus.read(from: &buf) ) } public static func write(_ value: PaymentDetails, into buf: inout [UInt8]) { FfiConverterTypePaymentHash.write(value.hash, into: &buf) FfiConverterOptionTypePaymentPreimage.write(value.preimage, into: &buf) FfiConverterOptionTypePaymentSecret.write(value.secret, into: &buf) FfiConverterOptionUInt64.write(value.amountMsat, into: &buf) FfiConverterTypePaymentDirection.write(value.direction, into: &buf) FfiConverterTypePaymentStatus.write(value.status, into: &buf) } } public func FfiConverterTypePaymentDetails_lift(_ buf: RustBuffer) throws -> PaymentDetails { return try FfiConverterTypePaymentDetails.lift(buf) } public func FfiConverterTypePaymentDetails_lower(_ value: PaymentDetails) -> RustBuffer { return FfiConverterTypePaymentDetails.lower(value) } public struct PeerDetails { public var nodeId: PublicKey public var address: NetAddress public var isPersisted: Bool public var isConnected: Bool // Default memberwise initializers are never public by default, so we // declare one manually. public init(nodeId: PublicKey, address: NetAddress, isPersisted: Bool, isConnected: Bool) { self.nodeId = nodeId self.address = address self.isPersisted = isPersisted self.isConnected = isConnected } } extension PeerDetails: Equatable, Hashable { public static func == (lhs: PeerDetails, rhs: PeerDetails) -> Bool { if lhs.nodeId != rhs.nodeId { return false } if lhs.address != rhs.address { return false } if lhs.isPersisted != rhs.isPersisted { return false } if lhs.isConnected != rhs.isConnected { return false } return true } public func hash(into hasher: inout Hasher) { hasher.combine(nodeId) hasher.combine(address) hasher.combine(isPersisted) hasher.combine(isConnected) } } public struct FfiConverterTypePeerDetails: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PeerDetails { return try PeerDetails( nodeId: FfiConverterTypePublicKey.read(from: &buf), address: FfiConverterTypeNetAddress.read(from: &buf), isPersisted: FfiConverterBool.read(from: &buf), isConnected: FfiConverterBool.read(from: &buf) ) } public static func write(_ value: PeerDetails, into buf: inout [UInt8]) { FfiConverterTypePublicKey.write(value.nodeId, into: &buf) FfiConverterTypeNetAddress.write(value.address, into: &buf) FfiConverterBool.write(value.isPersisted, into: &buf) FfiConverterBool.write(value.isConnected, into: &buf) } } public func FfiConverterTypePeerDetails_lift(_ buf: RustBuffer) throws -> PeerDetails { return try FfiConverterTypePeerDetails.lift(buf) } public func FfiConverterTypePeerDetails_lower(_ value: PeerDetails) -> RustBuffer { return FfiConverterTypePeerDetails.lower(value) } // Note that we don't yet support `indirect` for enums. // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum Event { case paymentSuccessful(paymentHash: PaymentHash) case paymentFailed(paymentHash: PaymentHash) case paymentReceived(paymentHash: PaymentHash, amountMsat: UInt64) case channelPending(channelId: ChannelId, userChannelId: UserChannelId, formerTemporaryChannelId: ChannelId, counterpartyNodeId: PublicKey, fundingTxo: OutPoint) case channelReady(channelId: ChannelId, userChannelId: UserChannelId) case channelClosed(channelId: ChannelId, userChannelId: UserChannelId) } 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( paymentHash: try FfiConverterTypePaymentHash.read(from: &buf) ) case 2: return .paymentFailed( paymentHash: try FfiConverterTypePaymentHash.read(from: &buf) ) case 3: return .paymentReceived( paymentHash: try FfiConverterTypePaymentHash.read(from: &buf), amountMsat: try FfiConverterUInt64.read(from: &buf) ) case 4: return .channelPending( channelId: try FfiConverterTypeChannelId.read(from: &buf), userChannelId: try FfiConverterTypeUserChannelId.read(from: &buf), formerTemporaryChannelId: try FfiConverterTypeChannelId.read(from: &buf), counterpartyNodeId: try FfiConverterTypePublicKey.read(from: &buf), fundingTxo: try FfiConverterTypeOutPoint.read(from: &buf) ) case 5: return .channelReady( channelId: try FfiConverterTypeChannelId.read(from: &buf), userChannelId: try FfiConverterTypeUserChannelId.read(from: &buf) ) case 6: return .channelClosed( channelId: try FfiConverterTypeChannelId.read(from: &buf), userChannelId: try FfiConverterTypeUserChannelId.read(from: &buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: Event, into buf: inout [UInt8]) { switch value { case let .paymentSuccessful(paymentHash): writeInt(&buf, Int32(1)) FfiConverterTypePaymentHash.write(paymentHash, into: &buf) case let .paymentFailed(paymentHash): writeInt(&buf, Int32(2)) FfiConverterTypePaymentHash.write(paymentHash, into: &buf) case let .paymentReceived(paymentHash, amountMsat): writeInt(&buf, Int32(3)) FfiConverterTypePaymentHash.write(paymentHash, into: &buf) FfiConverterUInt64.write(amountMsat, into: &buf) case let .channelPending(channelId, userChannelId, formerTemporaryChannelId, counterpartyNodeId, fundingTxo): writeInt(&buf, Int32(4)) FfiConverterTypeChannelId.write(channelId, into: &buf) FfiConverterTypeUserChannelId.write(userChannelId, into: &buf) FfiConverterTypeChannelId.write(formerTemporaryChannelId, into: &buf) FfiConverterTypePublicKey.write(counterpartyNodeId, into: &buf) FfiConverterTypeOutPoint.write(fundingTxo, into: &buf) case let .channelReady(channelId, userChannelId): writeInt(&buf, Int32(5)) FfiConverterTypeChannelId.write(channelId, into: &buf) FfiConverterTypeUserChannelId.write(userChannelId, into: &buf) case let .channelClosed(channelId, userChannelId): writeInt(&buf, Int32(6)) FfiConverterTypeChannelId.write(channelId, into: &buf) FfiConverterTypeUserChannelId.write(userChannelId, into: &buf) } } } public func FfiConverterTypeEvent_lift(_ buf: RustBuffer) throws -> Event { return try FfiConverterTypeEvent.lift(buf) } 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. public enum LogLevel { case gossip case trace case debug case info case warn case error } public struct FfiConverterTypeLogLevel: FfiConverterRustBuffer { typealias SwiftType = LogLevel public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> LogLevel { let variant: Int32 = try readInt(&buf) switch variant { case 1: return .gossip case 2: return .trace case 3: return .debug case 4: return .info case 5: return .warn case 6: return .error default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: LogLevel, into buf: inout [UInt8]) { switch value { case .gossip: writeInt(&buf, Int32(1)) case .trace: writeInt(&buf, Int32(2)) case .debug: writeInt(&buf, Int32(3)) case .info: writeInt(&buf, Int32(4)) case .warn: writeInt(&buf, Int32(5)) case .error: writeInt(&buf, Int32(6)) } } } public func FfiConverterTypeLogLevel_lift(_ buf: RustBuffer) throws -> LogLevel { return try FfiConverterTypeLogLevel.lift(buf) } public func FfiConverterTypeLogLevel_lower(_ value: LogLevel) -> RustBuffer { return FfiConverterTypeLogLevel.lower(value) } extension LogLevel: 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 Network { case bitcoin case testnet case signet case regtest } 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 .bitcoin case 2: return .testnet case 3: return .signet case 4: return .regtest default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: Network, into buf: inout [UInt8]) { switch value { case .bitcoin: writeInt(&buf, Int32(1)) case .testnet: writeInt(&buf, Int32(2)) case .signet: writeInt(&buf, Int32(3)) case .regtest: writeInt(&buf, Int32(4)) } } } public func FfiConverterTypeNetwork_lift(_ buf: RustBuffer) throws -> Network { return try FfiConverterTypeNetwork.lift(buf) } public func FfiConverterTypeNetwork_lower(_ value: Network) -> RustBuffer { return FfiConverterTypeNetwork.lower(value) } extension Network: 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 PaymentDirection { case inbound case outbound } public struct FfiConverterTypePaymentDirection: FfiConverterRustBuffer { typealias SwiftType = PaymentDirection public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentDirection { let variant: Int32 = try readInt(&buf) switch variant { case 1: return .inbound case 2: return .outbound default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: PaymentDirection, into buf: inout [UInt8]) { switch value { case .inbound: writeInt(&buf, Int32(1)) case .outbound: writeInt(&buf, Int32(2)) } } } public func FfiConverterTypePaymentDirection_lift(_ buf: RustBuffer) throws -> PaymentDirection { return try FfiConverterTypePaymentDirection.lift(buf) } public func FfiConverterTypePaymentDirection_lower(_ value: PaymentDirection) -> RustBuffer { return FfiConverterTypePaymentDirection.lower(value) } extension PaymentDirection: 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 PaymentStatus { case pending case succeeded case failed } public struct FfiConverterTypePaymentStatus: FfiConverterRustBuffer { typealias SwiftType = PaymentStatus public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentStatus { let variant: Int32 = try readInt(&buf) switch variant { case 1: return .pending case 2: return .succeeded case 3: return .failed default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: PaymentStatus, into buf: inout [UInt8]) { switch value { case .pending: writeInt(&buf, Int32(1)) case .succeeded: writeInt(&buf, Int32(2)) case .failed: writeInt(&buf, Int32(3)) } } } public func FfiConverterTypePaymentStatus_lift(_ buf: RustBuffer) throws -> PaymentStatus { return try FfiConverterTypePaymentStatus.lift(buf) } public func FfiConverterTypePaymentStatus_lower(_ value: PaymentStatus) -> RustBuffer { return FfiConverterTypePaymentStatus.lower(value) } extension PaymentStatus: Equatable, Hashable {} public enum BuildError { // Simple error enums only carry a message case InvalidSeedBytes(message: String) // Simple error enums only carry a message case InvalidSeedFile(message: String) // Simple error enums only carry a message case InvalidSystemTime(message: String) // Simple error enums only carry a message case ReadFailed(message: String) // Simple error enums only carry a message case WriteFailed(message: String) // Simple error enums only carry a message case StoragePathAccessFailed(message: String) // Simple error enums only carry a message case WalletSetupFailed(message: String) // Simple error enums only carry a message case LoggerSetupFailed(message: String) } public struct FfiConverterTypeBuildError: FfiConverterRustBuffer { typealias SwiftType = BuildError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> BuildError { let variant: Int32 = try readInt(&buf) switch variant { case 1: return .InvalidSeedBytes( message: try FfiConverterString.read(from: &buf) ) case 2: return .InvalidSeedFile( message: try FfiConverterString.read(from: &buf) ) case 3: return .InvalidSystemTime( message: try FfiConverterString.read(from: &buf) ) case 4: return .ReadFailed( message: try FfiConverterString.read(from: &buf) ) case 5: return .WriteFailed( message: try FfiConverterString.read(from: &buf) ) case 6: return .StoragePathAccessFailed( message: try FfiConverterString.read(from: &buf) ) case 7: return .WalletSetupFailed( message: try FfiConverterString.read(from: &buf) ) case 8: return .LoggerSetupFailed( message: try FfiConverterString.read(from: &buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: BuildError, into buf: inout [UInt8]) { switch value { case let .InvalidSeedBytes(message): writeInt(&buf, Int32(1)) FfiConverterString.write(message, into: &buf) case let .InvalidSeedFile(message): writeInt(&buf, Int32(2)) FfiConverterString.write(message, into: &buf) case let .InvalidSystemTime(message): writeInt(&buf, Int32(3)) FfiConverterString.write(message, into: &buf) case let .ReadFailed(message): writeInt(&buf, Int32(4)) FfiConverterString.write(message, into: &buf) case let .WriteFailed(message): writeInt(&buf, Int32(5)) FfiConverterString.write(message, into: &buf) case let .StoragePathAccessFailed(message): writeInt(&buf, Int32(6)) FfiConverterString.write(message, into: &buf) case let .WalletSetupFailed(message): writeInt(&buf, Int32(7)) FfiConverterString.write(message, into: &buf) case let .LoggerSetupFailed(message): writeInt(&buf, Int32(8)) FfiConverterString.write(message, into: &buf) } } } extension BuildError: Equatable, Hashable {} extension BuildError: Error {} public enum NodeError { // Simple error enums only carry a message case AlreadyRunning(message: String) // Simple error enums only carry a message case NotRunning(message: String) // Simple error enums only carry a message case OnchainTxCreationFailed(message: String) // Simple error enums only carry a message case ConnectionFailed(message: String) // Simple error enums only carry a message case InvoiceCreationFailed(message: String) // Simple error enums only carry a message case PaymentSendingFailed(message: String) // Simple error enums only carry a message case ChannelCreationFailed(message: String) // Simple error enums only carry a message case ChannelClosingFailed(message: String) // Simple error enums only carry a message case ChannelConfigUpdateFailed(message: String) // Simple error enums only carry a message case PersistenceFailed(message: String) // Simple error enums only carry a message case WalletOperationFailed(message: String) // Simple error enums only carry a message case OnchainTxSigningFailed(message: String) // Simple error enums only carry a message case MessageSigningFailed(message: String) // Simple error enums only carry a message case TxSyncFailed(message: String) // Simple error enums only carry a message case GossipUpdateFailed(message: String) // Simple error enums only carry a message case InvalidAddress(message: String) // Simple error enums only carry a message case InvalidNetAddress(message: String) // Simple error enums only carry a message case InvalidPublicKey(message: String) // Simple error enums only carry a message case InvalidSecretKey(message: String) // Simple error enums only carry a message case InvalidPaymentHash(message: String) // Simple error enums only carry a message case InvalidPaymentPreimage(message: String) // Simple error enums only carry a message case InvalidPaymentSecret(message: String) // Simple error enums only carry a message case InvalidAmount(message: String) // Simple error enums only carry a message case InvalidInvoice(message: String) // Simple error enums only carry a message case InvalidChannelId(message: String) // Simple error enums only carry a message case InvalidNetwork(message: String) // Simple error enums only carry a message case DuplicatePayment(message: String) // Simple error enums only carry a message case InsufficientFunds(message: String) } public struct FfiConverterTypeNodeError: FfiConverterRustBuffer { typealias SwiftType = NodeError public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NodeError { let variant: Int32 = try readInt(&buf) switch variant { case 1: return .AlreadyRunning( message: try FfiConverterString.read(from: &buf) ) case 2: return .NotRunning( message: try FfiConverterString.read(from: &buf) ) case 3: return .OnchainTxCreationFailed( message: try FfiConverterString.read(from: &buf) ) case 4: return .ConnectionFailed( message: try FfiConverterString.read(from: &buf) ) case 5: return .InvoiceCreationFailed( message: try FfiConverterString.read(from: &buf) ) case 6: return .PaymentSendingFailed( message: try FfiConverterString.read(from: &buf) ) case 7: return .ChannelCreationFailed( message: try FfiConverterString.read(from: &buf) ) case 8: return .ChannelClosingFailed( message: try FfiConverterString.read(from: &buf) ) case 9: return .ChannelConfigUpdateFailed( message: try FfiConverterString.read(from: &buf) ) case 10: return .PersistenceFailed( message: try FfiConverterString.read(from: &buf) ) case 11: return .WalletOperationFailed( message: try FfiConverterString.read(from: &buf) ) case 12: return .OnchainTxSigningFailed( message: try FfiConverterString.read(from: &buf) ) case 13: return .MessageSigningFailed( message: try FfiConverterString.read(from: &buf) ) case 14: return .TxSyncFailed( message: try FfiConverterString.read(from: &buf) ) case 15: return .GossipUpdateFailed( message: try FfiConverterString.read(from: &buf) ) case 16: return .InvalidAddress( message: try FfiConverterString.read(from: &buf) ) case 17: return .InvalidNetAddress( message: try FfiConverterString.read(from: &buf) ) case 18: return .InvalidPublicKey( message: try FfiConverterString.read(from: &buf) ) case 19: return .InvalidSecretKey( message: try FfiConverterString.read(from: &buf) ) case 20: return .InvalidPaymentHash( message: try FfiConverterString.read(from: &buf) ) case 21: return .InvalidPaymentPreimage( message: try FfiConverterString.read(from: &buf) ) case 22: return .InvalidPaymentSecret( message: try FfiConverterString.read(from: &buf) ) case 23: return .InvalidAmount( message: try FfiConverterString.read(from: &buf) ) case 24: return .InvalidInvoice( message: try FfiConverterString.read(from: &buf) ) case 25: return .InvalidChannelId( message: try FfiConverterString.read(from: &buf) ) case 26: return .InvalidNetwork( message: try FfiConverterString.read(from: &buf) ) case 27: return .DuplicatePayment( message: try FfiConverterString.read(from: &buf) ) case 28: return .InsufficientFunds( message: try FfiConverterString.read(from: &buf) ) default: throw UniffiInternalError.unexpectedEnumCase } } public static func write(_ value: NodeError, into buf: inout [UInt8]) { switch value { case let .AlreadyRunning(message): writeInt(&buf, Int32(1)) FfiConverterString.write(message, into: &buf) case let .NotRunning(message): writeInt(&buf, Int32(2)) FfiConverterString.write(message, into: &buf) case let .OnchainTxCreationFailed(message): writeInt(&buf, Int32(3)) FfiConverterString.write(message, into: &buf) case let .ConnectionFailed(message): writeInt(&buf, Int32(4)) FfiConverterString.write(message, into: &buf) case let .InvoiceCreationFailed(message): writeInt(&buf, Int32(5)) FfiConverterString.write(message, into: &buf) case let .PaymentSendingFailed(message): writeInt(&buf, Int32(6)) FfiConverterString.write(message, into: &buf) case let .ChannelCreationFailed(message): writeInt(&buf, Int32(7)) FfiConverterString.write(message, into: &buf) case let .ChannelClosingFailed(message): writeInt(&buf, Int32(8)) FfiConverterString.write(message, into: &buf) case let .ChannelConfigUpdateFailed(message): writeInt(&buf, Int32(9)) FfiConverterString.write(message, into: &buf) case let .PersistenceFailed(message): writeInt(&buf, Int32(10)) FfiConverterString.write(message, into: &buf) case let .WalletOperationFailed(message): writeInt(&buf, Int32(11)) FfiConverterString.write(message, into: &buf) case let .OnchainTxSigningFailed(message): writeInt(&buf, Int32(12)) FfiConverterString.write(message, into: &buf) case let .MessageSigningFailed(message): writeInt(&buf, Int32(13)) FfiConverterString.write(message, into: &buf) case let .TxSyncFailed(message): writeInt(&buf, Int32(14)) FfiConverterString.write(message, into: &buf) case let .GossipUpdateFailed(message): writeInt(&buf, Int32(15)) FfiConverterString.write(message, into: &buf) case let .InvalidAddress(message): writeInt(&buf, Int32(16)) FfiConverterString.write(message, into: &buf) case let .InvalidNetAddress(message): writeInt(&buf, Int32(17)) FfiConverterString.write(message, into: &buf) case let .InvalidPublicKey(message): writeInt(&buf, Int32(18)) FfiConverterString.write(message, into: &buf) case let .InvalidSecretKey(message): writeInt(&buf, Int32(19)) FfiConverterString.write(message, into: &buf) case let .InvalidPaymentHash(message): writeInt(&buf, Int32(20)) FfiConverterString.write(message, into: &buf) case let .InvalidPaymentPreimage(message): writeInt(&buf, Int32(21)) FfiConverterString.write(message, into: &buf) case let .InvalidPaymentSecret(message): writeInt(&buf, Int32(22)) FfiConverterString.write(message, into: &buf) case let .InvalidAmount(message): writeInt(&buf, Int32(23)) FfiConverterString.write(message, into: &buf) case let .InvalidInvoice(message): writeInt(&buf, Int32(24)) FfiConverterString.write(message, into: &buf) case let .InvalidChannelId(message): writeInt(&buf, Int32(25)) FfiConverterString.write(message, into: &buf) case let .InvalidNetwork(message): writeInt(&buf, Int32(26)) FfiConverterString.write(message, into: &buf) case let .DuplicatePayment(message): writeInt(&buf, Int32(27)) FfiConverterString.write(message, into: &buf) case let .InsufficientFunds(message): writeInt(&buf, Int32(28)) FfiConverterString.write(message, into: &buf) } } } extension NodeError: Equatable, Hashable {} extension NodeError: Error {} private 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 } } } private 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 } } } private 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 } } } private 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 } } } private struct FfiConverterOptionTypeChannelConfig: FfiConverterRustBuffer { typealias SwiftType = ChannelConfig? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypeChannelConfig.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 FfiConverterTypeChannelConfig.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private struct FfiConverterOptionTypeOutPoint: FfiConverterRustBuffer { typealias SwiftType = OutPoint? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypeOutPoint.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 FfiConverterTypeOutPoint.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private struct FfiConverterOptionTypePaymentDetails: FfiConverterRustBuffer { typealias SwiftType = PaymentDetails? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypePaymentDetails.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 FfiConverterTypePaymentDetails.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private 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 } } } private struct FfiConverterOptionTypeNetAddress: FfiConverterRustBuffer { typealias SwiftType = NetAddress? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypeNetAddress.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 FfiConverterTypeNetAddress.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private struct FfiConverterOptionTypePaymentPreimage: FfiConverterRustBuffer { typealias SwiftType = PaymentPreimage? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypePaymentPreimage.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 FfiConverterTypePaymentPreimage.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private struct FfiConverterOptionTypePaymentSecret: FfiConverterRustBuffer { typealias SwiftType = PaymentSecret? public static func write(_ value: SwiftType, into buf: inout [UInt8]) { guard let value = value else { writeInt(&buf, Int8(0)) return } writeInt(&buf, Int8(1)) FfiConverterTypePaymentSecret.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 FfiConverterTypePaymentSecret.read(from: &buf) default: throw UniffiInternalError.unexpectedOptionalTag } } } private struct FfiConverterSequenceUInt8: FfiConverterRustBuffer { typealias SwiftType = [UInt8] public static func write(_ value: [UInt8], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) for item in value { FfiConverterUInt8.write(item, into: &buf) } } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [UInt8] { let len: Int32 = try readInt(&buf) var seq = [UInt8]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { seq.append(try FfiConverterUInt8.read(from: &buf)) } return seq } } private 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 } } private struct FfiConverterSequenceTypePaymentDetails: FfiConverterRustBuffer { typealias SwiftType = [PaymentDetails] public static func write(_ value: [PaymentDetails], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) for item in value { FfiConverterTypePaymentDetails.write(item, into: &buf) } } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [PaymentDetails] { let len: Int32 = try readInt(&buf) var seq = [PaymentDetails]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { seq.append(try FfiConverterTypePaymentDetails.read(from: &buf)) } return seq } } private struct FfiConverterSequenceTypePeerDetails: FfiConverterRustBuffer { typealias SwiftType = [PeerDetails] public static func write(_ value: [PeerDetails], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) for item in value { FfiConverterTypePeerDetails.write(item, into: &buf) } } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [PeerDetails] { let len: Int32 = try readInt(&buf) var seq = [PeerDetails]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { seq.append(try FfiConverterTypePeerDetails.read(from: &buf)) } return seq } } private struct FfiConverterSequenceTypePublicKey: FfiConverterRustBuffer { typealias SwiftType = [PublicKey] public static func write(_ value: [PublicKey], into buf: inout [UInt8]) { let len = Int32(value.count) writeInt(&buf, len) for item in value { FfiConverterTypePublicKey.write(item, into: &buf) } } public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> [PublicKey] { let len: Int32 = try readInt(&buf) var seq = [PublicKey]() seq.reserveCapacity(Int(len)) for _ in 0 ..< len { seq.append(try FfiConverterTypePublicKey.read(from: &buf)) } return seq } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias Address = String public struct FfiConverterTypeAddress: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Address { return try FfiConverterString.read(from: &buf) } public static func write(_ value: Address, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> Address { return try FfiConverterString.lift(value) } public static func lower(_ value: Address) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias ChannelId = String public struct FfiConverterTypeChannelId: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ChannelId { return try FfiConverterString.read(from: &buf) } public static func write(_ value: ChannelId, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> ChannelId { return try FfiConverterString.lift(value) } public static func lower(_ value: ChannelId) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias Invoice = String public struct FfiConverterTypeInvoice: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Invoice { return try FfiConverterString.read(from: &buf) } public static func write(_ value: Invoice, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> Invoice { return try FfiConverterString.lift(value) } public static func lower(_ value: Invoice) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias Mnemonic = String public struct FfiConverterTypeMnemonic: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Mnemonic { return try FfiConverterString.read(from: &buf) } public static func write(_ value: Mnemonic, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> Mnemonic { return try FfiConverterString.lift(value) } public static func lower(_ value: Mnemonic) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias NetAddress = String public struct FfiConverterTypeNetAddress: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> NetAddress { return try FfiConverterString.read(from: &buf) } public static func write(_ value: NetAddress, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> NetAddress { return try FfiConverterString.lift(value) } public static func lower(_ value: NetAddress) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias PaymentHash = String public struct FfiConverterTypePaymentHash: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentHash { return try FfiConverterString.read(from: &buf) } public static func write(_ value: PaymentHash, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> PaymentHash { return try FfiConverterString.lift(value) } public static func lower(_ value: PaymentHash) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias PaymentPreimage = String public struct FfiConverterTypePaymentPreimage: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentPreimage { return try FfiConverterString.read(from: &buf) } public static func write(_ value: PaymentPreimage, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> PaymentPreimage { return try FfiConverterString.lift(value) } public static func lower(_ value: PaymentPreimage) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias PaymentSecret = String public struct FfiConverterTypePaymentSecret: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PaymentSecret { return try FfiConverterString.read(from: &buf) } public static func write(_ value: PaymentSecret, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> PaymentSecret { return try FfiConverterString.lift(value) } public static func lower(_ value: PaymentSecret) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias PublicKey = String public struct FfiConverterTypePublicKey: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> PublicKey { return try FfiConverterString.read(from: &buf) } public static func write(_ value: PublicKey, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> PublicKey { return try FfiConverterString.lift(value) } public static func lower(_ value: PublicKey) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias Txid = String public struct FfiConverterTypeTxid: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Txid { return try FfiConverterString.read(from: &buf) } public static func write(_ value: Txid, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> Txid { return try FfiConverterString.lift(value) } public static func lower(_ value: Txid) -> RustBuffer { return FfiConverterString.lower(value) } } /** * Typealias from the type name used in the UDL file to the builtin type. This * is needed because the UDL type name is used in function/method signatures. */ public typealias UserChannelId = String public struct FfiConverterTypeUserChannelId: FfiConverter { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UserChannelId { return try FfiConverterString.read(from: &buf) } public static func write(_ value: UserChannelId, into buf: inout [UInt8]) { return FfiConverterString.write(value, into: &buf) } public static func lift(_ value: RustBuffer) throws -> UserChannelId { return try FfiConverterString.lift(value) } public static func lower(_ value: UserChannelId) -> RustBuffer { return FfiConverterString.lower(value) } } public func generateEntropyMnemonic() -> Mnemonic { return try! FfiConverterTypeMnemonic.lift( try! rustCall { ldk_node_3490_generate_entropy_mnemonic($0) } ) } /** * Top level initializers and tear down methods. * * This is generated by uniffi. */ public enum LdkNodeLifecycle { /** * Initialize the FFI and Rust library. This should be only called once per application. */ func initialize() {} }