commit 52c374bc087128364233bcd532331551ab78c0bc
parent 053e50b71489ea3c5ab5d86e7d18a40fdf579515
Author: William Casarin <jb55@jb55.com>
Date: Fri, 25 Mar 2022 16:02:09 -0700
add 10 second fetchinvoice response timeout
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/lightninglink/RPC.swift b/lightninglink/RPC.swift
@@ -375,16 +375,19 @@ public func rpc_fetchinvoice(ln: LNSocket, token: String, req: FetchInvoiceReq)
{
var params: [String: String] = [ "offer": req.offer ]
- if req.pay_amt != nil {
- let amt = req.pay_amt!.amount + (req.pay_amt!.tip ?? 0)
+ if let pay_amt = req.pay_amt {
+ let amt = pay_amt.amount + (pay_amt.tip ?? 0)
params["msatoshi"] = "\(amt)msat"
}
- if req.quantity != nil {
- params["quantity"] = "\(req.quantity!)"
+ let timeout = req.timeout ?? 15
+ params["timeout"] = "\(timeout)"
+
+ if let qty = req.quantity {
+ params["quantity"] = "\(qty)"
}
- return performRpc(ln: ln, operation: "fetchinvoice", authToken: token, timeout_ms: 10000, params: params)
+ return performRpc(ln: ln, operation: "fetchinvoice", authToken: token, timeout_ms: Int32((timeout + 2) * 1000), params: params)
}
public func maybe_decode_error_json<T: Decodable>(_ dat: Data) -> Either<String, T>? {
diff --git a/lightninglink/Views/PayView.swift b/lightninglink/Views/PayView.swift
@@ -61,6 +61,7 @@ public struct FetchInvoiceReq {
let pay_amt: PayAmount?
let amount: InvoiceAmount
let quantity: Int?
+ let timeout: Int?
}
public enum TipSelection {
@@ -650,11 +651,26 @@ func fetchinvoice_req_from_offer(offer: InvoiceDecode, offer_str: String, pay_am
qty = offer.quantity_min!
}
+ // TODO: should we wait longer to fetch an invoice??
+ let timeout = 10
+
if offer.amount_msat != nil {
- return .right(.init(offer: offer_str, pay_amt: pay_amt, amount: .any, quantity: qty))
+ return .right(.init(
+ offer: offer_str,
+ pay_amt: pay_amt,
+ amount: .any,
+ quantity: qty,
+ timeout: timeout
+ ))
} else {
let amount: InvoiceAmount = .amount(pay_amt.amount)
- return .right(.init(offer: offer_str, pay_amt: pay_amt, amount: amount, quantity: qty))
+ return .right(.init(
+ offer: offer_str,
+ pay_amt: pay_amt,
+ amount: amount,
+ quantity: qty,
+ timeout: timeout
+ ))
}
}