diff --git a/CHANGELOG.md b/CHANGELOG.md index d92039872..953ab1afb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 0.7.0-rc.32 (Synonym Fork) +# 0.7.0-rc.33 (Synonym Fork) ## Bug Fixes @@ -29,6 +29,14 @@ ## Synonym Fork Additions +- Added `connection_timeout_secs` field to `ElectrumSyncConfig` (default: 10 s). This bounds + Electrum socket operations for both the BDK on-chain and LDK tx-sync clients, preventing Tokio's + blocking thread pool from being exhausted by threads stuck on dead sockets under total packet + loss (e.g. a captive portal on iOS). Set to `0` to disable; values above 255 are capped to + 255 and a warning is logged. + **Breaking change:** existing struct-literal construction of `ElectrumSyncConfig` must add the + new field or switch to `ElectrumSyncConfig { .., ..Default::default() }`. + - Added `OnchainPayment::calculate_send_all_fee()` to preview the fee for a drain / send-all transaction before broadcasting (fee-calculation counterpart of `send_all_to_address`) - Added runtime APIs for dynamic address type management: diff --git a/Cargo.toml b/Cargo.toml index 515bcbcd2..077b4c6d7 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ exclude = ["bindings/uniffi-bindgen"] [package] name = "ldk-node" -version = "0.7.0-rc.32" +version = "0.7.0-rc.33" authors = ["Elias Rohrer "] homepage = "https://lightningdevkit.org/" license = "MIT OR Apache-2.0" diff --git a/Package.swift b/Package.swift index 0d5a264ab..73c1fef8e 100644 --- a/Package.swift +++ b/Package.swift @@ -3,8 +3,8 @@ import PackageDescription -let tag = "v0.7.0-rc.32" -let checksum = "89d987f390e0f8fae370c6d549aacd8b8e1c3c95fb0d6e9ccfcf216cbd263b38" +let tag = "v0.7.0-rc.33" +let checksum = "82e318ac605e04d87f1aa24c920c06627346d9500c6395db45cb23f159e200f0" let url = "https://github.com/synonymdev/ldk-node/releases/download/\(tag)/LDKNodeFFI.xcframework.zip" let package = Package( diff --git a/bindgen.sh b/bindgen.sh old mode 100644 new mode 100755 diff --git a/bindings/kotlin/ldk-node-android/gradle.properties b/bindings/kotlin/ldk-node-android/gradle.properties index 63a32f40e..456d7a65e 100644 --- a/bindings/kotlin/ldk-node-android/gradle.properties +++ b/bindings/kotlin/ldk-node-android/gradle.properties @@ -3,4 +3,4 @@ android.useAndroidX=true android.enableJetifier=true kotlin.code.style=official group=com.synonym -version=0.7.0-rc.32 +version=0.7.0-rc.33 diff --git a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/arm64-v8a/libldk_node.so b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/arm64-v8a/libldk_node.so index 8fa9afdaf..a3c890372 100755 Binary files a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/arm64-v8a/libldk_node.so and b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/arm64-v8a/libldk_node.so differ diff --git a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/armeabi-v7a/libldk_node.so b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/armeabi-v7a/libldk_node.so index 0b00d1b89..e3422f752 100755 Binary files a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/armeabi-v7a/libldk_node.so and b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/armeabi-v7a/libldk_node.so differ diff --git a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/x86_64/libldk_node.so b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/x86_64/libldk_node.so index ec2a5a8e6..3edb943db 100755 Binary files a/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/x86_64/libldk_node.so and b/bindings/kotlin/ldk-node-android/lib/src/main/jniLibs/x86_64/libldk_node.so differ diff --git a/bindings/kotlin/ldk-node-android/lib/src/main/kotlin/org/lightningdevkit/ldknode/ldk_node.android.kt b/bindings/kotlin/ldk-node-android/lib/src/main/kotlin/org/lightningdevkit/ldknode/ldk_node.android.kt index 7503d693a..d066f53c8 100644 --- a/bindings/kotlin/ldk-node-android/lib/src/main/kotlin/org/lightningdevkit/ldknode/ldk_node.android.kt +++ b/bindings/kotlin/ldk-node-android/lib/src/main/kotlin/org/lightningdevkit/ldknode/ldk_node.android.kt @@ -9459,15 +9459,18 @@ object FfiConverterTypeElectrumSyncConfig: FfiConverterRustBuffer (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. +// 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 { @@ -96,8 +96,8 @@ private func readInt(_ reader: inout (data: Data, offset: return value.bigEndian } -/// Reads an arbitrary number of bytes, to be used to read -/// raw bytes, this is useful when lifting strings +// 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 { @@ -111,17 +111,17 @@ private func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: return value } -/// Reads a float at the current offset. +// Reads a float at the current offset. private func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float { return try Float(bitPattern: readInt(&reader)) } -/// Reads a float at the current offset. +// Reads a float at the current offset. private func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double { return try Double(bitPattern: readInt(&reader)) } -/// Indicates if the offset has reached the end of the buffer. +// 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 } @@ -134,14 +134,14 @@ private func createWriter() -> [UInt8] { return [] } -private func writeBytes(_ writer: inout [UInt8], _ byteArr: S) where S.Element == UInt8 { +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! +// 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) } @@ -155,8 +155,8 @@ 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 to the Rust trait of the same name. +// Protocol for types that transfer other types across the FFI. This is +// analogous to the Rust trait of the same name. private protocol FfiConverter { associatedtype FfiType associatedtype SwiftType @@ -167,7 +167,7 @@ private protocol FfiConverter { static func write(_ value: SwiftType, into buf: inout [UInt8]) } -/// Types conforming to `Primitive` pass themselves directly over the FFI. +// Types conforming to `Primitive` pass themselves directly over the FFI. private protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType {} extension FfiConverterPrimitive { @@ -186,8 +186,8 @@ extension FfiConverterPrimitive { } } -/// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`. -/// Used for complex types where it's hard to write a custom lift/lower. +// 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 { @@ -214,8 +214,8 @@ extension FfiConverterRustBuffer { } } -/// An error type for FFI errors. These errors occur at the UniFFI level, not -/// the library level. +// 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 @@ -601,7 +601,7 @@ open class Bolt11Invoice: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -862,7 +862,7 @@ open class Bolt11Payment: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -906,13 +906,12 @@ open class Bolt11Payment: try! rustCall { uniffi_ldk_node_fn_free_bolt11payment(pointer, $0) } } - open func claimForHash(paymentHash: PaymentHash, claimableAmountMsat: UInt64, preimage: PaymentPreimage) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_bolt11payment_claim_for_hash(self.uniffiClonePointer(), - FfiConverterTypePaymentHash.lower(paymentHash), - FfiConverterUInt64.lower(claimableAmountMsat), - FfiConverterTypePaymentPreimage.lower(preimage), $0) - } + open func claimForHash(paymentHash: PaymentHash, claimableAmountMsat: UInt64, preimage: PaymentPreimage) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_claim_for_hash(self.uniffiClonePointer(), + FfiConverterTypePaymentHash.lower(paymentHash), + FfiConverterUInt64.lower(claimableAmountMsat), + FfiConverterTypePaymentPreimage.lower(preimage), $0) + } } open func estimateRoutingFees(invoice: Bolt11Invoice) throws -> UInt64 { @@ -930,11 +929,10 @@ open class Bolt11Payment: }) } - open func failForHash(paymentHash: PaymentHash) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_bolt11payment_fail_for_hash(self.uniffiClonePointer(), - FfiConverterTypePaymentHash.lower(paymentHash), $0) - } + open func failForHash(paymentHash: PaymentHash) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_fail_for_hash(self.uniffiClonePointer(), + FfiConverterTypePaymentHash.lower(paymentHash), $0) + } } open func receive(amountMsat: UInt64, description: Bolt11InvoiceDescription, expirySecs: UInt32) throws -> Bolt11Invoice { @@ -1021,21 +1019,19 @@ open class Bolt11Payment: }) } - open func sendProbes(invoice: Bolt11Invoice, routeParameters: RouteParametersConfig?) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_bolt11payment_send_probes(self.uniffiClonePointer(), - FfiConverterTypeBolt11Invoice.lower(invoice), - FfiConverterOptionTypeRouteParametersConfig.lower(routeParameters), $0) - } + open func sendProbes(invoice: Bolt11Invoice, routeParameters: RouteParametersConfig?) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_send_probes(self.uniffiClonePointer(), + FfiConverterTypeBolt11Invoice.lower(invoice), + FfiConverterOptionTypeRouteParametersConfig.lower(routeParameters), $0) + } } - open func sendProbesUsingAmount(invoice: Bolt11Invoice, amountMsat: UInt64, routeParameters: RouteParametersConfig?) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_bolt11payment_send_probes_using_amount(self.uniffiClonePointer(), - FfiConverterTypeBolt11Invoice.lower(invoice), - FfiConverterUInt64.lower(amountMsat), - FfiConverterOptionTypeRouteParametersConfig.lower(routeParameters), $0) - } + open func sendProbesUsingAmount(invoice: Bolt11Invoice, amountMsat: UInt64, routeParameters: RouteParametersConfig?) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt11payment_send_probes_using_amount(self.uniffiClonePointer(), + FfiConverterTypeBolt11Invoice.lower(invoice), + FfiConverterUInt64.lower(amountMsat), + FfiConverterOptionTypeRouteParametersConfig.lower(routeParameters), $0) + } } open func sendUsingAmount(invoice: Bolt11Invoice, amountMsat: UInt64, routeParameters: RouteParametersConfig?) throws -> PaymentId { @@ -1142,7 +1138,7 @@ open class Bolt12Invoice: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1387,7 +1383,7 @@ open class Bolt12Payment: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1501,11 +1497,10 @@ open class Bolt12Payment: }) } - open func setPathsToStaticInvoiceServer(paths: Data) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_bolt12payment_set_paths_to_static_invoice_server(self.uniffiClonePointer(), - FfiConverterData.lower(paths), $0) - } + open func setPathsToStaticInvoiceServer(paths: Data) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_bolt12payment_set_paths_to_static_invoice_server(self.uniffiClonePointer(), + FfiConverterData.lower(paths), $0) + } } } @@ -1621,7 +1616,7 @@ open class Builder: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -1658,7 +1653,8 @@ open class Builder: public convenience init() { let pointer = try! rustCall { - uniffi_ldk_node_fn_constructor_builder_new($0) + uniffi_ldk_node_fn_constructor_builder_new($0 + ) } self.init(unsafeFromRawPointer: pointer) } @@ -1719,186 +1715,162 @@ open class Builder: }) } - open func setAddressType(addressType: AddressType) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_address_type(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), $0) - } + open func setAddressType(addressType: AddressType) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_address_type(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), $0) + } } - open func setAddressTypesToMonitor(addressTypesToMonitor: [AddressType]) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_address_types_to_monitor(self.uniffiClonePointer(), - FfiConverterSequenceTypeAddressType.lower(addressTypesToMonitor), $0) - } + open func setAddressTypesToMonitor(addressTypesToMonitor: [AddressType]) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_address_types_to_monitor(self.uniffiClonePointer(), + FfiConverterSequenceTypeAddressType.lower(addressTypesToMonitor), $0) + } } - open func setAnnouncementAddresses(announcementAddresses: [SocketAddress]) throws { - try rustCallWithError(FfiConverterTypeBuildError.lift) { - uniffi_ldk_node_fn_method_builder_set_announcement_addresses(self.uniffiClonePointer(), - FfiConverterSequenceTypeSocketAddress.lower(announcementAddresses), $0) - } + open func setAnnouncementAddresses(announcementAddresses: [SocketAddress]) throws { try rustCallWithError(FfiConverterTypeBuildError.lift) { + uniffi_ldk_node_fn_method_builder_set_announcement_addresses(self.uniffiClonePointer(), + FfiConverterSequenceTypeSocketAddress.lower(announcementAddresses), $0) + } } - open func setAsyncPaymentsRole(role: AsyncPaymentsRole?) throws { - try rustCallWithError(FfiConverterTypeBuildError.lift) { - uniffi_ldk_node_fn_method_builder_set_async_payments_role(self.uniffiClonePointer(), - FfiConverterOptionTypeAsyncPaymentsRole.lower(role), $0) - } + open func setAsyncPaymentsRole(role: AsyncPaymentsRole?) throws { try rustCallWithError(FfiConverterTypeBuildError.lift) { + uniffi_ldk_node_fn_method_builder_set_async_payments_role(self.uniffiClonePointer(), + FfiConverterOptionTypeAsyncPaymentsRole.lower(role), $0) + } } - open func setChainSourceBitcoindRest(restHost: String, restPort: UInt16, rpcHost: String, rpcPort: UInt16, rpcUser: String, rpcPassword: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_chain_source_bitcoind_rest(self.uniffiClonePointer(), - FfiConverterString.lower(restHost), - FfiConverterUInt16.lower(restPort), - FfiConverterString.lower(rpcHost), - FfiConverterUInt16.lower(rpcPort), - FfiConverterString.lower(rpcUser), - FfiConverterString.lower(rpcPassword), $0) - } + open func setChainSourceBitcoindRest(restHost: String, restPort: UInt16, rpcHost: String, rpcPort: UInt16, rpcUser: String, rpcPassword: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_chain_source_bitcoind_rest(self.uniffiClonePointer(), + FfiConverterString.lower(restHost), + FfiConverterUInt16.lower(restPort), + FfiConverterString.lower(rpcHost), + FfiConverterUInt16.lower(rpcPort), + FfiConverterString.lower(rpcUser), + FfiConverterString.lower(rpcPassword), $0) + } } - open func setChainSourceBitcoindRpc(rpcHost: String, rpcPort: UInt16, rpcUser: String, rpcPassword: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_chain_source_bitcoind_rpc(self.uniffiClonePointer(), - FfiConverterString.lower(rpcHost), - FfiConverterUInt16.lower(rpcPort), - FfiConverterString.lower(rpcUser), - FfiConverterString.lower(rpcPassword), $0) - } + open func setChainSourceBitcoindRpc(rpcHost: String, rpcPort: UInt16, rpcUser: String, rpcPassword: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_chain_source_bitcoind_rpc(self.uniffiClonePointer(), + FfiConverterString.lower(rpcHost), + FfiConverterUInt16.lower(rpcPort), + FfiConverterString.lower(rpcUser), + FfiConverterString.lower(rpcPassword), $0) + } } - open func setChainSourceElectrum(serverUrl: String, config: ElectrumSyncConfig?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_chain_source_electrum(self.uniffiClonePointer(), - FfiConverterString.lower(serverUrl), - FfiConverterOptionTypeElectrumSyncConfig.lower(config), $0) - } + open func setChainSourceElectrum(serverUrl: String, config: ElectrumSyncConfig?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_chain_source_electrum(self.uniffiClonePointer(), + FfiConverterString.lower(serverUrl), + FfiConverterOptionTypeElectrumSyncConfig.lower(config), $0) + } } - open func setChainSourceEsplora(serverUrl: String, config: EsploraSyncConfig?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_chain_source_esplora(self.uniffiClonePointer(), - FfiConverterString.lower(serverUrl), - FfiConverterOptionTypeEsploraSyncConfig.lower(config), $0) - } + open func setChainSourceEsplora(serverUrl: String, config: EsploraSyncConfig?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_chain_source_esplora(self.uniffiClonePointer(), + FfiConverterString.lower(serverUrl), + FfiConverterOptionTypeEsploraSyncConfig.lower(config), $0) + } } - open func setChannelDataMigration(migration: ChannelDataMigration) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_channel_data_migration(self.uniffiClonePointer(), - FfiConverterTypeChannelDataMigration.lower(migration), $0) - } + open func setChannelDataMigration(migration: ChannelDataMigration) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_channel_data_migration(self.uniffiClonePointer(), + FfiConverterTypeChannelDataMigration.lower(migration), $0) + } } - open func setCustomLogger(logWriter: LogWriter) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_custom_logger(self.uniffiClonePointer(), - FfiConverterTypeLogWriter.lower(logWriter), $0) - } + open func setCustomLogger(logWriter: LogWriter) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_custom_logger(self.uniffiClonePointer(), + FfiConverterTypeLogWriter.lower(logWriter), $0) + } } - open func setEntropyBip39Mnemonic(mnemonic: Mnemonic, passphrase: String?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_entropy_bip39_mnemonic(self.uniffiClonePointer(), - FfiConverterTypeMnemonic.lower(mnemonic), - FfiConverterOptionString.lower(passphrase), $0) - } + open func setEntropyBip39Mnemonic(mnemonic: Mnemonic, passphrase: String?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_entropy_bip39_mnemonic(self.uniffiClonePointer(), + FfiConverterTypeMnemonic.lower(mnemonic), + FfiConverterOptionString.lower(passphrase), $0) + } } - open func setEntropySeedBytes(seedBytes: [UInt8]) throws { - try rustCallWithError(FfiConverterTypeBuildError.lift) { - uniffi_ldk_node_fn_method_builder_set_entropy_seed_bytes(self.uniffiClonePointer(), - FfiConverterSequenceUInt8.lower(seedBytes), $0) - } + open func setEntropySeedBytes(seedBytes: [UInt8]) throws { try rustCallWithError(FfiConverterTypeBuildError.lift) { + uniffi_ldk_node_fn_method_builder_set_entropy_seed_bytes(self.uniffiClonePointer(), + FfiConverterSequenceUInt8.lower(seedBytes), $0) + } } - open func setEntropySeedPath(seedPath: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_entropy_seed_path(self.uniffiClonePointer(), - FfiConverterString.lower(seedPath), $0) - } + open func setEntropySeedPath(seedPath: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_entropy_seed_path(self.uniffiClonePointer(), + FfiConverterString.lower(seedPath), $0) + } } - open func setFilesystemLogger(logFilePath: String?, maxLogLevel: LogLevel?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_filesystem_logger(self.uniffiClonePointer(), - FfiConverterOptionString.lower(logFilePath), - FfiConverterOptionTypeLogLevel.lower(maxLogLevel), $0) - } + open func setFilesystemLogger(logFilePath: String?, maxLogLevel: LogLevel?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_filesystem_logger(self.uniffiClonePointer(), + FfiConverterOptionString.lower(logFilePath), + FfiConverterOptionTypeLogLevel.lower(maxLogLevel), $0) + } } - open func setGossipSourceP2p() { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_gossip_source_p2p(self.uniffiClonePointer(), $0) - } + open func setGossipSourceP2p() { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_gossip_source_p2p(self.uniffiClonePointer(), $0) + } } - open func setGossipSourceRgs(rgsServerUrl: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_gossip_source_rgs(self.uniffiClonePointer(), - FfiConverterString.lower(rgsServerUrl), $0) - } + open func setGossipSourceRgs(rgsServerUrl: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_gossip_source_rgs(self.uniffiClonePointer(), + FfiConverterString.lower(rgsServerUrl), $0) + } } - open func setLiquiditySourceLsps1(nodeId: PublicKey, address: SocketAddress, token: String?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_liquidity_source_lsps1(self.uniffiClonePointer(), - FfiConverterTypePublicKey.lower(nodeId), - FfiConverterTypeSocketAddress.lower(address), - FfiConverterOptionString.lower(token), $0) - } + open func setLiquiditySourceLsps1(nodeId: PublicKey, address: SocketAddress, token: String?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_liquidity_source_lsps1(self.uniffiClonePointer(), + FfiConverterTypePublicKey.lower(nodeId), + FfiConverterTypeSocketAddress.lower(address), + FfiConverterOptionString.lower(token), $0) + } } - open func setLiquiditySourceLsps2(nodeId: PublicKey, address: SocketAddress, token: String?) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_liquidity_source_lsps2(self.uniffiClonePointer(), - FfiConverterTypePublicKey.lower(nodeId), - FfiConverterTypeSocketAddress.lower(address), - FfiConverterOptionString.lower(token), $0) - } + open func setLiquiditySourceLsps2(nodeId: PublicKey, address: SocketAddress, token: String?) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_liquidity_source_lsps2(self.uniffiClonePointer(), + FfiConverterTypePublicKey.lower(nodeId), + FfiConverterTypeSocketAddress.lower(address), + FfiConverterOptionString.lower(token), $0) + } } - open func setListeningAddresses(listeningAddresses: [SocketAddress]) throws { - try rustCallWithError(FfiConverterTypeBuildError.lift) { - uniffi_ldk_node_fn_method_builder_set_listening_addresses(self.uniffiClonePointer(), - FfiConverterSequenceTypeSocketAddress.lower(listeningAddresses), $0) - } + open func setListeningAddresses(listeningAddresses: [SocketAddress]) throws { try rustCallWithError(FfiConverterTypeBuildError.lift) { + uniffi_ldk_node_fn_method_builder_set_listening_addresses(self.uniffiClonePointer(), + FfiConverterSequenceTypeSocketAddress.lower(listeningAddresses), $0) + } } - open func setLogFacadeLogger() { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_log_facade_logger(self.uniffiClonePointer(), $0) - } + open func setLogFacadeLogger() { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_log_facade_logger(self.uniffiClonePointer(), $0) + } } - open func setNetwork(network: Network) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_network(self.uniffiClonePointer(), - FfiConverterTypeNetwork.lower(network), $0) - } + open func setNetwork(network: Network) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_network(self.uniffiClonePointer(), + FfiConverterTypeNetwork.lower(network), $0) + } } - open func setNodeAlias(nodeAlias: String) throws { - try rustCallWithError(FfiConverterTypeBuildError.lift) { - uniffi_ldk_node_fn_method_builder_set_node_alias(self.uniffiClonePointer(), - FfiConverterString.lower(nodeAlias), $0) - } + open func setNodeAlias(nodeAlias: String) throws { try rustCallWithError(FfiConverterTypeBuildError.lift) { + uniffi_ldk_node_fn_method_builder_set_node_alias(self.uniffiClonePointer(), + FfiConverterString.lower(nodeAlias), $0) + } } - open func setPathfindingScoresSource(url: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_pathfinding_scores_source(self.uniffiClonePointer(), - FfiConverterString.lower(url), $0) - } + open func setPathfindingScoresSource(url: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_pathfinding_scores_source(self.uniffiClonePointer(), + FfiConverterString.lower(url), $0) + } } - open func setStorageDirPath(storageDirPath: String) { - try! rustCall { - uniffi_ldk_node_fn_method_builder_set_storage_dir_path(self.uniffiClonePointer(), - FfiConverterString.lower(storageDirPath), $0) - } + open func setStorageDirPath(storageDirPath: String) { try! rustCall { + uniffi_ldk_node_fn_method_builder_set_storage_dir_path(self.uniffiClonePointer(), + FfiConverterString.lower(storageDirPath), $0) + } } } @@ -1962,7 +1934,7 @@ open class FeeRate: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -2099,7 +2071,7 @@ open class Lsps1Liquidity: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -2217,7 +2189,7 @@ open class LogWriterImpl: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -2261,26 +2233,25 @@ open class LogWriterImpl: try! rustCall { uniffi_ldk_node_fn_free_logwriter(pointer, $0) } } - open func log(record: LogRecord) { - try! rustCall { - uniffi_ldk_node_fn_method_logwriter_log(self.uniffiClonePointer(), - FfiConverterTypeLogRecord.lower(record), $0) - } + open func log(record: LogRecord) { try! rustCall { + uniffi_ldk_node_fn_method_logwriter_log(self.uniffiClonePointer(), + FfiConverterTypeLogRecord.lower(record), $0) + } } } -/// Magic number for the Rust proxy to call using the same mechanism as every other method, -/// to free the callback once it's dropped by Rust. +// Magic number for the Rust proxy to call using the same mechanism as every other method, +// to free the callback once it's dropped by Rust. private let IDX_CALLBACK_FREE: Int32 = 0 // Callback return codes private let UNIFFI_CALLBACK_SUCCESS: Int32 = 0 private let UNIFFI_CALLBACK_ERROR: Int32 = 1 private let UNIFFI_CALLBACK_UNEXPECTED_ERROR: Int32 = 2 -/// Put the implementation in a struct so we don't pollute the top-level namespace +// Put the implementation in a struct so we don't pollute the top-level namespace private enum UniffiCallbackInterfaceLogWriter { - /// Create the VTable using a series of closures. - /// Swift automatically converts these into C callback functions. + // Create the VTable using a series of closures. + // Swift automatically converts these into C callback functions. static var vtable: UniffiVTableCallbackInterfaceLogWriter = .init( log: { ( uniffiHandle: UInt64, @@ -2385,7 +2356,7 @@ open class NetworkGraph: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -2608,7 +2579,7 @@ open class Node: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -2652,21 +2623,19 @@ open class Node: try! rustCall { uniffi_ldk_node_fn_free_node(pointer, $0) } } - open func addAddressTypeToMonitor(addressType: AddressType, seedBytes: [UInt8]) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_add_address_type_to_monitor(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), - FfiConverterSequenceUInt8.lower(seedBytes), $0) - } + open func addAddressTypeToMonitor(addressType: AddressType, seedBytes: [UInt8]) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_add_address_type_to_monitor(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), + FfiConverterSequenceUInt8.lower(seedBytes), $0) + } } - open func addAddressTypeToMonitorWithMnemonic(addressType: AddressType, mnemonic: Mnemonic, passphrase: String?) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_add_address_type_to_monitor_with_mnemonic(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), - FfiConverterTypeMnemonic.lower(mnemonic), - FfiConverterOptionString.lower(passphrase), $0) - } + open func addAddressTypeToMonitorWithMnemonic(addressType: AddressType, mnemonic: Mnemonic, passphrase: String?) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_add_address_type_to_monitor_with_mnemonic(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), + FfiConverterTypeMnemonic.lower(mnemonic), + FfiConverterOptionString.lower(passphrase), $0) + } } open func announcementAddresses() -> [SocketAddress]? { @@ -2687,12 +2656,11 @@ open class Node: }) } - open func closeChannel(userChannelId: UserChannelId, counterpartyNodeId: PublicKey) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_close_channel(self.uniffiClonePointer(), - FfiConverterTypeUserChannelId.lower(userChannelId), - FfiConverterTypePublicKey.lower(counterpartyNodeId), $0) - } + open func closeChannel(userChannelId: UserChannelId, counterpartyNodeId: PublicKey) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_close_channel(self.uniffiClonePointer(), + FfiConverterTypeUserChannelId.lower(userChannelId), + FfiConverterTypePublicKey.lower(counterpartyNodeId), $0) + } } open func config() -> Config { @@ -2701,13 +2669,12 @@ open class Node: }) } - open func connect(nodeId: PublicKey, address: SocketAddress, persist: Bool) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_connect(self.uniffiClonePointer(), - FfiConverterTypePublicKey.lower(nodeId), - FfiConverterTypeSocketAddress.lower(address), - FfiConverterBool.lower(persist), $0) - } + open func connect(nodeId: PublicKey, address: SocketAddress, persist: Bool) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_connect(self.uniffiClonePointer(), + FfiConverterTypePublicKey.lower(nodeId), + FfiConverterTypeSocketAddress.lower(address), + FfiConverterBool.lower(persist), $0) + } } open func currentSyncIntervals() -> RuntimeSyncIntervals { @@ -2716,17 +2683,15 @@ open class Node: }) } - open func disconnect(nodeId: PublicKey) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_disconnect(self.uniffiClonePointer(), - FfiConverterTypePublicKey.lower(nodeId), $0) - } + open func disconnect(nodeId: PublicKey) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_disconnect(self.uniffiClonePointer(), + FfiConverterTypePublicKey.lower(nodeId), $0) + } } - open func eventHandled() throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_event_handled(self.uniffiClonePointer(), $0) - } + open func eventHandled() throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_event_handled(self.uniffiClonePointer(), $0) + } } open func exportPathfindingScores() throws -> Data { @@ -2735,13 +2700,12 @@ open class Node: }) } - open func forceCloseChannel(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, reason: String?) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_force_close_channel(self.uniffiClonePointer(), - FfiConverterTypeUserChannelId.lower(userChannelId), - FfiConverterTypePublicKey.lower(counterpartyNodeId), - FfiConverterOptionString.lower(reason), $0) - } + open func forceCloseChannel(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, reason: String?) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_force_close_channel(self.uniffiClonePointer(), + FfiConverterTypeUserChannelId.lower(userChannelId), + FfiConverterTypePublicKey.lower(counterpartyNodeId), + FfiConverterOptionString.lower(reason), $0) + } } open func getAddressBalance(addressStr: String) throws -> UInt64 { @@ -2882,35 +2846,31 @@ open class Node: }) } - open func removeAddressTypeFromMonitor(addressType: AddressType) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_remove_address_type_from_monitor(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), $0) - } + open func removeAddressTypeFromMonitor(addressType: AddressType) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_remove_address_type_from_monitor(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), $0) + } } - open func removePayment(paymentId: PaymentId) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_remove_payment(self.uniffiClonePointer(), - FfiConverterTypePaymentId.lower(paymentId), $0) - } + open func removePayment(paymentId: PaymentId) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_remove_payment(self.uniffiClonePointer(), + FfiConverterTypePaymentId.lower(paymentId), $0) + } } - open func setPrimaryAddressType(addressType: AddressType, seedBytes: [UInt8]) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_set_primary_address_type(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), - FfiConverterSequenceUInt8.lower(seedBytes), $0) - } + open func setPrimaryAddressType(addressType: AddressType, seedBytes: [UInt8]) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_set_primary_address_type(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), + FfiConverterSequenceUInt8.lower(seedBytes), $0) + } } - open func setPrimaryAddressTypeWithMnemonic(addressType: AddressType, mnemonic: Mnemonic, passphrase: String?) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_set_primary_address_type_with_mnemonic(self.uniffiClonePointer(), - FfiConverterTypeAddressType.lower(addressType), - FfiConverterTypeMnemonic.lower(mnemonic), - FfiConverterOptionString.lower(passphrase), $0) - } + open func setPrimaryAddressTypeWithMnemonic(addressType: AddressType, mnemonic: Mnemonic, passphrase: String?) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_set_primary_address_type_with_mnemonic(self.uniffiClonePointer(), + FfiConverterTypeAddressType.lower(addressType), + FfiConverterTypeMnemonic.lower(mnemonic), + FfiConverterOptionString.lower(passphrase), $0) + } } open func signMessage(msg: [UInt8]) -> String { @@ -2920,23 +2880,21 @@ open class Node: }) } - open func spliceIn(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, spliceAmountSats: UInt64) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_splice_in(self.uniffiClonePointer(), - FfiConverterTypeUserChannelId.lower(userChannelId), - FfiConverterTypePublicKey.lower(counterpartyNodeId), - FfiConverterUInt64.lower(spliceAmountSats), $0) - } + open func spliceIn(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, spliceAmountSats: UInt64) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_splice_in(self.uniffiClonePointer(), + FfiConverterTypeUserChannelId.lower(userChannelId), + FfiConverterTypePublicKey.lower(counterpartyNodeId), + FfiConverterUInt64.lower(spliceAmountSats), $0) + } } - open func spliceOut(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, address: Address, spliceAmountSats: UInt64) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_splice_out(self.uniffiClonePointer(), - FfiConverterTypeUserChannelId.lower(userChannelId), - FfiConverterTypePublicKey.lower(counterpartyNodeId), - FfiConverterTypeAddress.lower(address), - FfiConverterUInt64.lower(spliceAmountSats), $0) - } + open func spliceOut(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, address: Address, spliceAmountSats: UInt64) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_splice_out(self.uniffiClonePointer(), + FfiConverterTypeUserChannelId.lower(userChannelId), + FfiConverterTypePublicKey.lower(counterpartyNodeId), + FfiConverterTypeAddress.lower(address), + FfiConverterUInt64.lower(spliceAmountSats), $0) + } } open func spontaneousPayment() -> SpontaneousPayment { @@ -2945,10 +2903,9 @@ open class Node: }) } - open func start() throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_start(self.uniffiClonePointer(), $0) - } + open func start() throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_start(self.uniffiClonePointer(), $0) + } } open func status() -> NodeStatus { @@ -2957,16 +2914,14 @@ open class Node: }) } - open func stop() throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_stop(self.uniffiClonePointer(), $0) - } + open func stop() throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_stop(self.uniffiClonePointer(), $0) + } } - open func syncWallets() throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_sync_wallets(self.uniffiClonePointer(), $0) - } + open func syncWallets() throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_sync_wallets(self.uniffiClonePointer(), $0) + } } open func unifiedQrPayment() -> UnifiedQrPayment { @@ -2975,20 +2930,18 @@ open class Node: }) } - open func updateChannelConfig(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, channelConfig: ChannelConfig) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_update_channel_config(self.uniffiClonePointer(), - FfiConverterTypeUserChannelId.lower(userChannelId), - FfiConverterTypePublicKey.lower(counterpartyNodeId), - FfiConverterTypeChannelConfig.lower(channelConfig), $0) - } + open func updateChannelConfig(userChannelId: UserChannelId, counterpartyNodeId: PublicKey, channelConfig: ChannelConfig) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_update_channel_config(self.uniffiClonePointer(), + FfiConverterTypeUserChannelId.lower(userChannelId), + FfiConverterTypePublicKey.lower(counterpartyNodeId), + FfiConverterTypeChannelConfig.lower(channelConfig), $0) + } } - open func updateSyncIntervals(intervals: RuntimeSyncIntervals) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_node_update_sync_intervals(self.uniffiClonePointer(), - FfiConverterTypeRuntimeSyncIntervals.lower(intervals), $0) - } + open func updateSyncIntervals(intervals: RuntimeSyncIntervals) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_node_update_sync_intervals(self.uniffiClonePointer(), + FfiConverterTypeRuntimeSyncIntervals.lower(intervals), $0) + } } open func verifySignature(msg: [UInt8], sig: String, pkey: PublicKey) -> Bool { @@ -3088,7 +3041,7 @@ open class Offer: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -3316,7 +3269,7 @@ open class OnchainPayment: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -3530,7 +3483,7 @@ open class Refund: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -3732,7 +3685,7 @@ open class SpontaneousPayment: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -3785,12 +3738,11 @@ open class SpontaneousPayment: }) } - open func sendProbes(amountMsat: UInt64, nodeId: PublicKey) throws { - try rustCallWithError(FfiConverterTypeNodeError.lift) { - uniffi_ldk_node_fn_method_spontaneouspayment_send_probes(self.uniffiClonePointer(), - FfiConverterUInt64.lower(amountMsat), - FfiConverterTypePublicKey.lower(nodeId), $0) - } + open func sendProbes(amountMsat: UInt64, nodeId: PublicKey) throws { try rustCallWithError(FfiConverterTypeNodeError.lift) { + uniffi_ldk_node_fn_method_spontaneouspayment_send_probes(self.uniffiClonePointer(), + FfiConverterUInt64.lower(amountMsat), + FfiConverterTypePublicKey.lower(nodeId), $0) + } } open func sendWithCustomTlvs(amountMsat: UInt64, nodeId: PublicKey, routeParameters: RouteParametersConfig?, customTlvs: [CustomTlvRecord]) throws -> PaymentId { @@ -3883,7 +3835,7 @@ open class UnifiedQrPayment: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -4001,7 +3953,7 @@ open class VssHeaderProvider: { fileprivate let pointer: UnsafeMutableRawPointer! - // Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. + /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly. #if swift(>=5.8) @_documentation(visibility: private) #endif @@ -4114,8 +4066,8 @@ public struct AddressTypeBalance { public var totalSats: UInt64 public var spendableSats: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(totalSats: UInt64, spendableSats: UInt64) { self.totalSats = totalSats self.spendableSats = spendableSats @@ -4175,8 +4127,8 @@ public struct AnchorChannelsConfig { public var trustedPeersNoReserve: [PublicKey] public var perChannelReserveSats: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(trustedPeersNoReserve: [PublicKey], perChannelReserveSats: UInt64) { self.trustedPeersNoReserve = trustedPeersNoReserve self.perChannelReserveSats = perChannelReserveSats @@ -4237,8 +4189,8 @@ public struct BackgroundSyncConfig { public var lightningWalletSyncIntervalSecs: UInt64 public var feeRateCacheUpdateIntervalSecs: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(onchainWalletSyncIntervalSecs: UInt64, lightningWalletSyncIntervalSecs: UInt64, feeRateCacheUpdateIntervalSecs: UInt64) { self.onchainWalletSyncIntervalSecs = onchainWalletSyncIntervalSecs self.lightningWalletSyncIntervalSecs = lightningWalletSyncIntervalSecs @@ -4309,8 +4261,8 @@ public struct BalanceDetails { public var lightningBalances: [LightningBalance] public var pendingBalancesFromChannelClosures: [PendingSweepBalance] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(totalOnchainBalanceSats: UInt64, spendableOnchainBalanceSats: UInt64, totalAnchorChannelsReserveSats: UInt64, totalLightningBalanceSats: UInt64, lightningBalances: [LightningBalance], pendingBalancesFromChannelClosures: [PendingSweepBalance]) { self.totalOnchainBalanceSats = totalOnchainBalanceSats self.spendableOnchainBalanceSats = spendableOnchainBalanceSats @@ -4398,8 +4350,8 @@ public struct BestBlock { public var blockHash: BlockHash public var height: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(blockHash: BlockHash, height: UInt32) { self.blockHash = blockHash self.height = height @@ -4463,8 +4415,8 @@ public struct ChannelConfig { public var forceCloseAvoidanceMaxFeeSatoshis: UInt64 public var acceptUnderpayingHtlcs: Bool - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(forwardingFeeProportionalMillionths: UInt32, forwardingFeeBaseMsat: UInt32, cltvExpiryDelta: UInt16, maxDustHtlcExposure: MaxDustHtlcExposure, forceCloseAvoidanceMaxFeeSatoshis: UInt64, acceptUnderpayingHtlcs: Bool) { self.forwardingFeeProportionalMillionths = forwardingFeeProportionalMillionths self.forwardingFeeBaseMsat = forwardingFeeBaseMsat @@ -4552,8 +4504,8 @@ public struct ChannelDataMigration { public var channelManager: [UInt8]? public var channelMonitors: [[UInt8]] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(channelManager: [UInt8]?, channelMonitors: [[UInt8]]) { self.channelManager = channelManager self.channelMonitors = channelMonitors @@ -4643,8 +4595,8 @@ public struct ChannelDetails { public var config: ChannelConfig public var claimableOnCloseSats: UInt64? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(channelId: ChannelId, counterpartyNodeId: PublicKey, fundingTxo: OutPoint?, shortChannelId: UInt64?, outboundScidAlias: UInt64?, inboundScidAlias: UInt64?, channelValueSats: UInt64, unspendablePunishmentReserve: UInt64?, userChannelId: UserChannelId, feerateSatPer1000Weight: UInt32, outboundCapacityMsat: UInt64, inboundCapacityMsat: UInt64, confirmationsRequired: UInt32?, confirmations: UInt32?, isOutbound: Bool, isChannelReady: Bool, isUsable: Bool, isAnnounced: Bool, cltvExpiryDelta: UInt16?, counterpartyUnspendablePunishmentReserve: UInt64, counterpartyOutboundHtlcMinimumMsat: UInt64?, counterpartyOutboundHtlcMaximumMsat: UInt64?, counterpartyForwardingInfoFeeBaseMsat: UInt32?, counterpartyForwardingInfoFeeProportionalMillionths: UInt32?, counterpartyForwardingInfoCltvExpiryDelta: UInt16?, nextOutboundHtlcLimitMsat: UInt64, nextOutboundHtlcMinimumMsat: UInt64, forceCloseSpendDelay: UInt16?, inboundHtlcMinimumMsat: UInt64, inboundHtlcMaximumMsat: UInt64?, config: ChannelConfig, claimableOnCloseSats: UInt64?) { self.channelId = channelId self.counterpartyNodeId = counterpartyNodeId @@ -4917,8 +4869,8 @@ public struct ChannelInfo { public var twoToOne: ChannelUpdateInfo? public var capacitySats: UInt64? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(nodeOne: NodeId, oneToTwo: ChannelUpdateInfo?, nodeTwo: NodeId, twoToOne: ChannelUpdateInfo?, capacitySats: UInt64?) { self.nodeOne = nodeOne self.oneToTwo = oneToTwo @@ -5003,8 +4955,8 @@ public struct ChannelUpdateInfo { public var htlcMaximumMsat: UInt64 public var fees: RoutingFees - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(lastUpdate: UInt32, enabled: Bool, cltvExpiryDelta: UInt16, htlcMinimumMsat: UInt64, htlcMaximumMsat: UInt64, fees: RoutingFees) { self.lastUpdate = lastUpdate self.enabled = enabled @@ -5102,8 +5054,8 @@ public struct Config { public var addressType: AddressType public var addressTypesToMonitor: [AddressType] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(storageDirPath: String, network: Network, listeningAddresses: [SocketAddress]?, announcementAddresses: [SocketAddress]?, nodeAlias: NodeAlias?, trustedPeers0conf: [PublicKey], probingLiquidityLimitMultiplier: UInt64, anchorChannelsConfig: AnchorChannelsConfig?, routeParameters: RouteParametersConfig?, includeUntrustedPendingInSpendable: Bool, addressType: AddressType, addressTypesToMonitor: [AddressType]) { self.storageDirPath = storageDirPath self.network = network @@ -5233,8 +5185,8 @@ public struct CustomTlvRecord { public var typeNum: UInt64 public var value: [UInt8] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(typeNum: UInt64, value: [UInt8]) { self.typeNum = typeNum self.value = value @@ -5292,11 +5244,13 @@ public func FfiConverterTypeCustomTlvRecord_lower(_ value: CustomTlvRecord) -> R public struct ElectrumSyncConfig { public var backgroundSyncConfig: BackgroundSyncConfig? + public var connectionTimeoutSecs: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. - public init(backgroundSyncConfig: BackgroundSyncConfig?) { + // Default memberwise initializers are never public by default, so we + // declare one manually. + public init(backgroundSyncConfig: BackgroundSyncConfig?, connectionTimeoutSecs: UInt64) { self.backgroundSyncConfig = backgroundSyncConfig + self.connectionTimeoutSecs = connectionTimeoutSecs } } @@ -5305,11 +5259,15 @@ extension ElectrumSyncConfig: Equatable, Hashable { if lhs.backgroundSyncConfig != rhs.backgroundSyncConfig { return false } + if lhs.connectionTimeoutSecs != rhs.connectionTimeoutSecs { + return false + } return true } public func hash(into hasher: inout Hasher) { hasher.combine(backgroundSyncConfig) + hasher.combine(connectionTimeoutSecs) } } @@ -5320,12 +5278,14 @@ public struct FfiConverterTypeElectrumSyncConfig: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ElectrumSyncConfig { return try ElectrumSyncConfig( - backgroundSyncConfig: FfiConverterOptionTypeBackgroundSyncConfig.read(from: &buf) + backgroundSyncConfig: FfiConverterOptionTypeBackgroundSyncConfig.read(from: &buf), + connectionTimeoutSecs: FfiConverterUInt64.read(from: &buf) ) } public static func write(_ value: ElectrumSyncConfig, into buf: inout [UInt8]) { FfiConverterOptionTypeBackgroundSyncConfig.write(value.backgroundSyncConfig, into: &buf) + FfiConverterUInt64.write(value.connectionTimeoutSecs, into: &buf) } } @@ -5346,8 +5306,8 @@ public func FfiConverterTypeElectrumSyncConfig_lower(_ value: ElectrumSyncConfig public struct EsploraSyncConfig { public var backgroundSyncConfig: BackgroundSyncConfig? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(backgroundSyncConfig: BackgroundSyncConfig?) { self.backgroundSyncConfig = backgroundSyncConfig } @@ -5400,8 +5360,8 @@ public struct LspFeeLimits { public var maxTotalOpeningFeeMsat: UInt64? public var maxProportionalOpeningFeePpmMsat: UInt64? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(maxTotalOpeningFeeMsat: UInt64?, maxProportionalOpeningFeePpmMsat: UInt64?) { self.maxTotalOpeningFeeMsat = maxTotalOpeningFeeMsat self.maxProportionalOpeningFeePpmMsat = maxProportionalOpeningFeePpmMsat @@ -5464,8 +5424,8 @@ public struct Lsps1Bolt11PaymentInfo { public var orderTotalSat: UInt64 public var invoice: Bolt11Invoice - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(state: Lsps1PaymentState, expiresAt: LspsDateTime, feeTotalSat: UInt64, orderTotalSat: UInt64, invoice: Bolt11Invoice) { self.state = state self.expiresAt = expiresAt @@ -5518,8 +5478,8 @@ public struct Lsps1ChannelInfo { public var fundingOutpoint: OutPoint public var expiresAt: LspsDateTime - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(fundedAt: LspsDateTime, fundingOutpoint: OutPoint, expiresAt: LspsDateTime) { self.fundedAt = fundedAt self.fundingOutpoint = fundingOutpoint @@ -5592,8 +5552,8 @@ public struct Lsps1OnchainPaymentInfo { public var minFeeFor0conf: FeeRate public var refundOnchainAddress: Address? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(state: Lsps1PaymentState, expiresAt: LspsDateTime, feeTotalSat: UInt64, orderTotalSat: UInt64, address: Address, minOnchainPaymentConfirmations: UInt16?, minFeeFor0conf: FeeRate, refundOnchainAddress: Address?) { self.state = state self.expiresAt = expiresAt @@ -5659,8 +5619,8 @@ public struct Lsps1OrderParams { public var token: String? public var announceChannel: Bool - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(lspBalanceSat: UInt64, clientBalanceSat: UInt64, requiredChannelConfirmations: UInt16, fundingConfirmsWithinBlocks: UInt16, channelExpiryBlocks: UInt32, token: String?, announceChannel: Bool) { self.lspBalanceSat = lspBalanceSat self.clientBalanceSat = clientBalanceSat @@ -5757,8 +5717,8 @@ public struct Lsps1OrderStatus { public var paymentOptions: Lsps1PaymentInfo public var channelState: Lsps1ChannelInfo? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(orderId: Lsps1OrderId, orderParams: Lsps1OrderParams, paymentOptions: Lsps1PaymentInfo, channelState: Lsps1ChannelInfo?) { self.orderId = orderId self.orderParams = orderParams @@ -5807,8 +5767,8 @@ public struct Lsps1PaymentInfo { public var bolt11: Lsps1Bolt11PaymentInfo? public var onchain: Lsps1OnchainPaymentInfo? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(bolt11: Lsps1Bolt11PaymentInfo?, onchain: Lsps1OnchainPaymentInfo?) { self.bolt11 = bolt11 self.onchain = onchain @@ -5859,8 +5819,8 @@ public struct Lsps2ServiceConfig { public var maxPaymentSizeMsat: UInt64 public var clientTrustsLsp: Bool - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(requireToken: String?, advertiseService: Bool, channelOpeningFeePpm: UInt32, channelOverProvisioningPpm: UInt32, minChannelOpeningFeeMsat: UInt64, minChannelLifetime: UInt32, maxClientToSelfDelay: UInt32, minPaymentSizeMsat: UInt64, maxPaymentSizeMsat: UInt64, clientTrustsLsp: Bool) { self.requireToken = requireToken self.advertiseService = advertiseService @@ -5978,8 +5938,8 @@ public struct LogRecord { public var modulePath: String public var line: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(level: LogLevel, args: String, modulePath: String, line: UInt32) { self.level = level self.args = args @@ -6054,8 +6014,8 @@ public struct NodeAnnouncementInfo { public var alias: String public var addresses: [SocketAddress] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(lastUpdate: UInt32, alias: String, addresses: [SocketAddress]) { self.lastUpdate = lastUpdate self.alias = alias @@ -6122,8 +6082,8 @@ public struct NodeInfo { public var channels: [UInt64] public var announcementInfo: NodeAnnouncementInfo? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(channels: [UInt64], announcementInfo: NodeAnnouncementInfo?) { self.channels = channels self.announcementInfo = announcementInfo @@ -6190,8 +6150,8 @@ public struct NodeStatus { public var latestNodeAnnouncementBroadcastTimestamp: UInt64? public var latestChannelMonitorArchivalHeight: UInt32? - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(isRunning: Bool, currentBestBlock: BestBlock, latestLightningWalletSyncTimestamp: UInt64?, latestOnchainWalletSyncTimestamp: UInt64?, latestFeeRateCacheUpdateTimestamp: UInt64?, latestRgsSnapshotTimestamp: UInt64?, latestPathfindingScoresSyncTimestamp: UInt64?, latestNodeAnnouncementBroadcastTimestamp: UInt64?, latestChannelMonitorArchivalHeight: UInt32?) { self.isRunning = isRunning self.currentBestBlock = currentBestBlock @@ -6300,8 +6260,8 @@ public struct OutPoint { public var txid: Txid public var vout: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // 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 @@ -6366,8 +6326,8 @@ public struct PaymentDetails { public var status: PaymentStatus public var latestUpdateTimestamp: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(id: PaymentId, kind: PaymentKind, amountMsat: UInt64?, feePaidMsat: UInt64?, direction: PaymentDirection, status: PaymentStatus, latestUpdateTimestamp: UInt64) { self.id = id self.kind = kind @@ -6464,8 +6424,8 @@ public struct PeerDetails { public var isPersisted: Bool public var isConnected: Bool - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(nodeId: PublicKey, address: SocketAddress, isPersisted: Bool, isConnected: Bool) { self.nodeId = nodeId self.address = address @@ -6543,8 +6503,8 @@ public struct RouteHintHop { public var htlcMaximumMsat: UInt64? public var fees: RoutingFees - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(srcNodeId: PublicKey, shortChannelId: UInt64, cltvExpiryDelta: UInt16, htlcMinimumMsat: UInt64?, htlcMaximumMsat: UInt64?, fees: RoutingFees) { self.srcNodeId = srcNodeId self.shortChannelId = shortChannelId @@ -6634,8 +6594,8 @@ public struct RouteParametersConfig { public var maxPathCount: UInt8 public var maxChannelSaturationPowerOfHalf: UInt8 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(maxTotalRoutingFeeMsat: UInt64?, maxTotalCltvExpiryDelta: UInt32, maxPathCount: UInt8, maxChannelSaturationPowerOfHalf: UInt8) { self.maxTotalRoutingFeeMsat = maxTotalRoutingFeeMsat self.maxTotalCltvExpiryDelta = maxTotalCltvExpiryDelta @@ -6709,8 +6669,8 @@ public struct RoutingFees { public var baseMsat: UInt32 public var proportionalMillionths: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(baseMsat: UInt32, proportionalMillionths: UInt32) { self.baseMsat = baseMsat self.proportionalMillionths = proportionalMillionths @@ -6771,8 +6731,8 @@ public struct RuntimeSyncIntervals { public var lightningWalletSyncIntervalSecs: UInt64 public var feeRateCacheUpdateIntervalSecs: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(onchainWalletSyncIntervalSecs: UInt64, lightningWalletSyncIntervalSecs: UInt64, feeRateCacheUpdateIntervalSecs: UInt64) { self.onchainWalletSyncIntervalSecs = onchainWalletSyncIntervalSecs self.lightningWalletSyncIntervalSecs = lightningWalletSyncIntervalSecs @@ -6839,8 +6799,8 @@ public struct SpendableUtxo { public var outpoint: OutPoint public var valueSats: UInt64 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(outpoint: OutPoint, valueSats: UInt64) { self.outpoint = outpoint self.valueSats = valueSats @@ -6901,8 +6861,8 @@ public struct TransactionDetails { public var inputs: [TxInput] public var outputs: [TxOutput] - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(amountSats: Int64, inputs: [TxInput], outputs: [TxOutput]) { self.amountSats = amountSats self.inputs = inputs @@ -6972,8 +6932,8 @@ public struct TxInput { public var witness: [String] public var sequence: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(txid: Txid, vout: UInt32, scriptsig: String, witness: [String], sequence: UInt32) { self.txid = txid self.vout = vout @@ -7057,8 +7017,8 @@ public struct TxOutput { public var value: Int64 public var n: UInt32 - /// Default memberwise initializers are never public by default, so we - /// declare one manually. + // Default memberwise initializers are never public by default, so we + // declare one manually. public init(scriptpubkey: String, scriptpubkeyType: String?, scriptpubkeyAddress: String?, value: Int64, n: UInt32) { self.scriptpubkey = scriptpubkey self.scriptpubkeyType = scriptpubkeyType @@ -7319,8 +7279,10 @@ extension BalanceSource: Equatable, Hashable {} // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum Bolt11InvoiceDescription { - case hash(hash: String) - case direct(description: String) + case hash(hash: String + ) + case direct(description: String + ) } #if swift(>=5.8) @@ -7332,9 +7294,11 @@ public struct FfiConverterTypeBolt11InvoiceDescription: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bolt11InvoiceDescription { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .hash(hash: FfiConverterString.read(from: &buf)) + case 1: return try .hash(hash: FfiConverterString.read(from: &buf) + ) - case 2: return try .direct(description: FfiConverterString.read(from: &buf)) + case 2: return try .direct(description: FfiConverterString.read(from: &buf) + ) default: throw UniffiInternalError.unexpectedEnumCase } @@ -7530,20 +7494,23 @@ extension BuildError: Foundation.LocalizedError { // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum ClosureReason { - case counterpartyForceClosed(peerMsg: UntrustedString) + case counterpartyForceClosed(peerMsg: UntrustedString + ) case holderForceClosed(broadcastedLatestTxn: Bool?, message: String) case legacyCooperativeClosure case counterpartyInitiatedCooperativeClosure case locallyInitiatedCooperativeClosure case commitmentTxConfirmed case fundingTimedOut - case processingError(err: String) + case processingError(err: String + ) case disconnectedPeer case outdatedChannelManager case counterpartyCoopClosedUnfundedChannel case locallyCoopClosedUnfundedChannel case fundingBatchClosure - case htlCsTimedOut(paymentHash: PaymentHash?) + case htlCsTimedOut(paymentHash: PaymentHash? + ) case peerFeerateTooLow(peerFeerateSatPerKw: UInt32, requiredFeerateSatPerKw: UInt32) } @@ -7556,7 +7523,8 @@ public struct FfiConverterTypeClosureReason: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ClosureReason { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .counterpartyForceClosed(peerMsg: FfiConverterTypeUntrustedString.read(from: &buf)) + case 1: return try .counterpartyForceClosed(peerMsg: FfiConverterTypeUntrustedString.read(from: &buf) + ) case 2: return try .holderForceClosed(broadcastedLatestTxn: FfiConverterOptionBool.read(from: &buf), message: FfiConverterString.read(from: &buf)) @@ -7570,7 +7538,8 @@ public struct FfiConverterTypeClosureReason: FfiConverterRustBuffer { case 7: return .fundingTimedOut - case 8: return try .processingError(err: FfiConverterString.read(from: &buf)) + case 8: return try .processingError(err: FfiConverterString.read(from: &buf) + ) case 9: return .disconnectedPeer @@ -7582,7 +7551,8 @@ public struct FfiConverterTypeClosureReason: FfiConverterRustBuffer { case 13: return .fundingBatchClosure - case 14: return try .htlCsTimedOut(paymentHash: FfiConverterOptionTypePaymentHash.read(from: &buf)) + case 14: return try .htlCsTimedOut(paymentHash: FfiConverterOptionTypePaymentHash.read(from: &buf) + ) case 15: return try .peerFeerateTooLow(peerFeerateSatPerKw: FfiConverterUInt32.read(from: &buf), requiredFeerateSatPerKw: FfiConverterUInt32.read(from: &buf)) @@ -7869,8 +7839,10 @@ public enum Event { case onchainTransactionConfirmed(txid: Txid, blockHash: BlockHash, blockHeight: UInt32, confirmationTime: UInt64, details: TransactionDetails) case onchainTransactionReceived(txid: Txid, details: TransactionDetails) case onchainTransactionReplaced(txid: Txid, conflicts: [Txid]) - case onchainTransactionReorged(txid: Txid) - case onchainTransactionEvicted(txid: Txid) + case onchainTransactionReorged(txid: Txid + ) + case onchainTransactionEvicted(txid: Txid + ) case syncProgress(syncType: SyncType, progressPercent: UInt8, currentBlockHeight: UInt32, targetBlockHeight: UInt32) case syncCompleted(syncType: SyncType, syncedBlockHeight: UInt32) case balanceChanged(oldSpendableOnchainBalanceSats: UInt64, newSpendableOnchainBalanceSats: UInt64, oldTotalOnchainBalanceSats: UInt64, newTotalOnchainBalanceSats: UInt64, oldTotalLightningBalanceSats: UInt64, newTotalLightningBalanceSats: UInt64) @@ -7911,9 +7883,11 @@ public struct FfiConverterTypeEvent: FfiConverterRustBuffer { case 13: return try .onchainTransactionReplaced(txid: FfiConverterTypeTxid.read(from: &buf), conflicts: FfiConverterSequenceTypeTxid.read(from: &buf)) - case 14: return try .onchainTransactionReorged(txid: FfiConverterTypeTxid.read(from: &buf)) + case 14: return try .onchainTransactionReorged(txid: FfiConverterTypeTxid.read(from: &buf) + ) - case 15: return try .onchainTransactionEvicted(txid: FfiConverterTypeTxid.read(from: &buf)) + case 15: return try .onchainTransactionEvicted(txid: FfiConverterTypeTxid.read(from: &buf) + ) case 16: return try .syncProgress(syncType: FfiConverterTypeSyncType.read(from: &buf), progressPercent: FfiConverterUInt8.read(from: &buf), currentBlockHeight: FfiConverterUInt32.read(from: &buf), targetBlockHeight: FfiConverterUInt32.read(from: &buf)) @@ -8317,8 +8291,10 @@ extension LogLevel: Equatable, Hashable {} // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum MaxDustHtlcExposure { - case fixedLimit(limitMsat: UInt64) - case feeRateMultiplier(multiplier: UInt64) + case fixedLimit(limitMsat: UInt64 + ) + case feeRateMultiplier(multiplier: UInt64 + ) } #if swift(>=5.8) @@ -8330,9 +8306,11 @@ public struct FfiConverterTypeMaxDustHTLCExposure: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> MaxDustHtlcExposure { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .fixedLimit(limitMsat: FfiConverterUInt64.read(from: &buf)) + case 1: return try .fixedLimit(limitMsat: FfiConverterUInt64.read(from: &buf) + ) - case 2: return try .feeRateMultiplier(multiplier: FfiConverterUInt64.read(from: &buf)) + case 2: return try .feeRateMultiplier(multiplier: FfiConverterUInt64.read(from: &buf) + ) default: throw UniffiInternalError.unexpectedEnumCase } @@ -9000,7 +8978,8 @@ extension NodeError: Foundation.LocalizedError { // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum OfferAmount { - case bitcoin(amountMsats: UInt64) + case bitcoin(amountMsats: UInt64 + ) case currency(iso4217Code: String, amount: UInt64) } @@ -9013,7 +8992,8 @@ public struct FfiConverterTypeOfferAmount: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> OfferAmount { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .bitcoin(amountMsats: FfiConverterUInt64.read(from: &buf)) + case 1: return try .bitcoin(amountMsats: FfiConverterUInt64.read(from: &buf) + ) case 2: return try .currency(iso4217Code: FfiConverterString.read(from: &buf), amount: FfiConverterUInt64.read(from: &buf)) @@ -9437,9 +9417,12 @@ extension PendingSweepBalance: Equatable, Hashable {} // See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion. public enum QrPaymentResult { - case onchain(txid: Txid) - case bolt11(paymentId: PaymentId) - case bolt12(paymentId: PaymentId) + case onchain(txid: Txid + ) + case bolt11(paymentId: PaymentId + ) + case bolt12(paymentId: PaymentId + ) } #if swift(>=5.8) @@ -9451,11 +9434,14 @@ public struct FfiConverterTypeQrPaymentResult: FfiConverterRustBuffer { public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> QrPaymentResult { let variant: Int32 = try readInt(&buf) switch variant { - case 1: return try .onchain(txid: FfiConverterTypeTxid.read(from: &buf)) + case 1: return try .onchain(txid: FfiConverterTypeTxid.read(from: &buf) + ) - case 2: return try .bolt11(paymentId: FfiConverterTypePaymentId.read(from: &buf)) + case 2: return try .bolt11(paymentId: FfiConverterTypePaymentId.read(from: &buf) + ) - case 3: return try .bolt12(paymentId: FfiConverterTypePaymentId.read(from: &buf)) + case 3: return try .bolt12(paymentId: FfiConverterTypePaymentId.read(from: &buf) + ) default: throw UniffiInternalError.unexpectedEnumCase } @@ -12090,8 +12076,8 @@ private func uniffiRustCallAsync( )) } -/// 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. +// 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. private func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) { if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) { continuation.resume(returning: pollResult) @@ -12102,13 +12088,15 @@ private func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) public func batterySavingSyncIntervals() -> RuntimeSyncIntervals { return try! FfiConverterTypeRuntimeSyncIntervals.lift(try! rustCall { - uniffi_ldk_node_fn_func_battery_saving_sync_intervals($0) + uniffi_ldk_node_fn_func_battery_saving_sync_intervals($0 + ) }) } public func defaultConfig() -> Config { return try! FfiConverterTypeConfig.lift(try! rustCall { - uniffi_ldk_node_fn_func_default_config($0) + uniffi_ldk_node_fn_func_default_config($0 + ) }) } @@ -12135,8 +12123,8 @@ private enum InitializationResult { case apiChecksumMismatch } -/// Use a global variable to perform the versioning checks. Swift ensures that -/// the code inside is only computed once. +// Use a global variable to perform the versioning checks. Swift ensures that +// the code inside is only computed once. private var initializationResult: InitializationResult = { // Get the bindings contract version from our ComponentInterface let bindings_contract_version = 26 diff --git a/src/chain/electrum.rs b/src/chain/electrum.rs index 2db971676..b20b45c58 100644 --- a/src/chain/electrum.rs +++ b/src/chain/electrum.rs @@ -44,7 +44,6 @@ use crate::NodeMetrics; const BDK_ELECTRUM_CLIENT_BATCH_SIZE: usize = 5; const ELECTRUM_CLIENT_NUM_RETRIES: u8 = 3; -const ELECTRUM_CLIENT_TIMEOUT_SECS: u8 = 10; pub(super) struct ElectrumChainSource { server_url: String, @@ -91,6 +90,7 @@ impl ElectrumChainSource { Arc::clone(&runtime), Arc::clone(&self.config), Arc::clone(&self.logger), + self.sync_config.connection_timeout_secs, ) } @@ -469,7 +469,7 @@ impl ElectrumRuntimeStatus { pub(super) fn start( &mut self, server_url: String, runtime: Arc, config: Arc, - logger: Arc, + logger: Arc, connection_timeout_secs: u64, ) -> Result<(), Error> { match self { Self::Stopped { pending_registered_txs, pending_registered_outputs } => { @@ -478,6 +478,7 @@ impl ElectrumRuntimeStatus { runtime, config, logger, + connection_timeout_secs, )?); // Apply any pending `Filter` entries @@ -540,24 +541,55 @@ struct ElectrumRuntimeClient { impl ElectrumRuntimeClient { fn new( server_url: String, runtime: Arc, config: Arc, logger: Arc, + connection_timeout_secs: u64, ) -> Result { + // 0 disables the socket timeout entirely. Values above u8::MAX are capped to 255 + // because the electrum_client crate's timeout field is a u8. + let timeout_opt = match connection_timeout_secs { + 0 => None, + n => { + let capped = n.min(u8::MAX as u64) as u8; + if capped as u64 != n { + log_warn!( + logger, + "Electrum connection_timeout_secs ({}) exceeds maximum of {}; capping to {}.", + n, + u8::MAX, + capped, + ); + } + Some(capped) + }, + }; + let electrum_config = ElectrumConfigBuilder::new() .retry(ELECTRUM_CLIENT_NUM_RETRIES) - .timeout(Some(ELECTRUM_CLIENT_TIMEOUT_SECS)) + .timeout(timeout_opt) .build(); let electrum_client = Arc::new( ElectrumClient::from_config(&server_url, electrum_config.clone()).map_err(|e| { - log_error!(logger, "Failed to connect to electrum server: {}", e); + log_error!(logger, "Failed to connect to Electrum server: {}", e); Error::ConnectionFailed })?, ); let bdk_electrum_client = Arc::new(BdkElectrumClient::new(Arc::clone(&electrum_client))); - let tx_sync = Arc::new( - ElectrumSyncClient::new(server_url.clone(), Arc::clone(&logger)).map_err(|e| { - log_error!(logger, "Failed to connect to electrum server: {}", e); + + // The LDK tx-sync client needs its own TCP connection, configured with the same + // timeout so that its blocking reads are bounded and Tokio's blocking thread pool + // is not exhausted by threads stuck on dead sockets. + let ldk_electrum_client = + Arc::new(ElectrumClient::from_config(&server_url, electrum_config).map_err(|e| { + log_error!(logger, "Failed to connect to Electrum server for tx sync: {}", e); Error::ConnectionFailed - })?, + })?); + let tx_sync = Arc::new( + ElectrumSyncClient::from_client(ldk_electrum_client, Arc::clone(&logger)).map_err( + |e| { + log_error!(logger, "Failed to initialize Electrum tx sync client: {}", e); + Error::ConnectionFailed + }, + )?, ); Ok(Self { electrum_client, bdk_electrum_client, tx_sync, runtime, config, logger }) } diff --git a/src/config.rs b/src/config.rs index 0fa4799eb..0df143a40 100644 --- a/src/config.rs +++ b/src/config.rs @@ -44,6 +44,9 @@ pub(crate) const DEFAULT_ESPLORA_SERVER_URL: &str = "https://blockstream.info/ap // The default Esplora client timeout we're using. pub(crate) const DEFAULT_ESPLORA_CLIENT_TIMEOUT_SECS: u64 = 10; +// The default Electrum connection/read timeout we're using. +pub(crate) const DEFAULT_ELECTRUM_CONNECTION_TIMEOUT_SECS: u64 = 10; + // The 'stop gap' parameter used by BDK's wallet sync. This seems to configure the threshold // number of derivation indexes after which BDK stops looking for new scripts belonging to the wallet. pub(crate) const BDK_CLIENT_STOP_GAP: usize = 20; @@ -611,11 +614,25 @@ pub struct ElectrumSyncConfig { /// /// [`Node::sync_wallets`]: crate::Node::sync_wallets pub background_sync_config: Option, + /// Timeout in seconds for each Electrum socket operation (connect, read, write). + /// + /// **Note:** Without a per-socket timeout, threads spawned by `sync_wallets` can block + /// indefinitely under total packet loss, eventually exhausting Tokio's blocking thread pool + /// and causing subsequent `sync_wallets` calls to block indefinitely. + /// + /// Set to `0` to disable the socket timeout entirely. The effective maximum is 255 seconds + /// (the underlying `electrum_client` crate uses a `u8`); larger values are capped with a + /// warning. Note that two TCP connections are opened at node start (on-chain and Lightning + /// sync), so budget accordingly when tuning this value. Defaults to 10 seconds. + pub connection_timeout_secs: u64, } impl Default for ElectrumSyncConfig { fn default() -> Self { - Self { background_sync_config: Some(BackgroundSyncConfig::default()) } + Self { + background_sync_config: Some(BackgroundSyncConfig::default()), + connection_timeout_secs: DEFAULT_ELECTRUM_CONNECTION_TIMEOUT_SECS, + } } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a21af838a..27f6b8cb4 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -450,7 +450,8 @@ pub(crate) fn setup_node_for_async_payments( }, TestChainSource::Electrum(electrsd) => { let electrum_url = format!("tcp://{}", electrsd.electrum_url); - let sync_config = ElectrumSyncConfig { background_sync_config: None }; + let sync_config = + ElectrumSyncConfig { background_sync_config: None, ..Default::default() }; builder.set_chain_source_electrum(electrum_url.clone(), Some(sync_config)); }, TestChainSource::BitcoindRpcSync(bitcoind) => { diff --git a/tests/integration_tests_rust.rs b/tests/integration_tests_rust.rs index 287f01a8a..35b620e2c 100644 --- a/tests/integration_tests_rust.rs +++ b/tests/integration_tests_rust.rs @@ -25,7 +25,7 @@ use common::{ random_listening_addresses, setup_bitcoind_and_electrsd, setup_builder, setup_node, setup_node_for_async_payments, setup_two_nodes, wait_for_tx, TestChainSource, TestSyncStore, }; -use ldk_node::config::{AsyncPaymentsRole, EsploraSyncConfig}; +use ldk_node::config::{AsyncPaymentsRole, ElectrumSyncConfig, EsploraSyncConfig}; use ldk_node::liquidity::LSPS2ServiceConfig; use ldk_node::payment::{ ConfirmationStatus, PaymentDetails, PaymentDirection, PaymentKind, PaymentStatus, @@ -3298,3 +3298,53 @@ async fn get_address_balance_electrum() { let invalid_result = node.get_address_balance("invalid_address"); assert!(invalid_result.is_err(), "Invalid address should return error"); } + +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn electrum_connection_timeout_config() { + let (_, electrsd) = setup_bitcoind_and_electrsd(); + let electrum_url = format!("tcp://{}", electrsd.electrum_url); + let config = random_config(false); + setup_builder!(builder, config.node_config); + let sync_config = + ElectrumSyncConfig { background_sync_config: None, connection_timeout_secs: 20 }; + builder.set_chain_source_electrum(electrum_url, Some(sync_config)); + let node = builder.build().unwrap(); + node.start().unwrap(); + node.sync_wallets().unwrap(); + node.stop().unwrap(); +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn electrum_connection_timeout_zero_disables() { + // connection_timeout_secs: 0 must map to no socket timeout rather than passing + // Duration::ZERO to set_read_timeout, which errors on most platforms and would + // cause start() to fail. + let (_, electrsd) = setup_bitcoind_and_electrsd(); + let electrum_url = format!("tcp://{}", electrsd.electrum_url); + let config = random_config(false); + setup_builder!(builder, config.node_config); + let sync_config = + ElectrumSyncConfig { background_sync_config: None, connection_timeout_secs: 0 }; + builder.set_chain_source_electrum(electrum_url, Some(sync_config)); + let node = builder.build().unwrap(); + node.start().unwrap(); + node.sync_wallets().unwrap(); + node.stop().unwrap(); +} + +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn electrum_connection_timeout_above_max_is_capped() { + // Values above 255 must be capped to 255 (electrum_client uses u8) and must not + // prevent startup or sync — the node should start and sync successfully. + let (_, electrsd) = setup_bitcoind_and_electrsd(); + let electrum_url = format!("tcp://{}", electrsd.electrum_url); + let config = random_config(false); + setup_builder!(builder, config.node_config); + let sync_config = + ElectrumSyncConfig { background_sync_config: None, connection_timeout_secs: 300 }; + builder.set_chain_source_electrum(electrum_url, Some(sync_config)); + let node = builder.build().unwrap(); + node.start().unwrap(); + node.sync_wallets().unwrap(); + node.stop().unwrap(); +}