From 4a9cdd715b0ba1f1427b1960b6e07cb2763d5ad7 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 25 Jul 2022 17:05:25 +0100
Subject: [PATCH] Add E2ESend functor

---
 Sources/ElixxirDAppsSDK/E2E.swift     |  7 +++++--
 Sources/ElixxirDAppsSDK/E2ESend.swift | 27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100644 Sources/ElixxirDAppsSDK/E2ESend.swift

diff --git a/Sources/ElixxirDAppsSDK/E2E.swift b/Sources/ElixxirDAppsSDK/E2E.swift
index f6353308..24e443ae 100644
--- a/Sources/ElixxirDAppsSDK/E2E.swift
+++ b/Sources/ElixxirDAppsSDK/E2E.swift
@@ -12,6 +12,7 @@ public struct E2E {
   public var addPartnerCallback: E2EAddPartnerCallback
   public var addService: E2EAddService
   public var removeService: E2ERemoveService
+  public var send: E2ESend
 
   // TODO:
 }
@@ -29,7 +30,8 @@ extension E2E {
       partitionSize: .live(bindingsE2E),
       addPartnerCallback: .live(bindingsE2E),
       addService: .live(bindingsE2E),
-      removeService: .live(bindingsE2E)
+      removeService: .live(bindingsE2E),
+      send: .live(bindingsE2E)
     )
   }
 }
@@ -46,6 +48,7 @@ extension E2E {
     partitionSize: .unimplemented,
     addPartnerCallback: .unimplemented,
     addService: .unimplemented,
-    removeService: .unimplemented
+    removeService: .unimplemented,
+    send: .unimplemented
   )
 }
diff --git a/Sources/ElixxirDAppsSDK/E2ESend.swift b/Sources/ElixxirDAppsSDK/E2ESend.swift
new file mode 100644
index 00000000..16f6d1bc
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/E2ESend.swift
@@ -0,0 +1,27 @@
+import Bindings
+import XCTestDynamicOverlay
+
+public struct E2ESend {
+  public var run: (Int, Data, Data, Data) throws -> Data
+
+  public func callAsFunction(
+    messageType: Int,
+    recipientId: Data,
+    payload: Data,
+    e2eParams: Data
+  ) throws -> Data {
+    try run(messageType, recipientId, payload, e2eParams)
+  }
+}
+
+extension E2ESend {
+  public static func live(_ bindingsE2E: BindingsE2e) -> E2ESend {
+    E2ESend(run: bindingsE2E.sendE2E(_:recipientId:payload:e2eParams:))
+  }
+}
+
+extension E2ESend {
+  public static let unimplemented = E2ESend(
+    run: XCTUnimplemented("\(Self.self)")
+  )
+}
-- 
GitLab