Skip to content

Commit cd4ef5a

Browse files
committed
convenience function getAddress added
1 parent f6dfc57 commit cd4ef5a

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

web3swift/Utils/Classes/ENS.swift

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,59 @@ public struct ENS {
4848
}
4949
}
5050

51-
//TODO: -
51+
public mutating func getAddress(_ domain: String) -> Result<EthereumAddress, Web3Error> {
52+
let resolver = self.resolver(forDomain: domain)
53+
switch resolver {
54+
case .success(var resolver):
55+
let isAddrSupports = resolver.supportsInterface(interfaceID: ResolverENS.InterfaceName.addr.hash())
56+
switch isAddrSupports{
57+
case .success(let isSupported):
58+
if isSupported {
59+
let result = resolver.addr(forDomain: domain)
60+
switch result {
61+
case .success(let address):
62+
return Result(address)
63+
case .failure(let error):
64+
return Result.failure(error)
65+
}
66+
} else {
67+
return Result.failure(Web3Error.dataError)
68+
}
69+
case .failure(let error):
70+
return Result.failure(error)
71+
}
72+
case .failure(let error):
73+
return Result.failure(error)
74+
}
75+
}
76+
5277
/*
53-
1. Write a function that allows map domain to the name
54-
*/
78+
TODO: -
79+
*/
80+
//
81+
// public func setAddress(domain: String, address: EthereumAddress, options: Web3Options? = nil) {
82+
//
83+
// }
84+
//
85+
// public func getPubkey(domain: String) -> Result<[String: String], Web3Error> {
86+
//
87+
// }
88+
//
89+
// public func setPubkey(domain: String, x: String, y: String, options: Web3Options? = nil) {
90+
//
91+
// }
92+
//
93+
// public func getContent(domain: String) -> Result<String, Web3Error> {
94+
//
95+
// }
96+
//
97+
// public func setContent(domain: String, hash: String, optioins: Web3Options? = nil) {
98+
//
99+
// }
100+
//
101+
// public func getMultihash(domain: String) -> String {
102+
//
103+
// }
55104
}
56105

57106
public struct ResolverENS {

0 commit comments

Comments
 (0)