diff --git a/.swiftpm/xcode/package.xcworkspace/xcuserdata/shubham.xcuserdatad/UserInterfaceState.xcuserstate b/.swiftpm/xcode/package.xcworkspace/xcuserdata/shubham.xcuserdatad/UserInterfaceState.xcuserstate index 8214ff4..9ded418 100644 Binary files a/.swiftpm/xcode/package.xcworkspace/xcuserdata/shubham.xcuserdatad/UserInterfaceState.xcuserstate and b/.swiftpm/xcode/package.xcworkspace/xcuserdata/shubham.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/README.md b/README.md index b4704d4..d9942eb 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,5 @@ A description of this package. ### Swift Package Manage ``` -.package(url: "https://github.com/torusresearch/fetch-node-details-swift5.git", from: "5.0.0"), +.package(url: "https://github.com/torusresearch/fetch-node-details-swift5.git", from: "0.0.1"), ``` diff --git a/Sources/fetch-node-details/fetchNodeDetails+promise.swift b/Sources/fetch-node-details/fetchNodeDetails+promise.swift index 389a813..c60f724 100644 --- a/Sources/fetch-node-details/fetchNodeDetails+promise.swift +++ b/Sources/fetch-node-details/fetchNodeDetails+promise.swift @@ -12,7 +12,7 @@ import PromiseKit extension FetchNodeDetails { - public func getCurrentEpochPromise() -> Promise{ + public func getCurrentEpochPromise() throws -> Promise{ let contractMethod = "currentEpoch" // Contract method you want to call let parameters: [AnyObject] = [] // Parameters for contract method let extraData: Data = Data() // Extra data for contract method @@ -25,24 +25,18 @@ extension FetchNodeDetails { parameters: parameters, extraData: extraData, transactionOptions: options)! - // - // let temp = try! tx.callPromise().wait() - // print(temp) - let returnPromise = Promise { seal in - let txPromise = try tx.callPromise() - print("txPromise", txPromise) - - txPromise.done{ data in - //print(data) - let epoch = data.first?.value - guard let newEpoch = epoch else { return seal.reject("some error")} - // print(newEpoch) - seal.fulfill(Int("\(newEpoch)")!) - }.catch{err in seal.reject(err)} - + let txPromise = tx.callPromise() + let rp = Promise.pending() + + txPromise.done{ data in + let epoch = data.first?.value + guard let newEpoch = epoch else { throw "some error"} + print(newEpoch) + rp.resolver.fulfill(Int("\(newEpoch)")!) } - return returnPromise + + return rp.promise } public func getEpochInfoPromise(epoch : Int) throws -> Promise{ @@ -126,31 +120,61 @@ extension FetchNodeDetails { return returnPromise } - public func getNodeDetailsPromise() -> Promise{ + public func getNodeDetailsPromise() throws -> Promise{ //if(self.nodeDetails.getUpdated()) { return self.nodeDetails } //let (promise, resolver) = Promise.pending() print("ASDF") + var currentEpoch: Int = -1; - let returnPromise = Promise { seal in - let currentEpoch = try self.getCurrentEpochPromise(); - currentEpoch.then{currentEpoch -> Promise in - print(currentEpoch) - return try self.getEpochInfoPromise(epoch: currentEpoch) + let returnPromise = Promise { seal in + let currentEpochPromise = try self.getCurrentEpochPromise(); + currentEpochPromise.then{ response -> Promise in + print("currentEpoch is", response) + currentEpoch = response + return try self.getEpochInfoPromise(epoch: response) }.then{epochInfo -> Guarantee<[Result]> in let nodelist = epochInfo.getNodeList(); - + print("nodeList is", nodelist) var torusIndexes:[BigInt] = Array() var nodeEndPoints:[NodeInfo] = Array() var getNodeInfoPromisesArray:[Promise] = Array() for i in 0.. = Array() + var updatedNodePub:Array = Array() + + for result in results{ + switch result { + case .fulfilled(let value): + // print(value) + let endPointElement:NodeInfo = value; + let endpoint = "https://" + endPointElement.getDeclaredIp().split(separator: ":")[0] + "/jrpc"; + updatedEndpoints.append(endpoint) + + let hexPubX = String(BigInt(endPointElement.getPubKx(), radix:10)!, radix:16, uppercase: true) + let hexPubY = String(BigInt(endPointElement.getPubKy(), radix:10)!, radix:16, uppercase: true) + updatedNodePub.append(TorusNodePub(_X: hexPubX, _Y: hexPubY)) + default: + seal.reject("error with node info") + } + + } + print(updatedNodePub, updatedEndpoints) + + + self.nodeDetails.setNodeListAddress(nodeListAddress: self.proxyAddress.address); + self.nodeDetails.setCurrentEpoch(currentEpoch: String(currentEpoch)); + self.nodeDetails.setTorusNodeEndpoints(torusNodeEndpoints: updatedEndpoints); + self.nodeDetails.setTorusNodePub(torusNodePub: updatedNodePub); + self.nodeDetails.setUpdated(updated: true); + + seal.fulfill(true) }.catch { error in print(error) seal.reject("get epoch info failed") @@ -158,40 +182,6 @@ extension FetchNodeDetails { } return returnPromise - // - // let epochInfo = try! getEpochInfo(epoch: currentEpoch); - // let nodelist = epochInfo.getNodeList(); - // - // var torusIndexes:[BigInt] = Array() - // var nodeEndPoints:[NodeInfo] = Array() - // - // for i in 0.. = Array() - // var updatedNodePub:Array = Array() - // - // for i in 0..