Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions Bitkit/Services/LightningService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
trustedPeersNoReserve: Env.trustedLnPeers.map(\.nodeId),
perChannelReserveSats: 1
)
config.includeUntrustedPendingInSpendable = true

let builder = Builder.fromConfig(config: config)

Expand All @@ -69,8 +70,6 @@
// Configure gossip source from current settings
configureGossipSource(builder: builder, rgsServerUrl: rgsServerUrl)

builder.setEntropyBip39Mnemonic(mnemonic: mnemonic, passphrase: passphrase)

Logger.debug("Building node...")
let storeId = try await VssStoreIdProvider.shared.getVssStoreId(walletIndex: walletIndex)

Expand All @@ -79,16 +78,21 @@
Logger.debug("Building ldk-node with vssUrl: '\(vssUrl)'")
Logger.debug("Building ldk-node with lnurlAuthServerUrl: '\(lnurlAuthServerUrl)'")

// Create NodeEntropy from mnemonic
let nodeEntropy = NodeEntropy.fromBip39Mnemonic(mnemonic: mnemonic, passphrase: passphrase)

try await ServiceQueue.background(.ldk) {
if !lnurlAuthServerUrl.isEmpty {
self.node = try builder.buildWithVssStore(
nodeEntropy: nodeEntropy,
vssUrl: vssUrl,
storeId: storeId,
lnurlAuthServerUrl: lnurlAuthServerUrl,
fixedHeaders: [:]
)
} else {
self.node = try builder.buildWithVssStoreAndFixedHeaders(
nodeEntropy: nodeEntropy,
vssUrl: vssUrl,
storeId: storeId,
fixedHeaders: [:]
Expand Down Expand Up @@ -411,7 +415,7 @@
}
}

func send(bolt11: String, sats: UInt64? = nil, params: SendingParameters? = nil) async throws -> PaymentHash {
func send(bolt11: String, sats: UInt64? = nil, params: RouteParametersConfig? = nil) async throws -> PaymentHash {
guard let node else {
throw AppError(serviceError: .nodeNotSetup)
}
Expand All @@ -432,10 +436,10 @@
return try await ServiceQueue.background(.ldk) {
if let sats {
try node.bolt11Payment().sendUsingAmount(
invoice: .fromStr(invoiceStr: bolt11), amountMsat: sats * 1000, sendingParameters: params
invoice: .fromStr(invoiceStr: bolt11), amountMsat: sats * 1000, routeParameters: params
)
} else {
try node.bolt11Payment().send(invoice: .fromStr(invoiceStr: bolt11), sendingParameters: params)
try node.bolt11Payment().send(invoice: .fromStr(invoiceStr: bolt11), routeParameters: params)
}
}
} catch {
Expand Down Expand Up @@ -468,7 +472,7 @@
}

func closeChannel(_ channel: ChannelDetails, force: Bool = false, forceCloseReason: String? = nil) async throws {
guard let node else {

Check warning on line 475 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

value 'node' was defined but never used; consider replacing with boolean test

Check warning on line 475 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

value 'node' was defined but never used; consider replacing with boolean test
throw AppError(serviceError: .nodeNotStarted)
}

Expand Down Expand Up @@ -671,7 +675,7 @@
onEvent?(event)

switch event {
case let .paymentSuccessful(paymentId, paymentHash, paymentPreimage, feePaidMsat):

Check warning on line 678 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'paymentPreimage' was never used; consider replacing with '_' or removing it

Check warning on line 678 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'paymentPreimage' was never used; consider replacing with '_' or removing it
Logger.info("✅ Payment successful: paymentId: \(paymentId ?? "?") paymentHash: \(paymentHash) feePaidMsat: \(feePaidMsat ?? 0)")
Task {
let hash = paymentId ?? paymentHash
Expand All @@ -696,7 +700,7 @@
Logger.warn("No paymentId or paymentHash available for failed payment", context: "LightningService")
}
}
case let .paymentReceived(paymentId, paymentHash, amountMsat, feePaidMsat):

Check warning on line 703 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'feePaidMsat' was never used; consider replacing with '_' or removing it

Check warning on line 703 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'feePaidMsat' was never used; consider replacing with '_' or removing it
Logger.info("🤑 Payment received: paymentId: \(paymentId ?? "?") paymentHash: \(paymentHash) amountMsat: \(amountMsat)")
Task {
let hash = paymentId ?? paymentHash
Expand All @@ -706,7 +710,7 @@
Logger.error("Failed to handle payment received for \(hash): \(error)", context: "LightningService")
}
}
case let .paymentClaimable(paymentId, paymentHash, claimableAmountMsat, claimDeadline, customRecords):

Check warning on line 713 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'customRecords' was never used; consider replacing with '_' or removing it

Check warning on line 713 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'claimDeadline' was never used; consider replacing with '_' or removing it
Logger.info(
"🫰 Payment claimable: paymentId: \(paymentId) paymentHash: \(paymentHash) claimableAmountMsat: \(claimableAmountMsat)"
)
Expand All @@ -717,9 +721,9 @@
"⏳ Channel pending: channelId: \(channelId) userChannelId: \(userChannelId) formerTemporaryChannelId: \(formerTemporaryChannelId) counterpartyNodeId: \(counterpartyNodeId) fundingTxo: \(fundingTxo)"
)
await refreshChannelCache()
case let .channelReady(channelId, userChannelId, counterpartyNodeId):
case let .channelReady(channelId, userChannelId, counterpartyNodeId, fundingTxo):
Logger.info(
"👐 Channel ready: channelId: \(channelId) userChannelId: \(userChannelId) counterpartyNodeId: \(counterpartyNodeId ?? "?")"
"👐 Channel ready: channelId: \(channelId) userChannelId: \(userChannelId) counterpartyNodeId: \(counterpartyNodeId ?? "?") fundingTxo: \(fundingTxo != nil ? "\(fundingTxo!.txid):\(fundingTxo!.vout)" : "nil")"
)
await refreshChannelCache()
case let .channelClosed(channelId, userChannelId, counterpartyNodeId, reason):
Expand All @@ -735,7 +739,7 @@

if let channel {
await registerClosedChannel(channel: channel, reason: reasonString)
await MainActor.run {

Check warning on line 742 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

result of call to 'run(resultType:body:)' is unused

Check warning on line 742 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

result of call to 'run(resultType:body:)' is unused
channelCache.removeValue(forKey: channelIdString)
}
} else {
Expand All @@ -758,7 +762,7 @@
Logger.error("Failed to handle transaction received for \(txid): \(error)", context: "LightningService")
}
}
case let .onchainTransactionConfirmed(txid, blockHash, blockHeight, confirmationTime, details):

