From 66cc7b62cfaa2dddf5dc5f47f0440cc97fbd19ee Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 1 Aug 2022 12:08:10 +0100
Subject: [PATCH] Add UdLookupCallback callback

---
 .../Callbacks/UdLookupCallback.swift          | 40 +++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/Callbacks/UdLookupCallback.swift

diff --git a/Sources/ElixxirDAppsSDK/Callbacks/UdLookupCallback.swift b/Sources/ElixxirDAppsSDK/Callbacks/UdLookupCallback.swift
new file mode 100644
index 00000000..772933fc
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/Callbacks/UdLookupCallback.swift
@@ -0,0 +1,40 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct UdLookupCallback {
+  public init(handle: @escaping (Result<Data, NSError>) -> Void) {
+    self.handle = handle
+  }
+
+  public var handle: (Result<Data, NSError>) -> Void
+}
+
+extension UdLookupCallback {
+  public static let unimplemented = UdLookupCallback(
+    handle: XCTUnimplemented("\(Self.self)")
+  )
+}
+
+extension UdLookupCallback {
+  func makeBindingsUdLookupCallback() -> BindingsUdLookupCallbackProtocol {
+    class CallbackObject: NSObject, BindingsUdLookupCallbackProtocol {
+      init(_ callback: UdLookupCallback) {
+        self.callback = callback
+      }
+
+      let callback: UdLookupCallback
+
+      func callback(_ contactBytes: Data?, err: Error?) {
+        if let error = err {
+          callback.handle(.failure(error as NSError))
+        } else if let data = contactBytes {
+          callback.handle(.success(data))
+        } else {
+          fatalError("BindingsUdLookupCallback received `nil` data and `nil` error")
+        }
+      }
+    }
+
+    return CallbackObject(self)
+  }
+}
-- 
GitLab