From d6f65882812e2e48432512a27cc17e28fc54efe0 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 25 Jul 2022 17:24:01 +0100
Subject: [PATCH] Add E2ERequestAuthenticatedChannel functor

---
 Sources/ElixxirDAppsSDK/E2E.swift             |  3 ++
 .../E2ERequestAuthenticatedChannel.swift      | 33 +++++++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/E2ERequestAuthenticatedChannel.swift

diff --git a/Sources/ElixxirDAppsSDK/E2E.swift b/Sources/ElixxirDAppsSDK/E2E.swift
index 11886145..b11f08e2 100644
--- a/Sources/ElixxirDAppsSDK/E2E.swift
+++ b/Sources/ElixxirDAppsSDK/E2E.swift
@@ -13,6 +13,7 @@ public struct E2E {
   public var addService: E2EAddService
   public var removeService: E2ERemoveService
   public var hasAuthenticatedChannel: E2EHasAuthenticatedChannel
+  public var requestAuthenticatedChannel: E2ERequestAuthenticatedChannel
   public var callAllReceivedRequests: E2ECallAllReceivedRequests
   public var send: E2ESend
 
@@ -34,6 +35,7 @@ extension E2E {
       addService: .live(bindingsE2E),
       removeService: .live(bindingsE2E),
       hasAuthenticatedChannel: .live(bindingsE2E),
+      requestAuthenticatedChannel: .live(bindingsE2E),
       callAllReceivedRequests: .live(bindingsE2E),
       send: .live(bindingsE2E)
     )
@@ -54,6 +56,7 @@ extension E2E {
     addService: .unimplemented,
     removeService: .unimplemented,
     hasAuthenticatedChannel: .unimplemented,
+    requestAuthenticatedChannel: .unimplemented,
     callAllReceivedRequests: .unimplemented,
     send: .unimplemented
   )
diff --git a/Sources/ElixxirDAppsSDK/E2ERequestAuthenticatedChannel.swift b/Sources/ElixxirDAppsSDK/E2ERequestAuthenticatedChannel.swift
new file mode 100644
index 00000000..abba09c7
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/E2ERequestAuthenticatedChannel.swift
@@ -0,0 +1,33 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct E2ERequestAuthenticatedChannel {
+  public var run: (Data, String) throws -> Int64
+
+  public func callAsFunction(
+    partnerContact: Data,
+    myFactsString: String
+  ) throws -> Int64 {
+    try run(partnerContact, myFactsString)
+  }
+}
+
+extension E2ERequestAuthenticatedChannel {
+  public static func live(_ bindingsE2E: BindingsE2e) -> E2ERequestAuthenticatedChannel {
+    E2ERequestAuthenticatedChannel { partnerContact, myFactsString in
+      var roundId: Int64 = 0
+      try bindingsE2E.request(
+        partnerContact,
+        myFactsString: myFactsString,
+        ret0_: &roundId
+      )
+      return roundId
+    }
+  }
+}
+
+extension E2ERequestAuthenticatedChannel {
+  public static let unimplemented = E2ERequestAuthenticatedChannel(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
-- 
GitLab