Check warning on line 765 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'confirmationTime' was never used; consider replacing with '_' or removing it

Check warning on line 765 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'blockHash' was never used; consider replacing with '_' or removing it
Logger.info("✅ Onchain transaction confirmed: txid=\(txid) blockHeight=\(blockHeight) amountSats=\(details.amountSats)")
Task {
do {
Expand Down Expand Up @@ -812,9 +816,23 @@

// MARK: Balance Events

case let .balanceChanged(oldSpendableOnchain, newSpendableOnchain, oldTotalOnchain, newTotalOnchain, oldLightning, newLightning):

Check warning on line 819 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'newTotalOnchain' was never used; consider replacing with '_' or removing it

Check warning on line 819 in Bitkit/Services/LightningService.swift

View workflow job for this annotation

GitHub Actions / Run Tests

immutable value 'oldTotalOnchain' was never used; consider replacing with '_' or removing it
Logger
.info("💰 Balance changed: onchain=\(oldSpendableOnchain)->\(newSpendableOnchain) lightning=\(oldLightning)->\(newLightning)")

// MARK: Splice Events

case let .splicePending(channelId, userChannelId, counterpartyNodeId, newFundingTxo):
Logger
.info(
"🔀 Splice pending: channelId=\(channelId) userChannelId=\(userChannelId) counterpartyNodeId=\(counterpartyNodeId) newFundingTxo=\(newFundingTxo)"
)
await refreshChannelCache()
case let .spliceFailed(channelId, userChannelId, counterpartyNodeId, abandonedFundingTxo):
Logger
.warn(
"❌ Splice failed: channelId=\(channelId) userChannelId=\(userChannelId) counterpartyNodeId=\(counterpartyNodeId) abandonedFundingTxo=\(abandonedFundingTxo != nil ? "\(abandonedFundingTxo!.txid):\(abandonedFundingTxo!.vout)" : "nil")"
)
}
}
}
Expand Down
33 changes: 24 additions & 9 deletions Bitkit/Utilities/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,16 @@

