From 144c6a511f2b34bae655bc5681ee79d758e70ccb Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Mon, 1 Aug 2022 12:17:38 +0100 Subject: [PATCH] Add LookupUD functor --- .../ElixxirDAppsSDK/Functors/LookupUD.swift | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Sources/ElixxirDAppsSDK/Functors/LookupUD.swift diff --git a/Sources/ElixxirDAppsSDK/Functors/LookupUD.swift b/Sources/ElixxirDAppsSDK/Functors/LookupUD.swift new file mode 100644 index 00000000..1fba41c8 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/Functors/LookupUD.swift @@ -0,0 +1,45 @@ +import Bindings +import XCTestDynamicOverlay + +public struct LookupUD { + public var run: (Int, Data, Data, Data, UdLookupCallback) throws -> SingleUseSendReport + + public func callAsFunction( + e2eId: Int, + udContact: Data, + udId: Data, + singleRequestParamsJSON: Data, + callback: UdLookupCallback + ) throws -> SingleUseSendReport { + try run(e2eId, udContact, udId, singleRequestParamsJSON, callback) + } +} + +extension LookupUD { + public static let live = LookupUD { + e2eId, udContact, udId, singleRequestParamsJSON, callback in + + var error: NSError? + let reportData = BindingsLookupUD( + e2eId, + udContact, + callback.makeBindingsUdLookupCallback(), + udId, + singleRequestParamsJSON, + &error + ) + if let error = error { + throw error + } + guard let reportData = reportData else { + fatalError("BindingsLookupUD returned `nil` without providing error") + } + return try SingleUseSendReport.decode(reportData) + } +} + +extension LookupUD { + public static let unimplemented = LookupUD( + run: XCTUnimplemented("\(Self.self)") + ) +} -- GitLab