Skip to content

Commit 434b4cf

Browse files
Merge pull request #730 from janndriessen/task/rename-default-options
2 parents 5063ca5 + 8180b0a commit 434b4cf

File tree

6 files changed

+46
-51
lines changed

6 files changed

+46
-51
lines changed

Sources/web3swift/Utils/ENS/ENS.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public class ENS {
7474
self.reverseRegistrar = reverseRegistrar
7575
}
7676

77-
// FIXME: Rewrite this to CodableTransaction
78-
lazy var defaultOptions: CodableTransaction = {
77+
lazy var defaultTransaction: CodableTransaction = {
7978
return CodableTransaction.emptyTransaction
8079
}()
8180

@@ -107,7 +106,7 @@ public class ENS {
107106
guard isAddrSupports else {
108107
throw Web3Error.processingError(desc: "Address isn't supported")
109108
}
110-
var options = options ?? defaultOptions
109+
var options = options ?? defaultTransaction
111110
options.to = resolver.resolverContractAddress
112111
guard let result = try? await resolver.setAddress(forNode: node, address: address, options: options, password: password) else {
113112
throw Web3Error.processingError(desc: "Can't get result")
@@ -142,7 +141,7 @@ public class ENS {
142141
guard isNameSupports else {
143142
throw Web3Error.processingError(desc: "Name isn't supported")
144143
}
145-
var options = options ?? defaultOptions
144+
var options = options ?? defaultTransaction
146145
options.to = resolver.resolverContractAddress
147146
guard let result = try? await resolver.setCanonicalName(forNode: node, name: name, options: options, password: password) else {
148147
throw Web3Error.processingError(desc: "Can't get result")
@@ -178,7 +177,7 @@ public class ENS {
178177
guard isContentSupports else {
179178
throw Web3Error.processingError(desc: "Content isn't supported")
180179
}
181-
var options = options ?? defaultOptions
180+
var options = options ?? defaultTransaction
182181
options.to = resolver.resolverContractAddress
183182
guard let result = try? await resolver.setContentHash(forNode: node, hash: hash, options: options, password: password) else {
184183
throw Web3Error.processingError(desc: "Can't get result")
@@ -213,7 +212,7 @@ public class ENS {
213212
guard isABISupports else {
214213
throw Web3Error.processingError(desc: "ABI isn't supported")
215214
}
216-
var options = options ?? defaultOptions
215+
var options = options ?? defaultTransaction
217216
options.to = resolver.resolverContractAddress
218217
guard let result = try? await resolver.setContractABI(forNode: node, contentType: contentType, data: data, options: options, password: password) else {
219218
throw Web3Error.processingError(desc: "Can't get result")
@@ -248,7 +247,7 @@ public class ENS {
248247
guard isPKSupports else {
249248
throw Web3Error.processingError(desc: "Public Key isn't supported")
250249
}
251-
var options = options ?? defaultOptions
250+
var options = options ?? defaultTransaction
252251
options.to = resolver.resolverContractAddress
253252
guard let result = try? await resolver.setPublicKey(forNode: node, publicKey: publicKey, options: options, password: password) else {
254253
throw Web3Error.processingError(desc: "Can't get result")
@@ -283,7 +282,7 @@ public class ENS {
283282
guard isTextSupports else {
284283
throw Web3Error.processingError(desc: "Text isn't supported")
285284
}
286-
var options = options ?? defaultOptions
285+
var options = options ?? defaultTransaction
287286
options.to = resolver.resolverContractAddress
288287
guard let result = try? await resolver.setTextData(forNode: node, key: key, value: value, options: options, password: password) else {
289288
throw Web3Error.processingError(desc: "Can't get result")

Sources/web3swift/Utils/ENS/ENSBaseRegistrar.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Web3Core
1212
// FIXME: Rewrite this to CodableTransaction
1313
public extension ENS {
1414
class BaseRegistrar: ERC721 {
15-
lazy var defaultOptions: CodableTransaction = {
15+
lazy var defaultTransaction: CodableTransaction = {
1616
return CodableTransaction.emptyTransaction
1717
}()
1818

@@ -34,24 +34,24 @@ public extension ENS {
3434

3535
@available(*, message: "Available for only owner")
3636
public func addController(from: EthereumAddress, controllerAddress: EthereumAddress) throws -> WriteOperation {
37-
defaultOptions.from = from
38-
defaultOptions.to = self.address
37+
defaultTransaction.from = from
38+
defaultTransaction.to = self.address
3939
guard let transaction = self.contract.createWriteOperation("addController", parameters: [controllerAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
4040
return transaction
4141
}
4242

4343
@available(*, message: "Available for only owner")
4444
public func removeController(from: EthereumAddress, controllerAddress: EthereumAddress) throws -> WriteOperation {
45-
defaultOptions.from = from
46-
defaultOptions.to = self.address
45+
defaultTransaction.from = from
46+
defaultTransaction.to = self.address
4747
guard let transaction = self.contract.createWriteOperation("removeController", parameters: [controllerAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
4848
return transaction
4949
}
5050

5151
@available(*, message: "Available for only owner")
5252
public func setResolver(from: EthereumAddress, resolverAddress: EthereumAddress) throws -> WriteOperation {
53-
defaultOptions.from = from
54-
defaultOptions.to = self.address
53+
defaultTransaction.from = from
54+
defaultTransaction.to = self.address
5555
guard let transaction = self.contract.createWriteOperation("setResolver", parameters: [resolverAddress as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
5656
return transaction
5757
}
@@ -72,8 +72,8 @@ public extension ENS {
7272
}
7373

7474
public func reclaim(from: EthereumAddress, record: BigUInt) throws -> WriteOperation {
75-
defaultOptions.from = from
76-
defaultOptions.to = self.address
75+
defaultTransaction.from = from
76+
defaultTransaction.to = self.address
7777
guard let transaction = self.contract.createWriteOperation("reclaim", parameters: [record as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
7878
return transaction
7979
}

Sources/web3swift/Utils/ENS/ENSRegistry.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public extension ENS {
3535
}
3636
}
3737

38-
// FIXME: Rewrite this to CodableTransaction
39-
lazy var defaultOptions: CodableTransaction = {
38+
lazy var defaultTransaction: CodableTransaction = {
4039
return CodableTransaction.emptyTransaction
4140
}()
4241

@@ -72,7 +71,7 @@ public extension ENS {
7271

7372
// FIXME: Rewrite this to CodableTransaction
7473
public func setOwner(node: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
75-
var options = options ?? defaultOptions
74+
var options = options ?? defaultTransaction
7675
if let contractAddress = self.registryContractAddress {
7776
options.to = contractAddress
7877
}
@@ -84,7 +83,7 @@ public extension ENS {
8483

8584
// FIXME: Rewrite this to CodableTransaction
8685
public func setSubnodeOwner(node: String, label: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
87-
var options = options ?? defaultOptions
86+
var options = options ?? defaultTransaction
8887
if let contractAddress = self.registryContractAddress {
8988
options.to = contractAddress
9089
}
@@ -97,7 +96,7 @@ public extension ENS {
9796

9897
// FIXME: Rewrite this to CodableTransaction
9998
public func setResolver(node: String, resolver: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
100-
var options = options ?? defaultOptions
99+
var options = options ?? defaultTransaction
101100
if let contractAddress = self.registryContractAddress {
102101
options.to = contractAddress
103102
}
@@ -109,7 +108,7 @@ public extension ENS {
109108

110109
// FIXME: Rewrite this to CodableTransaction
111110
public func setTTL(node: String, ttl: BigUInt, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
112-
var options = options ?? defaultOptions
111+
var options = options ?? defaultTransaction
113112
if let contractAddress = self.registryContractAddress {
114113
options.to = contractAddress
115114
}

Sources/web3swift/Utils/ENS/ENSResolver.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public extension ENS {
5151
return contract!
5252
}()
5353

54-
// FIXME: Rewrite this to CodableTransaction
55-
lazy var defaultOptions: CodableTransaction = {
54+
lazy var defaultTransaction: CodableTransaction = {
5655
return CodableTransaction.emptyTransaction
5756
}()
5857

@@ -107,7 +106,7 @@ public extension ENS {
107106
// FIXME: Rewrite this to CodableTransaction
108107
@available(*, message: "Available for only owner")
109108
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
110-
var options = options ?? defaultOptions
109+
var options = options ?? defaultTransaction
111110
options.to = self.resolverContractAddress
112111
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
113112
guard let transaction = self.resolverContract.createWriteOperation("setAddr", parameters: [nameHash, address] as [AnyObject]) else {throw Web3Error.transactionSerializationError}
@@ -126,7 +125,7 @@ public extension ENS {
126125
// FIXME: Rewrite this to CodableTransaction
127126
@available(*, message: "Available for only owner")
128127
func setCanonicalName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
129-
var options = options ?? defaultOptions
128+
var options = options ?? defaultTransaction
130129
options.to = self.resolverContractAddress
131130
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
132131
guard let transaction = self.resolverContract.createWriteOperation("setName", parameters: [nameHash, name] as [AnyObject]) else {throw Web3Error.transactionSerializationError}
@@ -145,7 +144,7 @@ public extension ENS {
145144
// FIXME: Rewrite this to CodableTransaction
146145
@available(*, message: "Available for only owner")
147146
func setContentHash(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
148-
var options = options ?? defaultOptions
147+
var options = options ?? defaultTransaction
149148
options.to = self.resolverContractAddress
150149
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
151150
guard let transaction = self.resolverContract.createWriteOperation("setContenthash", parameters: [nameHash, hash] as [AnyObject]) else {throw Web3Error.transactionSerializationError}
@@ -166,7 +165,7 @@ public extension ENS {
166165
// FIXME: Rewrite this to CodableTransaction
167166
@available(*, message: "Available for only owner")
168167
func setContractABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
169-
var options = options ?? defaultOptions
168+
var options = options ?? defaultTransaction
170169
options.to = self.resolverContractAddress
171170
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
172171
guard let transaction = self.resolverContract.createWriteOperation("setABI", parameters: [nameHash, contentType.rawValue, data] as [AnyObject]) else {throw Web3Error.transactionSerializationError}
@@ -187,7 +186,7 @@ public extension ENS {
187186
// FIXME: Rewrite this to CodableTransaction
188187
@available(*, message: "Available for only owner")
189188
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
190-
var options = options ?? defaultOptions
189+
var options = options ?? defaultTransaction
191190
options.to = self.resolverContractAddress
192191
let pubkeyWithoutPrefix = publicKey.getComponentsWithoutPrefix()
193192
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
@@ -207,7 +206,7 @@ public extension ENS {
207206
// FIXME: Rewrite this to CodableTransaction
208207
@available(*, message: "Available for only owner")
209208
public func setTextData(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
210-
var options = options ?? defaultOptions
209+
var options = options ?? defaultTransaction
211210
options.to = self.resolverContractAddress
212211
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
213212
guard let transaction = self.resolverContract.createWriteOperation("setText", parameters: [nameHash, key, value] as [AnyObject]) else {throw Web3Error.transactionSerializationError}

Sources/web3swift/Utils/ENS/ENSReverseRegistrar.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public extension ENS {
2020
return contract!
2121
}()
2222

23-
// FIXME: Rewrite this to CodableTransaction
24-
lazy var defaultOptions: CodableTransaction = {
23+
lazy var defaultTransaction: CodableTransaction = {
2524
return CodableTransaction.emptyTransaction
2625
}()
2726

@@ -31,22 +30,22 @@ public extension ENS {
3130
}
3231

3332
public func claimAddress(from: EthereumAddress, owner: EthereumAddress) throws -> WriteOperation {
34-
defaultOptions.from = from
35-
defaultOptions.to = self.address
33+
defaultTransaction.from = from
34+
defaultTransaction.to = self.address
3635
guard let transaction = self.contract.createWriteOperation("claim", parameters: [owner as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
3736
return transaction
3837
}
3938

4039
public func claimAddressWithResolver(from: EthereumAddress, owner: EthereumAddress, resolver: EthereumAddress) throws -> WriteOperation {
41-
defaultOptions.from = from
42-
defaultOptions.to = self.address
40+
defaultTransaction.from = from
41+
defaultTransaction.to = self.address
4342
guard let transaction = self.contract.createWriteOperation("claimWithResolver", parameters: [owner, resolver] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
4443
return transaction
4544
}
4645

4746
public func setName(from: EthereumAddress, name: String) throws -> WriteOperation {
48-
defaultOptions.from = from
49-
defaultOptions.to = self.address
47+
defaultTransaction.from = from
48+
defaultTransaction.to = self.address
5049
guard let transaction = self.contract.createWriteOperation("setName", parameters: [name] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
5150
return transaction
5251
}

Sources/web3swift/Utils/ENS/ETHRegistrarController.swift

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public extension ENS {
2020
return contract!
2121
}()
2222

23-
// FIXME: Rewrite this to CodableTransaction
24-
lazy var defaultOptions: CodableTransaction = {
23+
lazy var defaultTransaction: CodableTransaction = {
2524
return CodableTransaction.emptyTransaction
2625
}()
2726

@@ -59,34 +58,34 @@ public extension ENS {
5958
}
6059

6160
public func sumbitCommitment(from: EthereumAddress, commitment: Data) throws -> WriteOperation {
62-
defaultOptions.from = from
63-
defaultOptions.to = self.address
61+
defaultTransaction.from = from
62+
defaultTransaction.to = self.address
6463
guard let transaction = self.contract.createWriteOperation("commit", parameters: [commitment as AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
6564
return transaction
6665
}
6766

6867
public func registerName(from: EthereumAddress, name: String, owner: EthereumAddress, duration: UInt, secret: String, price: String) throws -> WriteOperation {
6968
guard let amount = Utilities.parseToBigUInt(price, units: .ether) else {throw Web3Error.inputError(desc: "Wrong price: no way for parsing to ether units")}
70-
defaultOptions.value = amount
71-
defaultOptions.from = from
72-
defaultOptions.to = self.address
69+
defaultTransaction.value = amount
70+
defaultTransaction.from = from
71+
defaultTransaction.to = self.address
7372
guard let transaction = self.contract.createWriteOperation("register", parameters: [name, owner.address, duration, secret] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
7473
return transaction
7574
}
7675

7776
public func extendNameRegistration(from: EthereumAddress, name: String, duration: UInt32, price: String) throws -> WriteOperation {
7877
guard let amount = Utilities.parseToBigUInt(price, units: .ether) else {throw Web3Error.inputError(desc: "Wrong price: no way for parsing to ether units")}
79-
defaultOptions.value = amount
80-
defaultOptions.from = from
81-
defaultOptions.to = self.address
78+
defaultTransaction.value = amount
79+
defaultTransaction.from = from
80+
defaultTransaction.to = self.address
8281
guard let transaction = self.contract.createWriteOperation("renew", parameters: [name, duration] as [AnyObject], extraData: Data()) else {throw Web3Error.transactionSerializationError}
8382
return transaction
8483
}
8584

8685
@available(*, message: "Available for only owner")
8786
public func withdraw(from: EthereumAddress) throws -> WriteOperation {
88-
defaultOptions.from = from
89-
defaultOptions.to = self.address
87+
defaultTransaction.from = from
88+
defaultTransaction.to = self.address
9089
guard let transaction = self.contract.createWriteOperation("withdraw", parameters: [AnyObject](), extraData: Data()) else {throw Web3Error.transactionSerializationError}
9190
return transaction
9291
}

0 commit comments

Comments
 (0)