From ec2fd9740b11fd3c4a90e239a52cdfa98a7db055 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 07:57:11 -0600 Subject: [PATCH 01/10] Rename Class --- Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift index b73863d..963adce 100644 --- a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift +++ b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift @@ -1,7 +1,7 @@ import Foundation import Alamofire -public struct XyoApiBoundWitnnessBody: Encodable { +public struct XyoApiBoundWitnessBody: Encodable { var boundWitnesses: [XyoBoundWitnessJson] var payloads: [XyoPayload]? } From 78f2bb3f7a58742712301d49bba2684900239f69 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 07:58:19 -0600 Subject: [PATCH 02/10] Spelling --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..da83e39 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cSpell.words": ["Alamofire", "keccak", "secp"] +} From b352f975f418eb646ec47100cc2f5fc5c033b3e8 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 08:17:32 -0600 Subject: [PATCH 03/10] update default Module --- Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift | 6 +++--- Sources/XyoClient/XyoPanel.swift | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift b/Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift index 7cf1db0..71f49a3 100644 --- a/Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift +++ b/Sources/XyoClient/ArchivistApi/ArchivistApiConfig.swift @@ -1,7 +1,7 @@ public class XyoArchivistApiConfig: XyoApiConfig { - var archive: String - public init(_ archive: String, _ apiDomain: String, _ token: String? = nil) { - self.archive = archive + var apiModule: String + public init(_ apiModule: String, _ apiDomain: String, _ token: String? = nil) { + self.apiModule = apiModule super.init(apiDomain, token) } } diff --git a/Sources/XyoClient/XyoPanel.swift b/Sources/XyoClient/XyoPanel.swift index 91e577a..0cdc637 100644 --- a/Sources/XyoClient/XyoPanel.swift +++ b/Sources/XyoClient/XyoPanel.swift @@ -12,7 +12,7 @@ public class XyoPanel { } public convenience init(archive: String? = nil, apiDomain: String? = nil, witnesses: [XyoWitness]? = nil, token: String? = nil) { - let apiConfig = XyoArchivistApiConfig(archive ?? XyoPanel.Defaults.apiArchive, apiDomain ?? XyoPanel.Defaults.apiDomain) + let apiConfig = XyoArchivistApiConfig(archive ?? XyoPanel.Defaults.apiModule, apiDomain ?? XyoPanel.Defaults.apiDomain) let archivist = XyoArchivistApiClient.get(apiConfig) self.init(archivists: [archivist], witnesses: witnesses ?? []) } @@ -77,13 +77,13 @@ public class XyoPanel { } struct Defaults { - static let apiArchive = "temp" + static let apiModule = "Archivist" static let apiDomain = "https://beta.api.archivist.xyo.network" } private static var defaultArchivist: XyoArchivistApiClient { get { - let apiConfig = XyoArchivistApiConfig(self.Defaults.apiArchive, self.Defaults.apiDomain) + let apiConfig = XyoArchivistApiConfig(self.Defaults.apiModule, self.Defaults.apiDomain) return XyoArchivistApiClient.get(apiConfig) } } From 6ba354adeca2e3b7652f3f82c7097588a6fe9bfa Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 08:17:39 -0600 Subject: [PATCH 04/10] Use module in path --- Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift index 963adce..af01206 100644 --- a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift +++ b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift @@ -40,7 +40,7 @@ public class XyoArchivistApiClient { ) throws { let body = entries AF.request( - "\(self.config.apiDomain)/archive/\(self.config.archive)/block", + "\(self.config.apiDomain)/\(self.config.apiModule)", method: .post, parameters: body, encoder: JSONParameterEncoder.default From 9076ecbb6cc9d9eebf6c0ae7538866830a6c6993 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 13:45:46 -0600 Subject: [PATCH 05/10] Validate HTTP responses so that non-successful status codes are not equated to success --- Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift index af01206..02ffb23 100644 --- a/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift +++ b/Sources/XyoClient/ArchivistApi/ArchivistApiClient.swift @@ -44,7 +44,7 @@ public class XyoArchivistApiClient { method: .post, parameters: body, encoder: JSONParameterEncoder.default - ).responseData(queue: XyoArchivistApiClient.queue) { response in + ).validate().responseData(queue: XyoArchivistApiClient.queue) { response in switch response.result { case .failure( _): XyoArchivistApiClient.mainQueue.async { From 406838dbb63a63a5dc172babb46cf55927b6fef1 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 13:49:11 -0600 Subject: [PATCH 06/10] Use real remote archivist for tests --- Tests/XyoClientTests/Panel.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/XyoClientTests/Panel.swift b/Tests/XyoClientTests/Panel.swift index 8d2e112..3e035ee 100644 --- a/Tests/XyoClientTests/Panel.swift +++ b/Tests/XyoClientTests/Panel.swift @@ -12,7 +12,7 @@ final class PanelTests: XCTestCase { func testCreatePanel() throws { let apiDomain = "https://beta.api.archivist.xyo.network" - let archive = "temp" + let archive = "Archivist" let address = XyoAddress() let witness = XyoWitness(address) let panel = XyoPanel(archive: archive, apiDomain: apiDomain, witnesses: [witness]) @@ -22,7 +22,7 @@ final class PanelTests: XCTestCase { func testPanelReport() throws { let apiDomain = "https://beta.api.archivist.xyo.network" - let archive = "temp" + let archive = "Archivist" _ = XyoAddress() let witness = XyoBasicWitness({ previousHash in let payload = XyoPayload("network.xyo.basic") From 27b38bee547a5dc1c5f3db075c1f9b0c414b7546 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Thu, 7 Nov 2024 13:51:51 -0600 Subject: [PATCH 07/10] Fix BW tests --- Tests/XyoClientTests/BoundWitness.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/XyoClientTests/BoundWitness.swift b/Tests/XyoClientTests/BoundWitness.swift index 6c52ae1..7257811 100644 --- a/Tests/XyoClientTests/BoundWitness.swift +++ b/Tests/XyoClientTests/BoundWitness.swift @@ -72,7 +72,7 @@ final class BoundWitnessTests: XCTestCase { ] func testNotAuthenticated() { - let config = XyoArchivistApiConfig("temp", "https://beta.api.archivist.xyo.network") + let config = XyoArchivistApiConfig("Archivist", "https://beta.api.archivist.xyo.network") let api = XyoArchivistApiClient.get(config) XCTAssertEqual(api.authenticated, false) } @@ -88,7 +88,7 @@ final class BoundWitnessTests: XCTestCase { func testPayload1WithSend() throws { let address = XyoAddress(testVectorPrivateKey.hexToData()) - let config = XyoArchivistApiConfig("temp", "https://beta.api.archivist.xyo.network") + let config = XyoArchivistApiConfig("Archivist", "https://beta.api.archivist.xyo.network") let api = XyoArchivistApiClient.get(config) let bw = try BoundWitnessBuilder().witness(address).payload("network.xyo.test", TestPayload1("network.xyo.test")) let apiExpectation = expectation(description: "API Call") @@ -113,7 +113,7 @@ final class BoundWitnessTests: XCTestCase { func testPayload2WithSend() throws { let address = XyoAddress(testVectorPrivateKey.hexToData()) - let config = XyoArchivistApiConfig("temp", "https://beta.api.archivist.xyo.network") + let config = XyoArchivistApiConfig("Archivist", "https://beta.api.archivist.xyo.network") let api = XyoArchivistApiClient.get(config) let bw = try BoundWitnessBuilder().witness(address).payload("network.xyo.test", TestPayload2("network.xyo.test")) let apiExpectation = expectation(description: "API Call") From 503b0577ffe1b0f642746c4a5461dcb848944c3f Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 8 Nov 2024 15:36:32 -0600 Subject: [PATCH 08/10] Formatting --- Sources/XyoClient/Address/XyoAddress.swift | 8 ++++---- Sources/XyoClient/XyoPanel.swift | 2 +- Tests/XyoClientTests/Panel.swift | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/XyoClient/Address/XyoAddress.swift b/Sources/XyoClient/Address/XyoAddress.swift index 556f588..869aea5 100644 --- a/Sources/XyoClient/Address/XyoAddress.swift +++ b/Sources/XyoClient/Address/XyoAddress.swift @@ -58,21 +58,21 @@ public class XyoAddress { public var keccakHex: String? { get { guard let bytes = keccakBytes else { return nil } - return bytes.toHex(64) + return bytes.toHex(64) } } public var addressBytes: Data? { get { guard let keccakBytes = keccakBytes else { return nil } - return keccakBytes.subdata(in: 12.. Data { - + var keyData = Data(count: count) let result = keyData.withUnsafeMutableBytes { SecRandomCopyBytes(kSecRandomDefault, 32, $0.baseAddress!) diff --git a/Sources/XyoClient/XyoPanel.swift b/Sources/XyoClient/XyoPanel.swift index 0cdc637..ef2cf67 100644 --- a/Sources/XyoClient/XyoPanel.swift +++ b/Sources/XyoClient/XyoPanel.swift @@ -24,7 +24,7 @@ public class XyoPanel { if let observe = observe { witnesses.append(XyoEventWitness(observe)) } - + self.init(witnesses: witnesses) } else { self.init() diff --git a/Tests/XyoClientTests/Panel.swift b/Tests/XyoClientTests/Panel.swift index 3e035ee..fbeb162 100644 --- a/Tests/XyoClientTests/Panel.swift +++ b/Tests/XyoClientTests/Panel.swift @@ -4,10 +4,11 @@ import XCTest @available(iOS 13.0, *) final class PanelTests: XCTestCase { static var allTests = [ - ("createPanel", testCreatePanel, - "panelReport", testPanelReport, - "simplePanelReport", testSimplePanelReport - ) + ( + "createPanel", testCreatePanel, + "panelReport", testPanelReport, + "simplePanelReport", testSimplePanelReport + ) ] func testCreatePanel() throws { From 68d51be96704e1ed444e0dc711298ab5f5faf3c3 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 8 Nov 2024 15:39:06 -0600 Subject: [PATCH 09/10] Formatting --- .../Payload/XyoPayloadValidator.swift | 2 +- .../XyoClient/Schema/XyoSchemaValidator.swift | 14 ++++---- .../XyoWitness/SystemInfo/OsName.swift | 12 +++---- .../SystemInfo/PathMonitorManager.swift | 26 +++++++-------- ...temInfoCellularProviderPayloadStruct.swift | 4 +-- ...stemInfoNetworkCellularPayloadStruct.swift | 4 +-- .../SystemInfo/WifiInformation.swift | 32 +++++++++---------- Sources/XyoClient/extensions/Data.swift | 2 +- Sources/XyoClient/extensions/String.swift | 6 ++-- 9 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Sources/XyoClient/Payload/XyoPayloadValidator.swift b/Sources/XyoClient/Payload/XyoPayloadValidator.swift index cca4e0a..c44ba97 100644 --- a/Sources/XyoClient/Payload/XyoPayloadValidator.swift +++ b/Sources/XyoClient/Payload/XyoPayloadValidator.swift @@ -16,7 +16,7 @@ open class XyoPayloadValidator { closure(errors) } } - + public func all() -> [String] { var errors: [String] = [] errors.append(contentsOf: self.schemaValidator.all()) diff --git a/Sources/XyoClient/Schema/XyoSchemaValidator.swift b/Sources/XyoClient/Schema/XyoSchemaValidator.swift index 0f6e612..25c378b 100644 --- a/Sources/XyoClient/Schema/XyoSchemaValidator.swift +++ b/Sources/XyoClient/Schema/XyoSchemaValidator.swift @@ -14,29 +14,29 @@ open class XyoSchemaValidator { return self.parts.count } } - + var isLowercase: Bool { get { return self.schema == self.schema.lowercased() } } - + private func domainLevel(_ level: Int) -> String { return self.parts[0..<(level + 1)].reversed().joined(separator: ".") - + } - + var rootDomain: String { get { return self.domainLevel(1) } } - + public func rootDomainExists(_ closure: (_ exists: Bool) -> Void) { //domainExists(this.rootDomain, closure) closure(true) } - + public func allDynamic(closure: (_ errors: [String]) -> Void) { var errors: [String] = [] if (self.schema.isEmpty) { @@ -52,7 +52,7 @@ open class XyoSchemaValidator { } } } - + public func all() -> [String] { var errors: [String] = [] if (self.schema.isEmpty) { diff --git a/Sources/XyoClient/XyoWitness/SystemInfo/OsName.swift b/Sources/XyoClient/XyoWitness/SystemInfo/OsName.swift index 94b32f7..e033f8f 100644 --- a/Sources/XyoClient/XyoWitness/SystemInfo/OsName.swift +++ b/Sources/XyoClient/XyoWitness/SystemInfo/OsName.swift @@ -1,15 +1,15 @@ import Foundation func osName() -> String { - #if os(iOS) +#if os(iOS) return "iOS" - #elseif os(macOS) +#elseif os(macOS) return "macOS" - #elseif os(watchOS) +#elseif os(watchOS) return "watchOS" - #elseif os(tvOS) +#elseif os(tvOS) return "tvOS" - #else +#else return "unknown" - #endif +#endif } diff --git a/Sources/XyoClient/XyoWitness/SystemInfo/PathMonitorManager.swift b/Sources/XyoClient/XyoWitness/SystemInfo/PathMonitorManager.swift index 24f79b0..effdd7c 100644 --- a/Sources/XyoClient/XyoWitness/SystemInfo/PathMonitorManager.swift +++ b/Sources/XyoClient/XyoWitness/SystemInfo/PathMonitorManager.swift @@ -22,20 +22,20 @@ public class PathMonitorManager { public init(_ start: Bool = true) { #if os(iOS) NotificationCenter.default.addObserver( - self, - selector: #selector(applicationWillEnterForeground(notification:)), - name: UIApplication.willEnterForegroundNotification, - object: nil) + self, + selector: #selector(applicationWillEnterForeground(notification:)), + name: UIApplication.willEnterForegroundNotification, + object: nil) NotificationCenter.default.addObserver( - self, - selector: #selector(applicationWillResignActive(notification:)), - name: UIApplication.willResignActiveNotification, - object: nil) + self, + selector: #selector(applicationWillResignActive(notification:)), + name: UIApplication.willResignActiveNotification, + object: nil) NotificationCenter.default.addObserver( - self, - selector: #selector(applicationWillResignActive(notification:)), - name: UIApplication.willTerminateNotification, - object: nil) + self, + selector: #selector(applicationWillResignActive(notification:)), + name: UIApplication.willTerminateNotification, + object: nil) #endif if (start) { self.start() @@ -93,7 +93,7 @@ public class PathMonitorManager { } else { self.ip = nil } - + self.group.leave() } } diff --git a/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoCellularProviderPayloadStruct.swift b/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoCellularProviderPayloadStruct.swift index 26c01d2..f63c97a 100644 --- a/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoCellularProviderPayloadStruct.swift +++ b/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoCellularProviderPayloadStruct.swift @@ -8,7 +8,7 @@ struct XyoSystemInfoCellularProviderPayloadStruct: Encodable { var mcc: String? var mnc: String? init() { - #if os(iOS) +#if os(iOS) let networkInfo = CTTelephonyNetworkInfo() let subscriberCellularProvider = networkInfo.serviceSubscriberCellularProviders?.first?.value name = subscriberCellularProvider?.carrierName @@ -16,6 +16,6 @@ struct XyoSystemInfoCellularProviderPayloadStruct: Encodable { mnc = subscriberCellularProvider?.mobileNetworkCode icc = subscriberCellularProvider?.isoCountryCode allowVoip = subscriberCellularProvider?.allowsVOIP - #endif +#endif } } diff --git a/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoNetworkCellularPayloadStruct.swift b/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoNetworkCellularPayloadStruct.swift index be1a71f..9992191 100644 --- a/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoNetworkCellularPayloadStruct.swift +++ b/Sources/XyoClient/XyoWitness/SystemInfo/SystemInfoNetworkCellularPayloadStruct.swift @@ -6,10 +6,10 @@ struct XyoSystemInfoNetworkCellularPayloadStruct: Encodable { var provider = XyoSystemInfoCellularProviderPayloadStruct() var radio: String? init(_ wifiInfo: WifiInformation?) { - #if os(iOS) +#if os(iOS) let networkInfo = CTTelephonyNetworkInfo() radio = networkInfo.serviceCurrentRadioAccessTechnology?.first?.value - #endif +#endif ip = wifiInfo?.pathMonitor?.ip } } diff --git a/Sources/XyoClient/XyoWitness/SystemInfo/WifiInformation.swift b/Sources/XyoClient/XyoWitness/SystemInfo/WifiInformation.swift index 87f2802..ad25010 100644 --- a/Sources/XyoClient/XyoWitness/SystemInfo/WifiInformation.swift +++ b/Sources/XyoClient/XyoWitness/SystemInfo/WifiInformation.swift @@ -17,7 +17,7 @@ public class WifiInformation { self.pathMonitor = allowPathMonitor ? PathMonitorManager(true) : nil } - #if os(iOS) +#if os(iOS) func ssid() -> String? { guard let interfaceNames = CNCopySupportedInterfaces() as? [String] else { return nil @@ -33,13 +33,13 @@ public class WifiInformation { } return ssids.first } - #elseif os(macOS) +#elseif os(macOS) func ssid() -> String? { let client = CWWiFiClient.shared() let interface = client.interface(withName: nil) return interface?.ssid() } - #else +#else func ssid() -> String? { var ssid: String? if let interfaces = CNCopySupportedInterfaces() as NSArray? { @@ -52,21 +52,21 @@ public class WifiInformation { } return ssid } - #endif +#endif - #if os(macOS) +#if os(macOS) func mac() -> String? { let client = CWWiFiClient.shared() let interface = client.interface(withName: nil) return interface?.hardwareAddress() } - #else +#else func mac() -> String? { return nil } - #endif +#endif - #if os(macOS) +#if os(macOS) func security() -> String? { let client = CWWiFiClient.shared() let interface = client.interface(withName: nil) @@ -106,11 +106,11 @@ public class WifiInformation { return nil } } - #else +#else func security() -> String? { return nil } - #endif +#endif func isWifi() -> Bool { return pathMonitor?.isWifi ?? false @@ -124,27 +124,27 @@ public class WifiInformation { return pathMonitor?.isCellular ?? false } - #if os(macOS) +#if os(macOS) func rssi() -> Int? { let client = CWWiFiClient.shared() let interface = client.interface(withName: nil) return interface?.rssiValue() } - #else +#else func rssi() -> Int? { return nil } - #endif +#endif - #if os(macOS) +#if os(macOS) func txPower() -> Int? { let client = CWWiFiClient.shared() let interface = client.interface(withName: nil) return interface?.transmitPower() } - #else +#else func txPower() -> Int? { return nil } - #endif +#endif } diff --git a/Sources/XyoClient/extensions/Data.swift b/Sources/XyoClient/extensions/Data.swift index 07a559c..e3d669b 100644 --- a/Sources/XyoClient/extensions/Data.swift +++ b/Sources/XyoClient/extensions/Data.swift @@ -8,7 +8,7 @@ extension Data { bytes.baseAddress?.assumingMemoryBound(to: UInt8.self) } } - + mutating func mutablePointer() -> UnsafeMutablePointer! { return withUnsafeMutableBytes { (bytes: UnsafeMutableRawBufferPointer) -> UnsafeMutablePointer? in bytes.baseAddress?.assumingMemoryBound(to: UInt8.self) diff --git a/Sources/XyoClient/extensions/String.swift b/Sources/XyoClient/extensions/String.swift index 2ea47a7..3170773 100644 --- a/Sources/XyoClient/extensions/String.swift +++ b/Sources/XyoClient/extensions/String.swift @@ -44,18 +44,18 @@ extension String { func hexToData() -> Data? { var data = Data(capacity: self.count / 2) - + let regex = try! NSRegularExpression(pattern: "[0-9a-f]{1,2}", options: .caseInsensitive) regex.enumerateMatches(in: self, options: [], range: NSMakeRange(0, self.count)) { match, flags, stop in let byteString = (self as NSString).substring(with: match!.range) var num = UInt8(byteString, radix: 16)! data.append(&num, count: 1) } - + guard data.count > 0 else { return nil } - + return data } From 4aed3b8b3805ecd03a813ee7e7b788fa93f1e427 Mon Sep 17 00:00:00 2001 From: Joel Carter Date: Fri, 8 Nov 2024 17:49:21 -0600 Subject: [PATCH 10/10] Return witnessed payloads from panel --- Sources/XyoClient/XyoPanel.swift | 14 ++++++-------- Tests/XyoClientTests/Panel.swift | 9 ++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Sources/XyoClient/XyoPanel.swift b/Sources/XyoClient/XyoPanel.swift index ef2cf67..ff045a1 100644 --- a/Sources/XyoClient/XyoPanel.swift +++ b/Sources/XyoClient/XyoPanel.swift @@ -37,15 +37,15 @@ public class XyoPanel { private var _witnesses: [XyoWitness] private var _previous_hash: String? - public func report() throws { + public func report() throws -> [XyoPayload] { try report(nil) } - public func event(_ event: String, _ closure: XyoPanelReportCallback?) throws { + public func event(_ event: String, _ closure: XyoPanelReportCallback?) throws -> [XyoPayload] { try report([XyoEventWitness { previousHash in XyoEventPayload(event, previousHash) }], closure) } - public func report(_ adhocWitnesses: [XyoWitness], _ closure: XyoPanelReportCallback?) throws { + public func report(_ adhocWitnesses: [XyoWitness], _ closure: XyoPanelReportCallback?) throws -> [XyoPayload] { var witnesses: [XyoWitness] = [] witnesses.append(contentsOf: adhocWitnesses) witnesses.append(contentsOf: self._witnesses) @@ -70,9 +70,10 @@ public class XyoPanel { } } } + return payloads.compactMap { $0 } } - public func report(_ closure: XyoPanelReportCallback?) throws { + public func report(_ closure: XyoPanelReportCallback?) throws -> [XyoPayload] { return try self.report([], closure) } @@ -82,9 +83,6 @@ public class XyoPanel { } private static var defaultArchivist: XyoArchivistApiClient { - get { - let apiConfig = XyoArchivistApiConfig(self.Defaults.apiModule, self.Defaults.apiDomain) - return XyoArchivistApiClient.get(apiConfig) - } + XyoArchivistApiClient.get(XyoArchivistApiConfig(self.Defaults.apiModule, self.Defaults.apiDomain)) } } diff --git a/Tests/XyoClientTests/Panel.swift b/Tests/XyoClientTests/Panel.swift index fbeb162..e274fbf 100644 --- a/Tests/XyoClientTests/Panel.swift +++ b/Tests/XyoClientTests/Panel.swift @@ -31,10 +31,11 @@ final class PanelTests: XCTestCase { }) let panel = XyoPanel(archive: archive, apiDomain: apiDomain, witnesses: [witness, XyoSystemInfoWitness()]) let panelExpectation = expectation(description: "Panel Report") - try panel.report { errors in + let result = try panel.report { errors in XCTAssertEqual(errors.count, 0) panelExpectation.fulfill() } + XCTAssertFalse(result.isEmpty) waitForExpectations(timeout: 10) { (error) in XCTAssertNil(error) } @@ -45,10 +46,11 @@ final class PanelTests: XCTestCase { return nil } let panelExpectation = expectation(description: "Panel Report") - try panel.report { errors in + let result = try panel.report { errors in XCTAssertEqual(errors.count, 0) panelExpectation.fulfill() } + XCTAssertTrue(result.isEmpty) waitForExpectations(timeout: 10) { (error) in XCTAssertNil(error) } @@ -57,10 +59,11 @@ final class PanelTests: XCTestCase { func testReportEvent() throws { let panel = XyoPanel(witnesses: [XyoSystemInfoWitness()]) let panelExpectation = expectation(description: "Panel Report") - try panel.event("test_event") { errors in + let result = try panel.event("test_event") { errors in XCTAssertEqual(errors.count, 0) panelExpectation.fulfill() } + XCTAssertFalse(result.isEmpty) waitForExpectations(timeout: 10) { (error) in XCTAssertNil(error) }