private init(ldkBuildError: BuildError) {
switch ldkBuildError as BuildError {
case let .InvalidSystemTime(message: ldkMessage):
message = "Invalid system time"
debugMessage = ldkMessage
case let .InvalidChannelMonitor(message: ldkMessage):
message = "Invalid channel monitor"
debugMessage = ldkMessage
case let .InvalidSeedBytes(message: ldkMessage):
message = "Invalid seed bytes"
debugMessage = ldkMessage
case let .InvalidSeedFile(message: ldkMessage):
message = "Invalid seed file"
debugMessage = ldkMessage
case let .InvalidSystemTime(message: ldkMessage):
case let .InvalidListeningAddresses(message: ldkMessage):
message = "Invalid system time"
debugMessage = ldkMessage
case let .InvalidListeningAddresses(message: ldkMessage):

Check warning on line 134 in Bitkit/Utilities/Errors.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

case is already handled by previous patterns; consider removing it
message = "Invalid listening addresses"
debugMessage = ldkMessage
case let .ReadFailed(message: ldkMessage):
Expand Down Expand Up @@ -164,6 +161,12 @@
case let .NetworkMismatch(message: ldkMessage):
message = ldkMessage
debugMessage = nil
case let .RuntimeSetupFailed(message: ldkMessage):
message = "Runtime setup failed"
debugMessage = ldkMessage
case let .AsyncPaymentsConfigMismatch(message: ldkMessage):
message = "Async payments config mismatch"
debugMessage = ldkMessage
}
}

Expand Down Expand Up @@ -197,6 +200,9 @@
// message = "Failed to send payment. \(ldkMessage)"
message = ldkMessage
debugMessage = ldkMessage
case let .InvalidCustomTlvs(message: ldkMessage):
message = "Invalid custom TLVs"
debugMessage = ldkMessage
case let .ProbeSendingFailed(message: ldkMessage):
message = "Failed to send probe"
debugMessage = ldkMessage
Expand All @@ -209,6 +215,9 @@
case let .ChannelClosingFailed(message: ldkMessage):
message = "Failed to close channel"
debugMessage = ldkMessage
case let .ChannelSplicingFailed(message: ldkMessage):
message = "Failed to splice channel"
debugMessage = ldkMessage
case let .ChannelConfigUpdateFailed(message: ldkMessage):
message = "Failed to update channel config"
debugMessage = ldkMessage
Expand Down Expand Up @@ -245,6 +254,9 @@
case let .LiquidityRequestFailed(message: ldkMessage):
message = "Failed to request liquidity"
debugMessage = ldkMessage
case let .UriParameterParsingFailed(message: ldkMessage):
message = "Failed to parse URI parameters"
debugMessage = ldkMessage
case let .InvalidAddress(message: ldkMessage):
message = "Invalid address"
debugMessage = ldkMessage
Expand Down Expand Up @@ -308,8 +320,11 @@
case let .LiquidityFeeTooHigh(message: ldkMessage):
message = "Liquidity fee too high"
debugMessage = ldkMessage
case let .UriParameterParsingFailed(message: ldkMessage):
message = "Uri parameter parsing failed"
case let .InvalidBlindedPaths(message: ldkMessage):
message = "Invalid blinded paths"
debugMessage = ldkMessage
case let .AsyncPaymentServicesDisabled(message: ldkMessage):
message = "Async payment services disabled"
debugMessage = ldkMessage
case let .InvalidUri(message: ldkMessage):
message = "Invalid URI"
Expand All @@ -320,7 +335,7 @@
case let .InvalidNodeAlias(message: ldkMessage):
message = "Invalid node alias"
debugMessage = ldkMessage
case let .InvalidCustomTlvs(message: ldkMessage):

