From 74dceb8dc753c7e5d572f0447495dcf7eb38793a Mon Sep 17 00:00:00 2001 From: Matthew Ramsden <6657488+reez@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:17:42 -0500 Subject: [PATCH] refactor: rename related methods for bolt11 + bolt12 --- .../LightningNodeService.swift | 94 ++++++++----------- .../View Model/Home/AmountViewModel.swift | 10 +- .../Home/Receive/AddressViewModel.swift | 2 +- .../Home/Receive/AmountInvoiceViewModel.swift | 2 +- .../Home/Receive/Bolt12InvoiceViewModel.swift | 2 +- .../Receive/Bolt12ZeroInvoiceViewModel.swift | 2 +- .../Home/Receive/JITInvoiceViewModel.swift | 2 +- .../Home/Receive/ZeroAmountViewModel.swift | 2 +- 8 files changed, 52 insertions(+), 64 deletions(-) diff --git a/LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift b/LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift index 11dba68..3838887 100644 --- a/LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift +++ b/LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift @@ -95,13 +95,13 @@ class LightningNodeService { } func nodeId() -> String { - let nodeID = ldkNode.nodeId() - return nodeID + let nodeId = ldkNode.nodeId() + return nodeId } - func newOnchainAddress() async throws -> String { - let fundingAddress = try ldkNode.onchainPayment().newAddress() - return fundingAddress + func newAddress() async throws -> String { + let address = try ldkNode.onchainPayment().newAddress() + return address } func spendableOnchainBalanceSats() async -> UInt64 { @@ -120,13 +120,13 @@ class LightningNodeService { } func lightningBalances() async -> [LightningBalance] { - let balance = ldkNode.listBalances().lightningBalances - return balance + let balances = ldkNode.listBalances().lightningBalances + return balances } func pendingBalancesFromChannelClosures() async -> [PendingSweepBalance] { - let balance = ldkNode.listBalances().pendingBalancesFromChannelClosures - return balance + let balances = ldkNode.listBalances().pendingBalancesFromChannelClosures + return balances } func connect(nodeId: PublicKey, address: String, persist: Bool) async throws { @@ -167,46 +167,48 @@ class LightningNodeService { ) } - /// Send - Bolt 11 + func sendToAddress(address: Address, amountMsat: UInt64) async throws -> Txid { + let txId = try ldkNode.onchainPayment().sendToAddress( + address: address, + amountMsat: amountMsat + ) + return txId + } - func sendPayment(invoice: Bolt11Invoice) async throws -> PaymentHash { - let paymentHash = try ldkNode.bolt11Payment().send(invoice: invoice) + func send(bolt11Invoice: Bolt11Invoice) async throws -> PaymentHash { + let paymentHash = try ldkNode.bolt11Payment().send(invoice: bolt11Invoice) return paymentHash } - func sendPaymentUsingAmount(invoice: Bolt11Invoice, amountMsat: UInt64) async throws + func send(bolt12Invoice: Bolt12Invoice) async throws -> PaymentId { + let payerNote = "BOLT 12 payer note" + let paymentId = try ldkNode.bolt12Payment().send(offer: bolt12Invoice, payerNote: payerNote) + return paymentId + } + + func sendUsingAmount(bolt11Invoice: Bolt11Invoice, amountMsat: UInt64) async throws -> PaymentHash { let paymentHash = try ldkNode.bolt11Payment().sendUsingAmount( - invoice: invoice, + invoice: bolt11Invoice, amountMsat: amountMsat ) return paymentHash } - /// Send - Bolt 12 - - func sendPaymentBolt12(invoice: Bolt12Invoice) async throws -> PaymentId { - let payerNote = "BOLT 12 payment payer note" - let paymentId = try ldkNode.bolt12Payment().send(offer: invoice, payerNote: payerNote) - return paymentId - } - - func sendPaymentUsingAmountBolt12(invoice: Bolt12Invoice, amountMsat: UInt64) async throws + func sendUsingAmount(bolt12Invoice: Bolt12Invoice, amountMsat: UInt64) async throws -> PaymentId { - let payerNote = "BOLT 12 payment payer note" + let payerNote = "BOLT 12 payer note" let paymentId = try ldkNode.bolt12Payment().sendUsingAmount( - offer: invoice, + offer: bolt12Invoice, payerNote: payerNote, amountMsat: amountMsat ) return paymentId } - /// Receive - Bolt 11 - - func receivePayment(amountMsat: UInt64, description: String, expirySecs: UInt32) async throws + func receive(amountMsat: UInt64, description: String, expirySecs: UInt32) async throws -> Bolt11Invoice { let invoice = try ldkNode.bolt11Payment().receive( @@ -217,7 +219,15 @@ class LightningNodeService { return invoice } - func receiveVariableAmountPayment(description: String, expirySecs: UInt32) async throws + func receive(amountMsat: UInt64, description: String) async throws -> Bolt12Invoice { + let offer = try ldkNode.bolt12Payment().receive( + amountMsat: amountMsat, + description: description + ) + return offer + } + + func receiveVariableAmount(description: String, expirySecs: UInt32) async throws -> Bolt11Invoice { let invoice = try ldkNode.bolt11Payment().receiveVariableAmount( @@ -227,26 +237,12 @@ class LightningNodeService { return invoice } - /// Receive - Bolt 12 - - // name these like receive(with amountMSat: ...) - func receivePaymentBolt12(amountMsat: UInt64, description: String) async throws -> Bolt12Invoice - { - let offer = try ldkNode.bolt12Payment().receive( - amountMsat: amountMsat, - description: description - ) - return offer - } - - func receiveVariableAmountBolt12(description: String) async throws -> Bolt12Invoice { + func receiveVariableAmount(description: String) async throws -> Bolt12Invoice { let offer = try ldkNode.bolt12Payment().receiveVariableAmount(description: description) return offer } - /// Receive - JIT - - func receivePaymentViaJitChannel( + func receiveViaJitChannel( amountMsat: UInt64, description: String, expirySecs: UInt32, @@ -271,14 +267,6 @@ class LightningNodeService { return channels } - func sendToOnchainAddress(address: Address, amountMsat: UInt64) async throws -> Txid { - let txId = try ldkNode.onchainPayment().sendToAddress( - address: address, - amountMsat: amountMsat - ) - return txId - } - func listPayments() -> [PaymentDetails] { let payments = ldkNode.listPayments() return payments diff --git a/LDKNodeMonday/View Model/Home/AmountViewModel.swift b/LDKNodeMonday/View Model/Home/AmountViewModel.swift index 4a65314..1bfcc9a 100644 --- a/LDKNodeMonday/View Model/Home/AmountViewModel.swift +++ b/LDKNodeMonday/View Model/Home/AmountViewModel.swift @@ -18,7 +18,7 @@ class AmountViewModel { func sendToOnchain(address: String, amountMsat: UInt64) async { do { - try await LightningNodeService.shared.sendToOnchainAddress( + try await LightningNodeService.shared.sendToAddress( address: address, amountMsat: amountMsat ) @@ -42,7 +42,7 @@ class AmountViewModel { func sendPayment(invoice: Bolt11Invoice) async { do { - try await LightningNodeService.shared.sendPayment(invoice: invoice) + try await LightningNodeService.shared.send(bolt11Invoice: invoice) } catch let error as NodeError { NotificationCenter.default.post(name: .ldkErrorReceived, object: error) @@ -65,8 +65,8 @@ class AmountViewModel { func sendPaymentUsingAmount(invoice: Bolt11Invoice, amountMsat: UInt64) async { do { - try await LightningNodeService.shared.sendPaymentUsingAmount( - invoice: invoice, + try await LightningNodeService.shared.sendUsingAmount( + bolt11Invoice: invoice, amountMsat: amountMsat ) } catch let error as NodeError { @@ -90,7 +90,7 @@ class AmountViewModel { func sendPaymentBolt12(invoice: Bolt12Invoice) async { do { - try await LightningNodeService.shared.sendPaymentBolt12(invoice: invoice) + try await LightningNodeService.shared.send(bolt12Invoice: invoice) } catch let error as NodeError { NotificationCenter.default.post(name: .ldkErrorReceived, object: error) let errorString = handleNodeError(error) diff --git a/LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift index 1d8fc61..3c64ef0 100644 --- a/LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift @@ -16,7 +16,7 @@ class AddressViewModel: ObservableObject { func newFundingAddress() async { do { - let address = try await LightningNodeService.shared.newOnchainAddress() + let address = try await LightningNodeService.shared.newAddress() DispatchQueue.main.async { self.address = address self.isAddressFinished = true diff --git a/LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift index c9f9fbd..0f8fa05 100644 --- a/LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift @@ -18,7 +18,7 @@ class AmountInvoiceViewModel: ObservableObject { func receivePayment(amountMsat: UInt64, description: String, expirySecs: UInt32) async { do { - let invoice = try await LightningNodeService.shared.receivePayment( + let invoice = try await LightningNodeService.shared.receive( amountMsat: amountMsat, description: description, expirySecs: expirySecs diff --git a/LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift index 01f6a09..7218f0a 100644 --- a/LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift @@ -17,7 +17,7 @@ class Bolt12InvoiceViewModel: ObservableObject { func receivePayment(amountMsat: UInt64, description: String) async { do { - let invoice = try await LightningNodeService.shared.receivePaymentBolt12( + let invoice = try await LightningNodeService.shared.receive( amountMsat: amountMsat, description: description ) diff --git a/LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift index 34cc4aa..77a564a 100644 --- a/LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift @@ -16,7 +16,7 @@ class Bolt12ZeroInvoiceViewModel: ObservableObject { func receivePayment(description: String) async { do { - let invoice = try await LightningNodeService.shared.receiveVariableAmountBolt12( + let invoice = try await LightningNodeService.shared.receiveVariableAmount( description: description ) DispatchQueue.main.async { diff --git a/LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift index 2f3e5eb..63c0712 100644 --- a/LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift @@ -23,7 +23,7 @@ class JITInvoiceViewModel: ObservableObject { maxLspFeeLimitMsat: UInt64? ) async { do { - let invoice = try await LightningNodeService.shared.receivePaymentViaJitChannel( + let invoice = try await LightningNodeService.shared.receiveViaJitChannel( amountMsat: amountMsat, description: description, expirySecs: expirySecs, diff --git a/LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift b/LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift index 3f29f74..4815686 100644 --- a/LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift +++ b/LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift @@ -16,7 +16,7 @@ class ZeroAmountViewModel: ObservableObject { func receiveVariableAmountPayment(description: String, expirySecs: UInt32) async { do { - let invoice = try await LightningNodeService.shared.receiveVariableAmountPayment( + let invoice = try await LightningNodeService.shared.receiveVariableAmount( description: description, expirySecs: expirySecs )