BOLT12 receive (#882)

* Add BOLT12 receive payment handling

* Handle BOLT12 invoice requests via WS

* Fix invoice request subscription on stream initialisation

* Store the BOLT12 offer used to receive a payment

* Address review feedback

* Separate into create BOLT12 invoice fn

* Update all BOLT12 offers when webhook URL changes

* Deprecate Lightning for Bolt11Invoice
This commit is contained in:
Ross Savage
2025-04-29 13:43:45 +02:00
committed by GitHub
parent 586a349b75
commit 5b69c7beb2
66 changed files with 2892 additions and 451 deletions

View File

@@ -59,3 +59,50 @@ extension TaskProtocol {
}
}
}
class ReplyableTask : TaskProtocol {
var payload: String
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var logger: ServiceLogger
var successNotificationTitle: String
var failNotificationTitle: String
init(payload: String, logger: ServiceLogger, contentHandler: ((UNNotificationContent) -> Void)? = nil, bestAttemptContent: UNMutableNotificationContent? = nil, successNotificationTitle: String, failNotificationTitle: String) {
self.payload = payload
self.contentHandler = contentHandler
self.bestAttemptContent = bestAttemptContent
self.logger = logger
self.successNotificationTitle = successNotificationTitle;
self.failNotificationTitle = failNotificationTitle;
}
func start(liquidSDK: BindingLiquidSdk) throws {}
public func onEvent(e: SdkEvent) {}
func onShutdown() {
displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
}
func replyServer(encodable: Encodable, replyURL: String) {
guard let serverReplyURL = URL(string: replyURL) else {
self.displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
return
}
var request = URLRequest(url: serverReplyURL)
request.httpMethod = "POST"
request.httpBody = try! JSONEncoder().encode(encodable)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
let statusCode = (response as! HTTPURLResponse).statusCode
if statusCode == 200 {
self.displayPushNotification(title: self.successNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
} else {
self.displayPushNotification(title: self.failNotificationTitle, logger: self.logger, threadIdentifier: Constants.NOTIFICATION_THREAD_REPLACEABLE)
return
}
}
task.resume()
}
}