Skip to content

Commit

Permalink
refactor: rename related methods for bolt11 + bolt12
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Jun 24, 2024
1 parent 68bd9b1 commit 74dceb8
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 64 deletions.
94 changes: 41 additions & 53 deletions LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions LDKNodeMonday/View Model/Home/AmountViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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)

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 74dceb8

Please sign in to comment.