Skip to content

Commit

Permalink
Merge pull request #39 from torusresearch/alpha
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
himanshuchawla009 authored Aug 28, 2023
2 parents 94a0ee5 + 201e329 commit 68459eb
Show file tree
Hide file tree
Showing 27 changed files with 747 additions and 500 deletions.
27 changes: 0 additions & 27 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,6 @@
"revision": "0ed110f7555c34ff468e72e1686e59721f2b0da6",
"version": "5.3.0"
}
},
{
"package": "GenericJSON",
"repositoryURL": "https://github.com/zoul/generic-json-swift",
"state": {
"branch": null,
"revision": "a137894b2a217abe489cdf1ea287e6f7819b1051",
"version": "2.0.1"
}
},
{
"package": "secp256k1",
"repositoryURL": "https://github.com/Boilertalk/secp256k1.swift",
"state": {
"branch": null,
"revision": "45e458ec3be46cf0a6eb68bc947f797852dc65d8",
"version": "0.1.6"
}
},
{
"package": "web3.swift",
"repositoryURL": "https://github.com/argentlabs/web3.swift",
"state": {
"branch": null,
"revision": "0474eb5e883bc4800b3909833207a1d35e72b808",
"version": "0.9.3"
}
}
]
},
Expand Down
30 changes: 19 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@ import PackageDescription

let package = Package(
name: "FetchNodeDetails",
platforms: [.iOS(.v13),.macOS(.v10_15)
],
platforms: [.iOS(.v13), .macOS(.v10_15)],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "FetchNodeDetails",
targets: ["FetchNodeDetails"]),
.library(
name: "FndBase",
targets: ["FndBase"])
],
dependencies: [
.package(url: "https://github.com/argentlabs/web3.swift", from:"0.8.1")
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "FetchNodeDetails" ,dependencies: ["web3.swift"], path: "Sources",resources: [.process("FetchNodeDetails/Resources/abi.json")]),
name: "CommonSources",
dependencies: ["BigInt"],
path: "Sources/CommonSources"),
.target(
name: "FndBase",
dependencies: ["CommonSources"],
path: "Sources/FndBase"),
.target(
name: "FetchNodeDetails",
dependencies: ["CommonSources", "FndBase"],
path: "Sources/FetchNodeDetails"),
.testTarget(
name: "FetchNodeDetailsTests",
dependencies: ["FetchNodeDetails"]),
]

,swiftLanguageVersions: [.v5]
dependencies: ["FetchNodeDetails","CommonSources", "FndBase"]),
],
swiftLanguageVersions: [.v5]
)
Binary file modified Sources/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions Sources/CommonSources/Error.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by CW Lee on 10/07/2023.
//

import Foundation

/// An error that occurs during the decoding of a value.
public enum FetchNodeError : Error {
case InvalidNetwork(String)
case InvalidMigrationNetwork(String)

}
15 changes: 15 additions & 0 deletions Sources/CommonSources/LegacyMap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// File.swift
//
//
// Created by CW Lee on 10/07/2023.
//

import Foundation


public struct LegacyNetworkMigrationInfo {
public var migrationCompleted: Bool
public var networkIdentifier: String
public var networkMigratedTo: SapphireNetwork
}
130 changes: 130 additions & 0 deletions Sources/CommonSources/Models/AllNodeDetailsModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import Foundation
import BigInt

