Skip to content

Commit 2becf4e

Browse files
Merge pull request #165 from matter-labs/ENSPermanentRegistrarSupport
Added reverse registrar
2 parents 4b14b50 + 0e4db01 commit 2becf4e

File tree

5 files changed

+236
-7
lines changed

5 files changed

+236
-7
lines changed

web3swift.xcodeproj/project.pbxproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
3A3F59BF225931BE0075C9E7 /* ENSResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = B219DC162154F3EE0035BF94 /* ENSResolver.swift */; };
2121
3A52CCB22264A6D4001C8D7A /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
2222
3A52CCB32264A6DC001C8D7A /* NonceMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 81ED4EA72190D922003E932E /* NonceMiddleware.swift */; };
23-
3A52CCB72264B712001C8D7A /* BaseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB62264B712001C8D7A /* BaseRegistrar.swift */; };
24-
3A52CCB82264B712001C8D7A /* BaseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB62264B712001C8D7A /* BaseRegistrar.swift */; };
23+
3A52CCB72264B712001C8D7A /* ENSBaseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB62264B712001C8D7A /* ENSBaseRegistrar.swift */; };
24+
3A52CCB82264B712001C8D7A /* ENSBaseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB62264B712001C8D7A /* ENSBaseRegistrar.swift */; };
2525
3A52CCBA2264B728001C8D7A /* ETHRegistrarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB92264B728001C8D7A /* ETHRegistrarController.swift */; };
2626
3A52CCBB2264B728001C8D7A /* ETHRegistrarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCB92264B728001C8D7A /* ETHRegistrarController.swift */; };
2727
3A52CCBD226747EB001C8D7A /* PublicKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCBC226747EB001C8D7A /* PublicKey.swift */; };
2828
3A52CCBE226747EB001C8D7A /* PublicKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCBC226747EB001C8D7A /* PublicKey.swift */; };
2929
3A52CCC022675CFC001C8D7A /* ENSRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCBF22675CFC001C8D7A /* ENSRegistry.swift */; };
3030
3A52CCC122675CFC001C8D7A /* ENSRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A52CCBF22675CFC001C8D7A /* ENSRegistry.swift */; };
31+
3AD7D0AD226B5AA900E0F98D /* ENSReverseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD7D0AC226B5AA900E0F98D /* ENSReverseRegistrar.swift */; };
32+
3AD7D0AE226B5AA900E0F98D /* ENSReverseRegistrar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AD7D0AC226B5AA900E0F98D /* ENSReverseRegistrar.swift */; };
3133
3AE8913C2256286C00D08E99 /* Web3+ERC1155.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE8911C2256286B00D08E99 /* Web3+ERC1155.swift */; };
3234
3AE8913D2256286C00D08E99 /* Web3+ERC1155.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE8911C2256286B00D08E99 /* Web3+ERC1155.swift */; };
3335
3AE8913E2256286C00D08E99 /* Web3+ERC1376.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE8911E2256286B00D08E99 /* Web3+ERC1376.swift */; };
@@ -268,10 +270,11 @@
268270
2B8FEFF3962166E1BEADC886 /* Pods_web3swift_ios.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3swift_ios.framework; sourceTree = BUILT_PRODUCTS_DIR; };
269271
342700493511FEB189700D13 /* Pods-web3swift-iOS_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-web3swift-iOS_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-web3swift-iOS_Tests/Pods-web3swift-iOS_Tests.debug.xcconfig"; sourceTree = "<group>"; };
270272
391A0D2EF42488E5C8AB2F71 /* Pods_web3swift_osx_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_web3swift_osx_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
271-
3A52CCB62264B712001C8D7A /* BaseRegistrar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseRegistrar.swift; sourceTree = "<group>"; };
273+
3A52CCB62264B712001C8D7A /* ENSBaseRegistrar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENSBaseRegistrar.swift; sourceTree = "<group>"; };
272274
3A52CCB92264B728001C8D7A /* ETHRegistrarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ETHRegistrarController.swift; sourceTree = "<group>"; };
273275
3A52CCBC226747EB001C8D7A /* PublicKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublicKey.swift; sourceTree = "<group>"; };
274276
3A52CCBF22675CFC001C8D7A /* ENSRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENSRegistry.swift; sourceTree = "<group>"; };
277+
3AD7D0AC226B5AA900E0F98D /* ENSReverseRegistrar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ENSReverseRegistrar.swift; sourceTree = "<group>"; };
275278
3AE8911C2256286B00D08E99 /* Web3+ERC1155.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+ERC1155.swift"; sourceTree = "<group>"; };
276279
3AE8911E2256286B00D08E99 /* Web3+ERC1376.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+ERC1376.swift"; sourceTree = "<group>"; };
277280
3AE891202256286B00D08E99 /* Web3+ERC888.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+ERC888.swift"; sourceTree = "<group>"; };
@@ -537,7 +540,8 @@
537540
3A52CCBC226747EB001C8D7A /* PublicKey.swift */,
538541
B219DC162154F3EE0035BF94 /* ENSResolver.swift */,
539542
3A52CCBF22675CFC001C8D7A /* ENSRegistry.swift */,
540-
3A52CCB62264B712001C8D7A /* BaseRegistrar.swift */,
543+
3AD7D0AC226B5AA900E0F98D /* ENSReverseRegistrar.swift */,
544+
3A52CCB62264B712001C8D7A /* ENSBaseRegistrar.swift */,
541545
3A52CCB92264B728001C8D7A /* ETHRegistrarController.swift */,
542546
);
543547
path = ENS;
@@ -1193,6 +1197,7 @@
11931197
3AE891642256620200D08E99 /* Web3+WebsocketProvider.swift in Sources */,
11941198
81195AB020D7FF8500ABC6B1 /* Promise+Web3+Contract+GetIndexedEvents.swift in Sources */,
11951199
3A52CCBD226747EB001C8D7A /* PublicKey.swift in Sources */,
1200+
3AD7D0AD226B5AA900E0F98D /* ENSReverseRegistrar.swift in Sources */,
11961201
81EB1E4B208173D7003BD47F /* Web3+Personal.swift in Sources */,
11971202
81909D1821862D5A007D2AE5 /* Web3+Eventloop.swift in Sources */,
11981203
81A1824B20D7DF1B0016741F /* Promise+Web3+Personal+UnlockAccount.swift in Sources */,
@@ -1268,7 +1273,7 @@
12681273
81A1822B20D67A1B0016741F /* Promise+Web3+Eth+GetTransactionDetails.swift in Sources */,
12691274
815630042007BC8F00A0EC2F /* BIP39+WordLists.swift in Sources */,
12701275
8113D2CE1FD7E1590074282C /* EthereumTransaction.swift in Sources */,
1271-
3A52CCB72264B712001C8D7A /* BaseRegistrar.swift in Sources */,
1276+
3A52CCB72264B712001C8D7A /* ENSBaseRegistrar.swift in Sources */,
12721277
3AE8914E2256286C00D08E99 /* Web3+ERC721.swift in Sources */,
12731278
81A1821F20D676BC0016741F /* Promise+Web3+Eth+GetTransactionCount.swift in Sources */,
12741279
81A1821520D5A2700016741F /* Promise+Web3+Eth+GetBalance.swift in Sources */,
@@ -1322,6 +1327,7 @@
13221327
3AE891652256620200D08E99 /* Web3+WebsocketProvider.swift in Sources */,
13231328
81909D1921862D5A007D2AE5 /* Web3+Eventloop.swift in Sources */,
13241329
3A52CCBE226747EB001C8D7A /* PublicKey.swift in Sources */,
1330+
3AD7D0AE226B5AA900E0F98D /* ENSReverseRegistrar.swift in Sources */,
13251331
8125F06A20499AC300A0F2FE /* BloomFilter.swift in Sources */,
13261332
81C0FD062044A8D100D82FAF /* TransactionSigner.swift in Sources */,
13271333
41948123203630530065A83B /* Web3+JSONRPC.swift in Sources */,
@@ -1397,7 +1403,7 @@
13971403
81909D1321862D17007D2AE5 /* Web3+ReadingTransaction.swift in Sources */,
13981404
4194813F203630530065A83B /* Dictionary+Extension.swift in Sources */,
13991405
41948140203630530065A83B /* Array+Extension.swift in Sources */,
1400-
3A52CCB82264B712001C8D7A /* BaseRegistrar.swift in Sources */,
1406+
3A52CCB82264B712001C8D7A /* ENSBaseRegistrar.swift in Sources */,
14011407
3AE8914F2256286C00D08E99 /* Web3+ERC721.swift in Sources */,
14021408
81A1822020D676BC0016741F /* Promise+Web3+Eth+GetTransactionCount.swift in Sources */,
14031409
81A1821620D5A2700016741F /* Promise+Web3+Eth+GetBalance.swift in Sources */,

