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