diff --git a/Sources/ElixxirDAppsSDK/Connection.swift b/Sources/ElixxirDAppsSDK/Connection.swift index 4ecac93a591f365b5c003ce4f223ef5c242c407e..00e18a81fef8334f4e329ff2acb5931a7d58d0ce 100644 --- a/Sources/ElixxirDAppsSDK/Connection.swift +++ b/Sources/ElixxirDAppsSDK/Connection.swift @@ -1,6 +1,7 @@ import Bindings public struct Connection { + public var getId: ConnectionIdProvider public var isAuthenticated: ConnectionAuthStatusProvider public var getPartner: ConnectionPartnerProvider public var send: MessageSender @@ -13,6 +14,7 @@ extension Connection { bindingsConnection: BindingsConnection ) -> Connection { Connection( + getId: .live(bindingsConnection: bindingsConnection), isAuthenticated: .live(bindingsConnection: bindingsConnection), getPartner: .live(bindingsConnection: bindingsConnection), send: .live(bindingsConnection: bindingsConnection), @@ -25,6 +27,7 @@ extension Connection { bindingsAuthenticatedConnection: BindingsAuthenticatedConnection ) -> Connection { Connection( + getId: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection), isAuthenticated: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection), getPartner: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection), send: .live(bindingsAuthenticatedConnection: bindingsAuthenticatedConnection), @@ -37,6 +40,7 @@ extension Connection { #if DEBUG extension Connection { public static let failing = Connection( + getId: .failing, isAuthenticated: .failing, getPartner: .failing, send: .failing, diff --git a/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift b/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift new file mode 100644 index 0000000000000000000000000000000000000000..3261dfd46f312e337bd586a0f21930087a21c273 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/ConnectionIdProvider.swift @@ -0,0 +1,31 @@ +import Bindings + +public struct ConnectionIdProvider { + public var get: () -> Int + + public func callAsFunction() -> Int { + get() + } +} + +extension ConnectionIdProvider { + public static func live( + bindingsConnection: BindingsConnection + ) -> ConnectionIdProvider { + ConnectionIdProvider(get: bindingsConnection.getId) + } + + public static func live( + bindingsAuthenticatedConnection: BindingsAuthenticatedConnection + ) -> ConnectionIdProvider { + ConnectionIdProvider(get: bindingsAuthenticatedConnection.getId) + } +} + +#if DEBUG +extension ConnectionIdProvider { + public static let failing = ConnectionIdProvider { + fatalError("Not implemented") + } +} +#endif