Skip to content

Commit 0a76a4a

Browse files
Delete hardcoded password, thus change public API in terms of ENS.
1 parent 7a15fb7 commit 0a76a4a

File tree

3 files changed

+26
-55
lines changed

3 files changed

+26
-55
lines changed

Sources/web3swift/Utils/ENS/ENS.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class ENS {
9797
}
9898

9999
// FIXME: Rewrite this to CodableTransaction
100-
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
100+
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
101101
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
102102
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
103103
}
@@ -132,7 +132,7 @@ public class ENS {
132132
}
133133

134134
// FIXME: Rewrite this to CodableTransaction
135-
public func setName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
135+
public func setName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
136136
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
137137
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
138138
}
@@ -168,7 +168,7 @@ public class ENS {
168168
}
169169

170170
// FIXME: Rewrite this to CodableTransaction
171-
public func setContent(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
171+
public func setContent(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
172172
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
173173
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
174174
}
@@ -203,7 +203,7 @@ public class ENS {
203203
}
204204

205205
// FIXME: Rewrite this to CodableTransaction
206-
public func setABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
206+
public func setABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
207207
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
208208
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
209209
}
@@ -238,7 +238,7 @@ public class ENS {
238238
}
239239

240240
// FIXME: Rewrite this to CodableTransaction
241-
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
241+
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
242242
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
243243
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
244244
}
@@ -273,7 +273,7 @@ public class ENS {
273273
}
274274

