From b42992c02a830a67dc7007987fe51908dcc89c9c Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 15 Mar 2024 11:08:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat=EF=BC=9A=20add=20previewnet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- Sources/Models/FlowChainId.swift | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca3539d..96aa10b 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ https://outblock.github.io/flow-swift/ This is a Swift Package, and can be installed via Xcode with the URL of this repository: ```swift -.package(name: "Flow", url: "https://github.com/outblock/flow-swift.git", from: "0.3.4") +.package(name: "Flow", url: "https://github.com/outblock/flow-swift.git", from: "0.3.6") ``` ## Config diff --git a/Sources/Models/FlowChainId.swift b/Sources/Models/FlowChainId.swift index f284797..0445a4b 100644 --- a/Sources/Models/FlowChainId.swift +++ b/Sources/Models/FlowChainId.swift @@ -42,7 +42,11 @@ public extension Flow { /// Default node is `access.crescendo.nodes.onflow.org:9000` /// HTTP node `https://rest-crescendo.onflow.org/` case crescendo - + + /// Previewnet enviroment + /// Default node is `access-previewnet.onflow.org/:9000` + /// HTTP node `https://rest-previewnet.onflow.org/` + case previewnet /// Emulator enviroment /// Default node is `127.0.0.1:9000` case emulator @@ -51,7 +55,7 @@ public extension Flow { case custom(name: String, transport: Flow.Transport) /// List of other type chain id exclude custom type - public static var allCases: [Flow.ChainID] = [.mainnet, .testnet, .canarynet, .crescendo, .emulator] + public static var allCases: [Flow.ChainID] = [.mainnet, .testnet, .canarynet, .crescendo,.previewnet, .emulator] /// Name of the chain id public var name: String { @@ -62,6 +66,8 @@ public extension Flow { return "testnet" case .crescendo: return "crescendo" + case .previewnet: + return "previewnet" case .canarynet: return "canarynet" case .emulator: @@ -98,6 +104,8 @@ public extension Flow { return .HTTP(URL(string: "http://127.0.0.1:8888/")!) case .crescendo: return .HTTP(URL(string: "https://rest-crescendo.onflow.org/")!) + case .previewnet: + return .HTTP(URL(string: "https://rest-previewnet.onflow.org/")!) case let .custom(_, transport): return transport default: @@ -116,6 +124,8 @@ public extension Flow { return .gRPC(.init(node: "access.canary.nodes.onflow.org", port: 9000)) case .crescendo: return .gRPC(.init(node: "access.crescendo.nodes.onflow.org", port: 9000)) + case .previewnet: + return .gRPC(.init(node: "access-previewnet.onflow.org", port: 9000)) case .emulator: return .gRPC(.init(node: "127.0.0.1", port: 9000)) case let .custom(_, endpoint): From 9979dd20347f9403fa1c0c53bb2e747ede40427c Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 29 Mar 2024 06:47:38 +0800 Subject: [PATCH 2/3] fix: Variable name 'DarwinVersion' should start with a lowercase character & device for mac --- Sources/Network/UserAgent.swift | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/Network/UserAgent.swift b/Sources/Network/UserAgent.swift index e53e3f1..4d6e713 100644 --- a/Sources/Network/UserAgent.swift +++ b/Sources/Network/UserAgent.swift @@ -6,10 +6,13 @@ // import Foundation +#if os(iOS) import UIKit - +#elseif os(macOS) +import AppKit +#endif // eg. Darwin/16.3.0 -var DarwinVersion: String { +var darwinVersion: String { var sysinfo = utsname() uname(&sysinfo) let dv = String(bytes: Data(bytes: &sysinfo.release, count: Int(_SYS_NAMELEN)), encoding: .ascii)!.trimmingCharacters(in: .controlCharacters) @@ -25,8 +28,14 @@ var CFNetworkVersion: String { // eg. iOS/10_1 var deviceVersion: String { +#if os(iOS) let currentDevice = UIDevice.current return "\(currentDevice.systemName)/\(currentDevice.systemVersion)" +#elseif os(macOS) + let info = ProcessInfo.processInfo + return "macOS/\(info.operatingSystemVersion.majorVersion).\(info.operatingSystemVersion.minorVersion).\(info.operatingSystemVersion.patchVersion)" +#endif + } // eg. iPhone5,2 @@ -46,4 +55,4 @@ var appNameAndVersion: String { return "\(name)/\(version)" } -let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(DarwinVersion)" +let userAgent = "\(appNameAndVersion) \(deviceName) \(deviceVersion) \(CFNetworkVersion) \(darwinVersion)" From 48bdd682089c7ed74086588dedebf094bf64c378 Mon Sep 17 00:00:00 2001 From: cat Date: Fri, 29 Mar 2024 06:56:13 +0800 Subject: [PATCH 3/3] feat: remove sandbox --- ...oxTests.swift => FlowAccessAPIOnPreviewnetTests.swift} | 8 ++++---- Tests/FlowAddressTest.swift | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) rename Tests/{FlowAccessAPIOnSandboxTests.swift => FlowAccessAPIOnPreviewnetTests.swift} (83%) diff --git a/Tests/FlowAccessAPIOnSandboxTests.swift b/Tests/FlowAccessAPIOnPreviewnetTests.swift similarity index 83% rename from Tests/FlowAccessAPIOnSandboxTests.swift rename to Tests/FlowAccessAPIOnPreviewnetTests.swift index 444862a..afba5bb 100644 --- a/Tests/FlowAccessAPIOnSandboxTests.swift +++ b/Tests/FlowAccessAPIOnPreviewnetTests.swift @@ -11,13 +11,13 @@ import CryptoKit import Foundation import XCTest -final class FlowAccessAPIOnSandboxTests: XCTestCase { +final class FlowAccessAPIOnPreviewnetTests: XCTestCase { var flowAPI: FlowAccessProtocol! override func setUp() { super.setUp() - flowAPI = flow.createHTTPAccessAPI(chainID: .sandboxnet) - flow.configure(chainID: .sandboxnet) + flowAPI = flow.createHTTPAccessAPI(chainID: .previewnet) + flow.configure(chainID: .previewnet) } func testFlowPing() async throws { @@ -27,7 +27,7 @@ final class FlowAccessAPIOnSandboxTests: XCTestCase { func testNetworkParameters() async throws { let chainID = try await flowAPI.getNetworkParameters() - XCTAssertEqual(chainID, Flow.ChainID.sandboxnet) + XCTAssertEqual(chainID, Flow.ChainID.previewnet) } func testFlowAccount() async throws { diff --git a/Tests/FlowAddressTest.swift b/Tests/FlowAddressTest.swift index 263f95a..a65c312 100644 --- a/Tests/FlowAddressTest.swift +++ b/Tests/FlowAddressTest.swift @@ -24,10 +24,10 @@ final class FlowAddressTest: XCTestCase { XCTAssertEqual(true, isVaild) } - func testAddressHexTypeSandboxnet() async throws { - let isVaild = await flow.isAddressVaildate(address: "0x4e8e130b4fb9aee2", network: .sandboxnet) - XCTAssertEqual(true, isVaild) - } +// func testAddressHexTypeSandboxnet() async throws { +// let isVaild = await flow.isAddressVaildate(address: "0x4e8e130b4fb9aee2", network: .sandboxnet) +// XCTAssertEqual(true, isVaild) +// } func testAddressHexTypeTestnet() async throws { let isVaild = await flow.isAddressVaildate(address: "0xc6de0d94160377cd", network: .testnet)