Check warning on line 338 in Bitkit/Utilities/Errors.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

case is already handled by previous patterns; consider removing it
message = "Invalid custom TLVs"
debugMessage = ldkMessage
case let .InvalidDateTime(message: ldkMessage):
Expand Down
2 changes: 1 addition & 1 deletion Bitkit/Utilities/StartupHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StartupHandler {
/// - walletIndex: wallet index, defaults to zero for first entry
/// - Returns: The generated mnemonic
static func createNewWallet(bip39Passphrase: String?, walletIndex: Int = 0) throws -> String {
let mnemonic = generateEntropyMnemonic()
let mnemonic = generateEntropyMnemonic(wordCount: .words12)

try Keychain.saveString(key: .bip39Mnemonic(index: walletIndex), str: mnemonic)
if let bip39Passphrase {
Expand Down
7 changes: 6 additions & 1 deletion Bitkit/ViewModels/AppViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ extension AppViewModel {
case .channelPending(channelId: _, userChannelId: _, formerTemporaryChannelId: _, counterpartyNodeId: _, fundingTxo: _):
// Only relevant for channels to external nodes
break
case .channelReady(let channelId, userChannelId: _, counterpartyNodeId: _):
case .channelReady(let channelId, userChannelId: _, counterpartyNodeId: _, fundingTxo: _):
if let channel = lightningService.channels?.first(where: { $0.channelId == channelId }) {
Task {
let cjitOrder = try await CoreService.shared.blocktank.getCjit(channel: channel)
Expand Down Expand Up @@ -471,6 +471,11 @@ extension AppViewModel {
}
}

// MARK: Splice Events

case .splicePending, .spliceFailed:
break

// MARK: Sync Events

case let .syncProgress(syncType, progressPercent, currentBlockHeight, targetBlockHeight):
Expand Down
7 changes: 6 additions & 1 deletion BitkitNotification/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
bestAttemptContent?.title = "Spending Balance Ready"
bestAttemptContent?.body = "Pending"
// Don't deliver, give a chance for channelReady event to update the content if it's a turbo channel
case let .channelReady(channelId, _, _):
case let .channelReady(channelId, _, _, _):
if notificationType == .cjitPaymentArrived {
bestAttemptContent?.title = "Payment Received"
bestAttemptContent?.body = "Your funds arrived in your spending balance"
Expand Down Expand Up @@ -224,7 +224,7 @@

// MARK: New Onchain Transaction Events

case let .onchainTransactionReceived(txid, details):

Check warning on line 227 in BitkitNotification/NotificationService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'txid' was never used; consider replacing with '_' or removing it
// Show notification for incoming onchain transactions
if details.amountSats > 0 {
let sats = UInt64(abs(Int64(details.amountSats)))
Expand All @@ -233,7 +233,7 @@
ReceivedTxSheetDetails(type: .onchain, sats: sats).save() // Save for UI to pick up
deliver()
}
case let .onchainTransactionConfirmed(txid, blockHash, blockHeight, confirmationTime, details):

Check warning on line 236 in BitkitNotification/NotificationService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'confirmationTime' was never used; consider replacing with '_' or removing it

Check warning on line 236 in BitkitNotification/NotificationService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'blockHash' was never used; consider replacing with '_' or removing it

Check warning on line 236 in BitkitNotification/NotificationService.swift

View workflow job for this annotation

GitHub Actions / Run Integration Tests

immutable value 'txid' was never used; consider replacing with '_' or removing it
// Transaction confirmed - could show notification if it was previously unconfirmed
if details.amountSats > 0 {
let sats = UInt64(abs(Int64(details.amountSats)))
Expand All @@ -256,6 +256,11 @@
case .balanceChanged:
// Balance changes are handled by other events, not critical for notifications
break

// MARK: Splice Events

case .splicePending, .spliceFailed:
break
}
}

Expand Down
Loading