Skip to content

Update ENS Resolver #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Sources/web3swift/Utils/ENS/ENSResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public extension ENS {
case CBOR = 4
case URI = 8
}

public enum InterfaceName {
case addr
case name
Expand Down Expand Up @@ -72,6 +72,14 @@ public extension ENS {
guard let supports = result["0"] as? Bool else {throw Web3Error.processingError(desc: "Can't get answer")}
return supports
}

public func interfaceImplementer(forNode node: String, interfaceID: String) throws -> EthereumAddress {
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
guard let transaction = self.resolverContract.read("interfaceImplementer", parameters: [nameHash, interfaceID] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
guard let result = try? transaction.call(transactionOptions: defaultOptions) else {throw Web3Error.processingError(desc: "Can't call transaction")}
guard let address = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Can't get address")}
return address
}

public func getAddress(forNode node: String) throws -> EthereumAddress {
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
Expand Down
Loading