web3swift/Utils/ENS/ENS.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ENS {
1515
var resolver: Resolver? = nil
1616
var baseRegistrar: BaseRegistrar? = nil
1717
var registrarController: ETHRegistrarController? = nil
18+
var reverseRegistrar: ReverseRegistrar? = nil
1819

1920
init?(web3: web3) {
2021
self.web3 = web3
@@ -62,11 +63,23 @@ public class ENS {
6263
self.registrarController = registrarController
6364
}
6465

66+
func setReverseRegistrar(_ reverseRegistrar: ReverseRegistrar) throws {
67+
guard reverseRegistrar.web3.provider.url == self.web3.provider.url else {
68+
throw Web3Error.processingError(desc: "Registrar controller should use same provider as ENS")
69+
}
70+
self.reverseRegistrar = reverseRegistrar
71+
}
72+
73+
func setReverseRegistrar(withAddress address: EthereumAddress) {
74+
let reverseRegistrar = ReverseRegistrar(web3: web3, address: address)
75+
self.reverseRegistrar = reverseRegistrar
76+
}
77+
6578
lazy var defaultOptions: TransactionOptions = {
6679
return TransactionOptions.defaultOptions
6780
}()
6881

69-
//MARK: - Convenience resolver methods
82+
//MARK: - Convenience public resolver methods
7083
public func getAddress(forNode node: String) throws -> EthereumAddress {
7184
guard let resolver = try? self.registry.getResolver(forDomain: node) else {
7285
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//
2+
// ENSReverseRegistrar.swift
3+
// web3swift
4+
//
5+
// Created by Anton on 20/04/2019.
6+
// Copyright © 2019 The Matter Inc. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import BigInt
11+
import EthereumAddress
12+
13+
public extension ENS {
14+
class ReverseRegistrar {
15+
let web3: web3
16+
let address: EthereumAddress
17+
18+
lazy var contract: web3.web3contract = {
19+
let contract = self.web3.contract(Web3.Utils.reverseRegistrarABI, at: self.address, abiVersion: 2)
20+
precondition(contract != nil)
21+
return contract!
22+
}()
23+
24+
lazy var defaultOptions: TransactionOptions = {
25+
return TransactionOptions.defaultOptions
26+
}()
27+
28+
init(web3: web3, address: EthereumAddress) {
29+
self.web3 = web3
30+
self.address = address
31+
}
32+
33+
public func claimAddress(from: EthereumAddress, owner: EthereumAddress) throws -> WriteTransaction {
34+
defaultOptions.from = from
35+
defaultOptions.to = self.address
36+
guard let transaction = self.contract.write("claim", parameters: [owner as AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
37+
return transaction
38+
}
39+
40+
public func claimAddressWithResolver(from: EthereumAddress, owner: EthereumAddress, resolver: EthereumAddress) throws -> WriteTransaction {
41+
defaultOptions.from = from
42+
defaultOptions.to = self.address
43+
guard let transaction = self.contract.write("claimWithResolver", parameters: [owner, resolver] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
44+
return transaction
45+
}
46+
47+
public func setName(from: EthereumAddress, name: String) throws -> WriteTransaction {
48+
defaultOptions.from = from
49+
defaultOptions.to = self.address
50+
guard let transaction = self.contract.write("setName", parameters: [name] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
51+
return transaction
52+
}
53+
54+
public func getReverseRecordName(address: EthereumAddress) throws -> Data {
55+
guard let transaction = self.contract.read("node", parameters: [address] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
56+
guard let result = try? transaction.call(transactionOptions: defaultOptions) else {throw Web3Error.processingError(desc: "Can't call transaction")}
57+
guard let name = result["0"] as? Data else {throw Web3Error.processingError(desc: "Can't get answer")}
58+
return name
59+
}
60+
61+
public func getDefaultResolver() throws -> EthereumAddress {
62+
guard let transaction = self.contract.read("defaultResolver", parameters: [] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
63+
guard let result = try? transaction.call(transactionOptions: defaultOptions) else {throw Web3Error.processingError(desc: "Can't call transaction")}
64+
guard let address = result["0"] as? EthereumAddress else {throw Web3Error.processingError(desc: "Can't get answer")}
65+
return address
66+
}
67+
}
68+
}

web3swift/Web3/Web3+Utils.swift

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4742,6 +4742,148 @@ extension Web3.Utils {
47424742
"type": "event"
47434743
}
47444744
]
4745+
"""
4746+
4747+
public static var reverseRegistrarABI = """
4748+
[
4749+
{
4750+
"constant": false,
4751+
"inputs": [
4752+
{
4753+
"name": "owner",
4754+
"type": "address"
4755+
},
4756+
{
4757+
"name": "resolver",
4758+
"type": "address"
4759+
}
4760+
],
4761+
"name": "claimWithResolver",
4762+
"outputs": [
4763+
{
4764+
"name": "",
4765+
"type": "bytes32"
4766+
}
4767+
],
4768+
"payable": false,
4769+
"stateMutability": "nonpayable",
4770+
"type": "function"
4771+
},
4772+
{
4773+
"constant": false,
4774+
"inputs": [
4775+
{
4776+
"name": "owner",
4777+
"type": "address"
4778+
}
4779+
],
4780+
"name": "claim",
4781+
"outputs": [
4782+
{
4783+
"name": "",
4784+
"type": "bytes32"
4785+
}
4786+
],
4787+
"payable": false,
4788+
"stateMutability": "nonpayable",
4789+
"type": "function"
4790+
},
4791+
{
4792+
"constant": true,
4793+
"inputs": [],
4794+
"name": "ens",
4795+
"outputs": [
4796+
{
4797+
"name": "",
4798+
"type": "address"
4799+
}
4800+
],
4801+
"payable": false,
4802+
"stateMutability": "view",
4803+
"type": "function"
4804+
},
4805+
{
4806+
"constant": true,
4807+
"inputs": [],
4808+
"name": "ADDR_REVERSE_NODE",
4809+
"outputs": [
4810+
{
4811+
"name": "",
4812+
"type": "bytes32"
4813+
}
4814+
],
4815+
"payable": false,
4816+
"stateMutability": "view",
4817+
"type": "function"
4818+
},
4819+
{
4820+
"constant": true,
4821+
"inputs": [],
4822+
"name": "defaultResolver",
4823+
"outputs": [
4824+
{
4825+
"name": "",
4826+
"type": "address"
4827+
}
4828+
],
4829+
"payable": false,
4830+
"stateMutability": "view",
4831+
"type": "function"
4832+
},
4833+
{
4834+
"constant": true,
4835+
"inputs": [
4836+
{
4837+
"name": "addr",
4838+
"type": "address"
4839+
}
4840+
],
4841+
"name": "node",
4842+
"outputs": [
4843+
{
4844+
"name": "",
4845+
"type": "bytes32"
4846+
}
4847+
],
4848+
"payable": false,
4849+
"stateMutability": "pure",
4850+
"type": "function"
4851+
},
4852+
{
4853+
"constant": false,
4854+
"inputs": [
4855+
{
4856+
"name": "name",
4857+
"type": "string"
4858+
}
4859+
],
4860+
"name": "setName",
4861+
"outputs": [
4862+
{
4863+
"name": "",
4864+
"type": "bytes32"
4865+
}
4866+
],
4867+
"payable": false,
4868+
"stateMutability": "nonpayable",
4869+
"type": "function"
4870+
},
4871+
{
4872+
"inputs": [
4873+
{
4874+
"name": "ensAddr",
4875+
"type": "address"
4876+
},
4877+
{
4878+
"name": "resolverAddr",
4879+
"type": "address"
4880+
}
4881+
],
4882+
"payable": false,
4883+
"stateMutability": "nonpayable",
4884+
"type": "constructor"
4885+
}
4886+
]
47454887
"""
47464888

47474889
//function setAddr(bytes32 node, address addr)

0 commit comments

Comments
 (0)