From 6e28641e1e1f217af9b2df1e803a304ce94deb69 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Wed, 20 Jul 2022 11:59:05 +0100 Subject: [PATCH] Add LoadCmix functor --- Sources/ElixxirDAppsSDK/LoadCmix.swift | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Sources/ElixxirDAppsSDK/LoadCmix.swift diff --git a/Sources/ElixxirDAppsSDK/LoadCmix.swift b/Sources/ElixxirDAppsSDK/LoadCmix.swift new file mode 100644 index 00000000..c388e9a3 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/LoadCmix.swift @@ -0,0 +1,34 @@ +import Bindings +import XCTestDynamicOverlay + +public struct LoadCmix { + public var run: (String, Data, Data) throws -> Cmix + + public func callAsFunction( + storageDir: String, + password: Data, + cmixParamsJSON: Data + ) throws -> Cmix { + try run(storageDir, password, cmixParamsJSON) + } +} + +extension LoadCmix { + public static let live = LoadCmix { storageDir, password, cmixParamsJSON in + var error: NSError? + let bindingsCmix = BindingsLoadCmix(storageDir, password, cmixParamsJSON, &error) + if let error = error { + throw error + } + guard let bindingsCmix = bindingsCmix else { + fatalError("BindingsLoadCmix returned `nil` without providing error") + } + return Cmix.live(bindingsCmix) + } +} + +extension LoadCmix { + public static let unimplemented = LoadCmix( + run: XCTUnimplemented("\(Self.self)") + ) +} -- GitLab