lnlink

iOS app for connecting to lightning nodes
git clone git://jb55.com/lnlink
Log | Files | Refs | Submodules | README | LICENSE

commit 65029bace3c827adb56f3bb0cef2af0e7ee96b55
parent 32db1914c4a1943ec1450bb6884c16e4f138fe18
Author: William Casarin <jb55@jb55.com>
Date:   Wed,  3 Aug 2022 15:31:21 -0700

Fix various issues with deprecated features

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mlightninglink/RPC.swift | 15++++++++++-----
Mlightninglink/Views/PayView.swift | 15++++++++-------
Mlightninglink/Views/ReceiveView.swift | 9++++++---
3 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/lightninglink/RPC.swift b/lightninglink/RPC.swift @@ -383,7 +383,7 @@ public func rpc_offer(ln: LNSocket, token: String, amount: InvoiceAmount = .any, return performRpc(ln: ln, operation: "offer", authToken: token, timeout_ms: default_timeout, params: params) } -public func rpc_invoice(ln: LNSocket, token: String, amount: InvoiceAmount = .any, description: String? = nil, expiry: String? = nil) -> RequestRes<InvoiceRes> { +public func rpc_invoice(ln: LNSocket, token: String, amount: InvoiceAmount = .any, description: String? = nil, expiry: UInt64? = nil) -> RequestRes<InvoiceRes> { let now = Date().timeIntervalSince1970 let label = "lnlink-\(now)" @@ -391,7 +391,7 @@ public func rpc_invoice(ln: LNSocket, token: String, amount: InvoiceAmount = .an var params: [String: String] = ["description": desc, "label": label] if let exp = expiry { - params["expiry"] = exp + params["expiry"] = "\(exp)" } switch amount { @@ -408,12 +408,17 @@ public func rpc_invoice(ln: LNSocket, token: String, amount: InvoiceAmount = .an return performRpc(ln: ln, operation: "invoice", authToken: token, timeout_ms: default_timeout, params: params) } -public func rpc_pay(ln: LNSocket, token: String, bolt11: String, amount_msat: Int64?, timeout_ms: Int32) -> RequestRes<Pay> +public func rpc_pay(ln: LNSocket, token: String, bolt11: String, amount_msat: Int64?, timeout_ms: Int32, description: String?) -> RequestRes<Pay> { - var params: Array<String> = [ bolt11 ] + var params: [String: String] = ["bolt11": bolt11] if amount_msat != nil { - params.append("\(amount_msat!)msat") + params["amount_msat"] = "\(amount_msat!)" } + + if let desc = description { + params["description"] = desc + } + return performRpc(ln: ln, operation: "pay", authToken: token, timeout_ms: timeout_ms, params: params) } diff --git a/lightninglink/Views/PayView.swift b/lightninglink/Views/PayView.swift @@ -371,8 +371,8 @@ struct PayView: View { } } - func confirm_pay(ln: LNSocket?, inv: String, pay_amt: PayAmount?, timeout_ms: Int32) { - let res = confirm_payment(ln: ln, lnlink: self.lnlink, bolt11: inv, pay_amt: pay_amt, timeout_ms: timeout_ms) + func confirm_pay(ln: LNSocket?, inv: String, pay_amt: PayAmount?, timeout_ms: Int32, description: String?) { + let res = confirm_payment(ln: ln, lnlink: self.lnlink, bolt11: inv, pay_amt: pay_amt, timeout_ms: timeout_ms, description: description) switch res { case .left(let err): self.paying = false @@ -419,7 +419,7 @@ struct PayView: View { } DispatchQueue.global(qos: .background).async { - confirm_pay(ln: mln, inv: invstr, pay_amt: nil, timeout_ms: pay_timeout_ms) + confirm_pay(ln: mln, inv: invstr, pay_amt: nil, timeout_ms: pay_timeout_ms, description: lnurlp.metadata) } case .offer: self.error = "Got an offer from a lnurl pay request? What?" @@ -463,7 +463,7 @@ struct PayView: View { self.paying = false self.error = err.description case .success(let fetch_invoice): - confirm_pay(ln: ln, inv: fetch_invoice.invoice, pay_amt: nil, timeout_ms: pay_timeout_ms) + confirm_pay(ln: ln, inv: fetch_invoice.invoice, pay_amt: nil, timeout_ms: pay_timeout_ms, description: nil) } } } @@ -486,7 +486,7 @@ struct PayView: View { let pay_amt = get_pay_amount(invoice.amount) self.paying = true DispatchQueue.global(qos: .background).async { - confirm_pay(ln: mln, inv: invoice.invstr, pay_amt: pay_amt, timeout_ms: pay_timeout_ms) + confirm_pay(ln: mln, inv: invoice.invstr, pay_amt: pay_amt, timeout_ms: pay_timeout_ms, description: nil) } case .initial: fallthrough @@ -683,7 +683,7 @@ public enum Either<L, R> { } } -func confirm_payment(ln mln: LNSocket?, lnlink: LNLink, bolt11: String, pay_amt: PayAmount?, timeout_ms: Int32) -> Either<String, Pay> { +func confirm_payment(ln mln: LNSocket?, lnlink: LNLink, bolt11: String, pay_amt: PayAmount?, timeout_ms: Int32, description: String?) -> Either<String, Pay> { let ln = mln ?? LNSocket() if mln == nil { @@ -702,7 +702,8 @@ func confirm_payment(ln mln: LNSocket?, lnlink: LNLink, bolt11: String, pay_amt: token: lnlink.token, bolt11: bolt11, amount_msat: amount_msat, - timeout_ms: timeout_ms + timeout_ms: timeout_ms, + description: description ) switch res { diff --git a/lightninglink/Views/ReceiveView.swift b/lightninglink/Views/ReceiveView.swift @@ -114,7 +114,10 @@ struct ReceiveView: View { if !self.making && self.qr_data == nil { Button("Receive") { self.making = true - make_invoice(lnlink: lnlink, expiry: "12h", description: self.description, amount: self.amount, issuer: self.issuer, is_offer: self.is_offer) { res in + + // 12h + let h12 = UInt64(Date().timeIntervalSince1970 + 60 * 60 * 12) + make_invoice(lnlink: lnlink, expiry: h12, description: self.description, amount: self.amount, issuer: self.issuer, is_offer: self.is_offer) { res in switch res { case .failure: self.making = false @@ -162,7 +165,7 @@ func generate_qr(from string: String) -> Image { return Image(uiImage: uiimg) } -func make_invoice(lnlink: LNLink, expiry: String, description: String?, amount: Int64?, issuer: String?, is_offer: Bool, callback: @escaping (RequestRes<String>) -> ()) { +func make_invoice(lnlink: LNLink, expiry: UInt64, description: String?, amount: Int64?, issuer: String?, is_offer: Bool, callback: @escaping (RequestRes<String>) -> ()) { let ln = LNSocket() ln.genkey() @@ -177,7 +180,7 @@ func make_invoice(lnlink: LNLink, expiry: String, description: String?, amount: } let desc = description ?? "lnlink invoice" - let expiry = "12h" + if is_offer { let res = rpc_offer(ln: ln, token: lnlink.token, amount: amt, description: desc, issuer: issuer) callback(res.map{ $0.bolt12 })