From c77a1afa3ab2a837c445f5cd4772c18c715cc09e Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 29 Jul 2022 14:52:18 +0100
Subject: [PATCH] Add InitFileTransfer functor

---
 .../Functors/InitFileTransfer.swift           | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/Functors/InitFileTransfer.swift

diff --git a/Sources/ElixxirDAppsSDK/Functors/InitFileTransfer.swift b/Sources/ElixxirDAppsSDK/Functors/InitFileTransfer.swift
new file mode 100644
index 00000000..5d9712d7
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/Functors/InitFileTransfer.swift
@@ -0,0 +1,43 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct InitFileTransfer {
+  public var run: (Int, Data, Data, ReceiveFileCallback) throws -> FileTransfer
+
+  public func callAsFunction(
+    e2eId: Int,
+    e2eFileTransferParamsJSON: Data,
+    fileTransferParamsJSON: Data,
+    callback: ReceiveFileCallback
+  ) throws -> FileTransfer {
+    try run(e2eId, e2eFileTransferParamsJSON, fileTransferParamsJSON, callback)
+  }
+}
+
+extension InitFileTransfer {
+  public static let live = InitFileTransfer {
+    e2eId, e2eFileTransferParamsJSON, fileTransferParamsJSON, callback in
+
+    var error: NSError?
+    let bindingsFileTransfer = BindingsInitFileTransfer(
+      e2eId,
+      callback.makeBindingsReceiveFileCallback(),
+      e2eFileTransferParamsJSON,
+      fileTransferParamsJSON,
+      &error
+    )
+    if let error = error {
+      throw error
+    }
+    guard let bindingsFileTransfer = bindingsFileTransfer else {
+      fatalError("BindingsInitFileTransfer returned `nil` without providing error")
+    }
+    return .live(bindingsFileTransfer)
+  }
+}
+
+extension InitFileTransfer {
+  public static let unimplemented = InitFileTransfer(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
-- 
GitLab