diff --git a/Sources/ElixxirDAppsSDK/Functors/LookupUD.swift b/Sources/ElixxirDAppsSDK/Functors/LookupUD.swift new file mode 100644 index 0000000000000000000000000000000000000000..1fba41c8974b8ab3d9b792a0c4b78e8dbc4519ef --- /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)") + ) +}