275275
// FIXME: Rewrite this to CodableTransaction
276-
public func setText(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
276+
public func setText(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
277277
guard let resolver = try? await self.registry.getResolver(forDomain: node) else {
278278
throw Web3Error.processingError(desc: "Failed to get resolver for domain")
279279
}

Sources/web3swift/Utils/ENS/ENSRegistry.swift

+8-20
Original file line numberDiff line numberDiff line change
@@ -71,63 +71,51 @@ public extension ENS {
7171
}
7272

7373
// FIXME: Rewrite this to CodableTransaction
74-
public func setOwner(node: String, owner: EthereumAddress, options: CodableTransaction?, password: String? = nil) async throws -> TransactionSendingResult {
74+
public func setOwner(node: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
7575
var options = options ?? defaultOptions
7676
if let contractAddress = self.registryContractAddress {
7777
options.to = contractAddress
7878
}
7979
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
8080
guard let transaction = self.registryContract.createWriteOperation("setOwner", parameters: [nameHash, owner] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
81-
guard let result = await password == nil
82-
? try? transaction.writeToChain(password: "web3swift")
83-
: try? transaction.writeToChain(password: password!)
84-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
81+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
8582
return result
8683
}
8784

8885
// FIXME: Rewrite this to CodableTransaction
89-
public func setSubnodeOwner(node: String, label: String, owner: EthereumAddress, options: CodableTransaction?, password: String? = nil) async throws -> TransactionSendingResult {
86+
public func setSubnodeOwner(node: String, label: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
9087
var options = options ?? defaultOptions
9188
if let contractAddress = self.registryContractAddress {
9289
options.to = contractAddress
9390
}
9491
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
9592
guard let labelHash = NameHash.nameHash(label) else {throw Web3Error.processingError(desc: "Failed to get label hash")}
9693
guard let transaction = self.registryContract.createWriteOperation("setSubnodeOwner", parameters: [nameHash, labelHash, owner] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
97-
guard let result = await password == nil
98-
? try? transaction.writeToChain(password: "web3swift")
99-
: try? transaction.writeToChain(password: password!)
100-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
94+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
10195
return result
10296
}
10397

10498
// FIXME: Rewrite this to CodableTransaction
105-
public func setResolver(node: String, resolver: EthereumAddress, options: CodableTransaction?, password: String? = nil) async throws -> TransactionSendingResult {
99+
public func setResolver(node: String, resolver: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
106100
var options = options ?? defaultOptions
107101
if let contractAddress = self.registryContractAddress {
108102
options.to = contractAddress
109103
}
110104
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
111105
guard let transaction = self.registryContract.createWriteOperation("setResolver", parameters: [nameHash, resolver] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
112-
guard let result = await password == nil
113-
? try? transaction.writeToChain(password: "web3swift")
114-
: try? transaction.writeToChain(password: password!)
115-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
106+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
116107
return result
117108
}
118109

119110
// FIXME: Rewrite this to CodableTransaction
120-
public func setTTL(node: String, ttl: BigUInt, options: CodableTransaction?, password: String? = nil) async throws -> TransactionSendingResult {
111+
public func setTTL(node: String, ttl: BigUInt, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
121112
var options = options ?? defaultOptions
122113
if let contractAddress = self.registryContractAddress {
123114
options.to = contractAddress
124115
}
125116
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
126117
guard let transaction = self.registryContract.createWriteOperation("setTTL", parameters: [nameHash, ttl] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
127-
guard let result = await password == nil
128-
? try? transaction.writeToChain(password: "web3swift")
129-
: try? transaction.writeToChain(password: password!)
130-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
118+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
131119
return result
132120
}
133121
}

Sources/web3swift/Utils/ENS/ENSResolver.swift

+12-29
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,12 @@ public extension ENS {
9191

9292
// FIXME: Rewrite this to CodableTransaction
9393
@available(*, message: "Available for only owner")
94-
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
94+
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
9595
var options = options ?? defaultOptions
9696
options.to = self.resolverContractAddress
9797
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
9898
guard let transaction = self.resolverContract.createWriteOperation("setAddr", parameters: [nameHash, address] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
99-
guard let result = await password == nil
100-
? try? transaction.writeToChain(password: "web3swift")
101-
: try? transaction.writeToChain(password: password!)
102-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
99+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
103100
return result
104101
}
105102

@@ -113,15 +110,12 @@ public extension ENS {
113110

114111
// FIXME: Rewrite this to CodableTransaction
115112
@available(*, message: "Available for only owner")
116-
func setCanonicalName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
113+
func setCanonicalName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
117114
var options = options ?? defaultOptions
118115
options.to = self.resolverContractAddress
119116
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
120117
guard let transaction = self.resolverContract.createWriteOperation("setName", parameters: [nameHash, name] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
121-
guard let result = await password == nil
122-
? try? transaction.writeToChain(password: "web3swift")
123-
: try? transaction.writeToChain(password: password!)
124-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
118+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
125119
return result
126120
}
127121

@@ -135,14 +129,12 @@ public extension ENS {
135129

136130
// FIXME: Rewrite this to CodableTransaction
137131
@available(*, message: "Available for only owner")
138-
func setContentHash(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
132+
func setContentHash(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
139133
var options = options ?? defaultOptions
140134
options.to = self.resolverContractAddress
141135
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
142136
guard let transaction = self.resolverContract.createWriteOperation("setContenthash", parameters: [nameHash, hash] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
143-
guard let result = await password == nil
144-
? try? transaction.writeToChain(password: "web3swift")
145-
: try? transaction.writeToChain(password: password!)
137+
guard let result = try? await transaction.writeToChain(password: password)
146138
else {throw Web3Error.processingError(desc: "Can't send transaction")}
147139
return result
148140
}
@@ -158,15 +150,12 @@ public extension ENS {
158150

159151
// FIXME: Rewrite this to CodableTransaction
160152
@available(*, message: "Available for only owner")
161-
func setContractABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
153+
func setContractABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
162154
var options = options ?? defaultOptions
163155
options.to = self.resolverContractAddress
164156
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
165157
guard let transaction = self.resolverContract.createWriteOperation("setABI", parameters: [nameHash, contentType.rawValue, data] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
166-
guard let result = await password == nil
167-
? try? transaction.writeToChain(password: "web3swift")
168-
: try? transaction.writeToChain(password: password!)
169-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
158+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
170159
return result
171160
}
172161

@@ -182,16 +171,13 @@ public extension ENS {
182171

183172
// FIXME: Rewrite this to CodableTransaction
184173
@available(*, message: "Available for only owner")
185-
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
174+
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
186175
var options = options ?? defaultOptions
187176
options.to = self.resolverContractAddress
188177
let pubkeyWithoutPrefix = publicKey.getComponentsWithoutPrefix()
189178
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
190179
guard let transaction = self.resolverContract.createWriteOperation("setPubkey", parameters: [nameHash, pubkeyWithoutPrefix.x, pubkeyWithoutPrefix.y] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
191-
guard let result = await password == nil
192-
? try? transaction.writeToChain(password: "web3swift")
193-
: try? transaction.writeToChain(password: password!)
194-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
180+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
195181
return result
196182
}
197183

@@ -205,15 +191,12 @@ public extension ENS {
205191

206192
// FIXME: Rewrite this to CodableTransaction
207193
@available(*, message: "Available for only owner")
208-
public func setTextData(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String? = nil) async throws -> TransactionSendingResult {
194+
public func setTextData(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
209195
var options = options ?? defaultOptions
210196
options.to = self.resolverContractAddress
211197
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
212198
guard let transaction = self.resolverContract.createWriteOperation("setText", parameters: [nameHash, key, value] as [AnyObject], extraData: Data() ) else {throw Web3Error.transactionSerializationError}
213-
guard let result = await password == nil
214-
? try? transaction.writeToChain(password: "web3swift")
215-
: try? transaction.writeToChain(password: password!)
216-
else {throw Web3Error.processingError(desc: "Can't send transaction")}
199+
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
217200
return result
218201
}
219202
}

0 commit comments

Comments
 (0)