Skip to content

Commit 1cedd86

Browse files
committed
pubkey function added
1 parent cd4ef5a commit 1cedd86

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

web3swift/Utils/Classes/ENS.swift

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public struct ENS {
7575
}
7676

7777
/*
78-
TODO: -
78+
TODO:
7979
*/
8080
//
8181
// public func setAddress(domain: String, address: EthereumAddress, options: Web3Options? = nil) {
@@ -138,12 +138,12 @@ public struct ResolverENS {
138138
self.resolverAddress = resolverAddress
139139
}
140140

141-
mutating func supportsInterface(interfaceID: Data) -> Result<Bool, Web3Error> {
141+
mutating public func supportsInterface(interfaceID: Data) -> Result<Bool, Web3Error> {
142142
return supportsInterface(interfaceID: interfaceID.toHexString())
143143
}
144144

145145
//MARK: - returns true if the contract supports given interface
146-
mutating func supportsInterface(interfaceID: String) -> Result<Bool, Web3Error> {
146+
mutating public func supportsInterface(interfaceID: String) -> Result<Bool, Web3Error> {
147147
let options = Web3Options.defaultOptions()
148148
guard let transaction = self.resolverContract.method("supportsInterface", parameters: [interfaceID as AnyObject], options: options) else { return Result.failure(Web3Error.transactionSerializationError) }
149149
let result = transaction.call(options: options)
@@ -157,7 +157,7 @@ public struct ResolverENS {
157157
}
158158

159159
//MARK: - returns address for the given domain at given resolver
160-
mutating func addr(forDomain domain: String) -> Result<EthereumAddress, Web3Error> {
160+
mutating public func addr(forDomain domain: String) -> Result<EthereumAddress, Web3Error> {
161161
guard let nameHash = NameHash.nameHash(domain) else { return Result.failure(Web3Error.dataError) }
162162
let options = Web3Options.defaultOptions()
163163
guard let transaction = self.resolverContract.method("addr", parameters: [nameHash as AnyObject], options: options) else { return Result.failure(Web3Error.dataError) }
@@ -171,7 +171,7 @@ public struct ResolverENS {
171171
}
172172

173173
//MARK: - returns corresponding ENS to the requested node
174-
mutating func name(node: String) -> Result<String, Web3Error> {
174+
mutating public func name(node: String) -> Result<String, Web3Error> {
175175
let options = Web3Options.defaultOptions()
176176
guard let transaction = self.resolverContract.method("name", parameters: [node.lowercased() as AnyObject], options: options) else { return Result.failure(Web3Error.transactionSerializationError)}
177177
let result = transaction.call(options: options)
@@ -185,7 +185,7 @@ public struct ResolverENS {
185185
}
186186

187187
//MARK: - returns ABI in the requested encodings
188-
mutating func ABI(node: String, contentType: BigUInt) -> Result<(BigUInt, Data), Web3Error> {
188+
mutating public func ABI(node: String, contentType: BigUInt) -> Result<(BigUInt, Data), Web3Error> {
189189
let options = Web3Options.defaultOptions()
190190
guard let transaction = self.resolverContract.method("ABI", parameters: [node, contentType] as [AnyObject], options: options) else { return Result.failure(Web3Error.transactionSerializationError) }
191191
let result = transaction.call(options: options)
@@ -199,6 +199,23 @@ public struct ResolverENS {
199199
}
200200
}
201201

202-
//TODO: - func pubkey()
202+
mutating public func pubkey(node: String) -> Result<Point, Web3Error> {
203+
let options = Web3Options.defaultOptions()
204+
guard let transaction = self.resolverContract.method("pubkey", parameters: [node as AnyObject], options: options) else { return Result.failure(Web3Error.transactionSerializationError) }
205+
let result = transaction.call(options: options)
206+
switch result {
207+
case .success(let value):
208+
guard let x = value["x"] as? String else { return Result.failure(Web3Error.dataError) }
209+
guard let y = value["y"] as? String else { return Result.failure(Web3Error.dataError) }
210+
return Result(Point(x: x, y: y))
211+
case .failure(let error):
212+
return Result.failure(error)
213+
}
214+
}
215+
}
216+
217+
public struct Point {
218+
let x: String
219+
let y: String
203220
}
204221

web3swift/Web3/Classes/Web3+Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ extension Web3.Utils {
7777
"""
7878

7979
public static var resolverABI = """
80-
[{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentType","type": "uint256"}],"name":"ABI","outputs":[{"name":"","type":"uint256"},{"name":"","type":"bytes"}],"payable":false,"type":"function"}]
80+
[{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"interfaceID","type":"bytes4"}],"name":"supportsInterface","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"},{"name":"contentType","type": "uint256"}],"name":"ABI","outputs":[{"name":"","type":"uint256"},{"name":"","type":"bytes"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"node","type":"bytes32"}],"name":"pubkey","outputs":[{"name":"x","type":"bytes32"},{"name":"y","type":"bytes32"}],"payable":false,"type":"function"}]
8181
"""
8282

8383
}

0 commit comments

Comments
 (0)