public struct AllNodeDetailsModel:Equatable, Decodable {
public static func == (lhs : AllNodeDetailsModel, rhs : AllNodeDetailsModel) -> Bool {
return lhs.currentEpoch == rhs.currentEpoch && lhs.torusNodeEndpoints == rhs.torusNodeEndpoints && lhs.torusNodePub == rhs.torusNodePub && lhs.currentEpoch == rhs.currentEpoch && lhs.torusIndexes == rhs.torusIndexes && lhs.updated == rhs.updated
}

public var currentEpoch : String
public var torusNodeEndpoints : Array<String>
public var torusNodeSSSEndpoints : Array<String>
public var torusNodeRSSEndpoints : Array<String>
public var torusNodeTSSEndpoints : Array<String>
public var torusIndexes : Array<BigUInt>
public var torusNodePub : Array<TorusNodePubModel>
public var updated = false

public enum CodingKeys: String, CodingKey {
case currentEpoch = "currentEpoch"
case torusNodeEndpoints = "torusNodeEndpoints"
case torusNodeSSSEndpoints = "torusNodeSSSEndpoints"
case torusNodeRSSEndpoints = "torusNodeRSSEndpoints"
case torusNodeTSSEndpoints = "torusNodeTSSEndpoints"
case torusIndexes = "torusIndexes"
case torusNodePub = "torusNodePub"
case updated = "updated"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
currentEpoch = try container.decode(String.self, forKey: .currentEpoch)
torusNodeEndpoints = try container.decode([String].self, forKey: .torusNodeEndpoints)
torusNodeSSSEndpoints = try container.decodeIfPresent([String].self, forKey: .torusNodeSSSEndpoints) ?? []
torusNodeRSSEndpoints = try container.decodeIfPresent([String].self, forKey: .torusNodeRSSEndpoints) ?? []
torusNodeTSSEndpoints = try container.decodeIfPresent([String].self, forKey: .torusNodeTSSEndpoints) ?? []
// Decode torusIndexes as [Int]
let torusIndexesInt = try container.decode([Int].self, forKey: .torusIndexes)

// Convert [Int] to Array<BigUInt>
torusIndexes = torusIndexesInt.map { BigUInt($0) }
torusNodePub = try container.decode([TorusNodePubModel].self, forKey: .torusNodePub)
updated = try container.decodeIfPresent(Bool.self, forKey: .updated) ?? false
}

public init(_currentEpoch : String, _torusNodeEndpoints : Array<String>, _torusNodeSSSEndpoints : Array<String> = [], _torusNodeRSSEndpoints : Array<String> = [], _torusNodeTSSEndpoints : Array<String> = [], _torusIndexes : Array<BigUInt>, _torusNodePub : Array<TorusNodePubModel>, _updated : Bool = false) {
self.currentEpoch = _currentEpoch;
self.torusNodeSSSEndpoints = _torusNodeSSSEndpoints;
self.torusNodeRSSEndpoints = _torusNodeRSSEndpoints;
self.torusNodeTSSEndpoints = _torusNodeTSSEndpoints;
self.torusNodeEndpoints = _torusNodeEndpoints;
self.torusIndexes = _torusIndexes;
self.torusNodePub = _torusNodePub;
self.updated = _updated;
}

public func getTorusIndexes() -> Array<BigUInt> {
return self.torusIndexes;
}

public mutating func setTorusIndexes(torusIndexes : Array<BigUInt>){
self.torusIndexes = torusIndexes
}

public func getUpdated() -> Bool {
return updated
}

public mutating func setUpdated(updated : Bool){
self.updated = updated
}

public mutating func getCurrentEpoch() -> String{
return currentEpoch
}

public mutating func setCurrentEpoch( currentEpoch : String) {
self.currentEpoch = currentEpoch;
}

public func getTorusNodeEndpoints() -> Array<String> {
return torusNodeEndpoints
}

public mutating func setTorusNodeEndpoints(torusNodeEndpoints : Array<String>) {
self.torusNodeEndpoints = torusNodeEndpoints
}

public func getTorusNodePub() -> Array<TorusNodePubModel> {
return torusNodePub
}

public mutating func setTorusNodePub(torusNodePub : Array<TorusNodePubModel>) {
self.torusNodePub = torusNodePub
}

public func getTorusNodeSSSEndpoints() -> Array<String> {
return torusNodeSSSEndpoints
}

public mutating func setTorusNodeSSSEndpoints(torusNodeSSSEndpoints : Array<String>) {
self.torusNodeSSSEndpoints = torusNodeSSSEndpoints
}

public func getTorusNodeRSSEndpoints() -> Array<String> {
return torusNodeRSSEndpoints
}

public mutating func setTorusNodeRSSEndpoints(torusNodeRSSEndpoints : Array<String>) {
self.torusNodeRSSEndpoints = torusNodeRSSEndpoints
}

public func getTorusNodeTSSEndpoints() -> Array<String> {
return torusNodeTSSEndpoints
}

public mutating func setTorusNodeTSSEndpoints(torusNodeTSSEndpoints : Array<String>) {
self.torusNodeTSSEndpoints = torusNodeTSSEndpoints
}

public mutating func setNodeDetails(nodeDetails: AllNodeDetailsModel) {
self.torusNodeEndpoints = nodeDetails.torusNodeEndpoints
self.torusNodeSSSEndpoints = nodeDetails.torusNodeSSSEndpoints
self.torusNodeRSSEndpoints = nodeDetails.torusNodeRSSEndpoints
self.torusNodeTSSEndpoints = nodeDetails.torusNodeTSSEndpoints
self.torusNodePub = nodeDetails.torusNodePub
self.torusIndexes = nodeDetails.torusIndexes
self.currentEpoch = nodeDetails.currentEpoch
self.updated = true
}
}
11 changes: 11 additions & 0 deletions Sources/CommonSources/Models/NodeDetailsResponse.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public struct NodeDetailsResponse: Decodable {
private let nodeDetails: AllNodeDetailsModel

public init(nodeDetails: AllNodeDetailsModel) {
self.nodeDetails = nodeDetails
}

public func getNodeDetails() -> AllNodeDetailsModel {
return nodeDetails
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Foundation
public struct TorusNodePubModel:Equatable {
public struct TorusNodePubModel:Equatable, Codable {

public static func == (lhs: TorusNodePubModel, rhs: TorusNodePubModel) -> Bool {
return lhs.X == rhs.X && lhs.Y == rhs.Y
}

private let X : String;
private let Y : String;
public let X : String;
public let Y : String;

public init(_X : String, _Y : String) {
self.X = _X
Expand Down
126 changes: 126 additions & 0 deletions Sources/CommonSources/TorusNetwork.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import Foundation

public enum TorusNetwork : Equatable, Hashable {
case legacy(LegacyNetwork)
case sapphire(SapphireNetwork)

public var name : String {
switch self {
case .legacy(let network) :
return network.name
case .sapphire(let network) :
return network.name
}
}

public var path : String {
switch self {
case .legacy(let network) :
return network.path
case .sapphire(let network) :
return network.path
}
}
}

public enum SapphireNetwork: Equatable, Hashable {
case SAPPHIRE_DEVNET
case SAPPHIRE_MAINNET

public var path: String {
switch self {
case .SAPPHIRE_DEVNET:
return "sapphire_devnet"
case .SAPPHIRE_MAINNET:
return "sapphire_mainnet"
}
}

public var name: String {
switch self {
case .SAPPHIRE_DEVNET:
return "sapphire_devnet"
case .SAPPHIRE_MAINNET:
return "sapphire_mainnet"
}
}
}

public enum LegacyNetwork: Equatable, Hashable {
case MAINNET
case TESTNET
case CYAN
case AQUA
case CELESTE
case CUSTOM(path: String)

public var path: String {
switch self {
case .MAINNET:
return "mainnet"
case .TESTNET:
return "goerli"
case .CYAN, .AQUA, .CELESTE:
return "polygon-mainnet"
case let .CUSTOM(path):
return path
}
}

public var name: String {
switch self {
case .MAINNET:
return "mainnet"
case .TESTNET:
return "testnet"
case .CYAN :
return "cyan"
case .AQUA :
return "aqua"
case .CELESTE:
return "celeste"
case .CUSTOM(_):
return "custom"
}
}

public var migration_map: LegacyNetworkMigrationInfo {
switch self {
case .MAINNET:
return LegacyNetworkMigrationInfo(migrationCompleted: true, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET)
case .TESTNET:
return LegacyNetworkMigrationInfo(migrationCompleted: true, networkIdentifier: "teal", networkMigratedTo: SapphireNetwork.SAPPHIRE_DEVNET)
case .CYAN :
return LegacyNetworkMigrationInfo(migrationCompleted: false, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET)
case .AQUA :
return LegacyNetworkMigrationInfo(migrationCompleted: false, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET)
case .CELESTE:
return LegacyNetworkMigrationInfo(migrationCompleted: false, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET)
case .CUSTOM(_):
return LegacyNetworkMigrationInfo(migrationCompleted: false, networkIdentifier: self.name, networkMigratedTo: SapphireNetwork.SAPPHIRE_MAINNET)
}
}

public var networkMap : String {
switch self {
case .MAINNET: return "mainnet"
case .TESTNET: return "goerli"
case .CYAN: return "polygon-mainnet"
case .AQUA: return "polygon-mainnet"
case .CELESTE: return "polygon-mainnet"
case .CUSTOM(let path) : return path
}
}

public var signerMap : String {
switch self {
case .MAINNET: return "https://signer.tor.us"
case .TESTNET: return "https://signer.tor.us"
case .CYAN: return "https://signer-polygon.tor.us"
case .AQUA: return "https://signer-polygon.tor.us"
case .CELESTE: return "https://signer-polygon.tor.us"
case .CUSTOM(let path) : return path
}
}
}

Loading

0 comments on commit 68459eb

Please sign in to comment.