Skip to content

Commit c66d204

Browse files
fix: createNewAccount refactoring
Refactor createNewAccount function to be an internal function and remove unused password argument
2 parents f0905c2 + 1035db1 commit c66d204

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

Sources/Web3Core/KeystoreManager/BIP32Keystore.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class BIP32Keystore: AbstractKeystore {
111111
addressStorage = PathAddressStorage()
112112
guard let rootNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else { return nil }
113113
self.rootPrefix = prefixPath
114-
try createNewAccount(parentNode: rootNode, password: password)
114+
try createNewAccount(parentNode: rootNode)
115115
guard let serializedRootNode = rootNode.serialize(serializePublic: false) else {
116116
throw AbstractKeystoreError.keyDerivationError
117117
}
@@ -129,14 +129,14 @@ public class BIP32Keystore: AbstractKeystore {
129129
guard rootNode.depth == prefixPath.components(separatedBy: "/").count - 1 else {
130130
throw AbstractKeystoreError.encryptionError("Derivation depth mismatch")
131131
}
132-
try createNewAccount(parentNode: rootNode, password: password)
132+
try createNewAccount(parentNode: rootNode)
133133
guard let serializedRootNode = rootNode.serialize(serializePublic: false) else {
134134
throw AbstractKeystoreError.keyDerivationError
135135
}
136136
try encryptDataToStorage(password, data: serializedRootNode, aesMode: self.keystoreParams!.crypto.cipher)
137137
}
138138

139-
func createNewAccount(parentNode: HDNode, password: String = "web3swift") throws {
139+
internal func createNewAccount(parentNode: HDNode) throws {
140140
let maxIndex = addressStorage.paths
141141
.compactMap { $0.components(separatedBy: "/").last }
142142
.compactMap { UInt32($0) }

Sources/web3swift/Utils/ENS/ENS.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ public class ENS {
106106
guard isAddrSupports else {
107107
throw Web3Error.processingError(desc: "Address isn't supported")
108108
}
109-
var options = transaction ?? defaultTransaction
110-
options.to = resolver.resolverContractAddress
111-
guard let result = try? await resolver.setAddress(forNode: node, address: address, transaction: options, password: password) else {
109+
var transaction = transaction ?? defaultTransaction
110+
transaction.to = resolver.resolverContractAddress
111+
guard let result = try? await resolver.setAddress(forNode: node, address: address, transaction: transaction, password: password) else {
112112
throw Web3Error.processingError(desc: "Can't get result")
113113
}
114114
return result

Sources/web3swift/Utils/ENS/ENSRegistry.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public extension ENS {
7676
}
7777

7878
// FIXME: Rewrite this to CodableTransaction
79-
public func setOwner(node: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
80-
var options = options ?? defaultTransaction
79+
public func setOwner(node: String, owner: EthereumAddress, transaction: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
80+
var transaction = transaction ?? defaultTransaction
8181
if let contractAddress = self.registryContractAddress {
82-
options.to = contractAddress
82+
transaction.to = contractAddress
8383
}
8484
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
8585

@@ -90,10 +90,10 @@ public extension ENS {
9090
}
9191

9292
// FIXME: Rewrite this to CodableTransaction
93-
public func setSubnodeOwner(node: String, label: String, owner: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
94-
var options = options ?? defaultTransaction
93+
public func setSubnodeOwner(node: String, label: String, owner: EthereumAddress, transaction: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
94+
var transaction = transaction ?? defaultTransaction
9595
if let contractAddress = self.registryContractAddress {
96-
options.to = contractAddress
96+
transaction.to = contractAddress
9797
}
9898
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
9999
guard let labelHash = NameHash.nameHash(label) else {throw Web3Error.processingError(desc: "Failed to get label hash")}
@@ -105,10 +105,10 @@ public extension ENS {
105105
}
106106

107107
// FIXME: Rewrite this to CodableTransaction
108-
public func setResolver(node: String, resolver: EthereumAddress, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
109-
var options = options ?? defaultTransaction
108+
public func setResolver(node: String, resolver: EthereumAddress, transaction: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
109+
var transaction = transaction ?? defaultTransaction
110110
if let contractAddress = self.registryContractAddress {
111-
options.to = contractAddress
111+
transaction.to = contractAddress
112112
}
113113
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
114114

@@ -119,10 +119,10 @@ public extension ENS {
119119
}
120120

121121
// FIXME: Rewrite this to CodableTransaction
122-
public func setTTL(node: String, ttl: BigUInt, options: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
123-
var options = options ?? defaultTransaction
122+
public func setTTL(node: String, ttl: BigUInt, transaction: CodableTransaction?, password: String) async throws -> TransactionSendingResult {
123+
var transaction = transaction ?? defaultTransaction
124124
if let contractAddress = self.registryContractAddress {
125-
options.to = contractAddress
125+
transaction.to = contractAddress
126126
}
127127
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
128128

Sources/web3swift/Utils/ENS/ENSResolver.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public extension ENS {
105105

106106
// FIXME: Rewrite this to CodableTransaction
107107
@available(*, message: "Available for only owner")
108-
public func setAddress(forNode node: String, address: EthereumAddress, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
109-
var options = options ?? defaultTransaction
110-
options.to = self.resolverContractAddress
108+
public func setAddress(forNode node: String, address: EthereumAddress, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
109+
var transaction = transaction ?? defaultTransaction
110+
transaction.to = self.resolverContractAddress
111111
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
112112
guard let transaction = self.resolverContract.createWriteOperation("setAddr", parameters: [nameHash, address]) else { throw Web3Error.transactionSerializationError }
113113
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
@@ -124,9 +124,9 @@ public extension ENS {
124124

125125
// FIXME: Rewrite this to CodableTransaction
126126
@available(*, message: "Available for only owner")
127-
func setCanonicalName(forNode node: String, name: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
128-
var options = options ?? defaultTransaction
129-
options.to = self.resolverContractAddress
127+
func setCanonicalName(forNode node: String, name: String, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
128+
var transaction = transaction ?? defaultTransaction
129+
transaction.to = self.resolverContractAddress
130130
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
131131
guard let transaction = self.resolverContract.createWriteOperation("setName", parameters: [nameHash, name]) else { throw Web3Error.transactionSerializationError }
132132
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
@@ -143,9 +143,9 @@ public extension ENS {
143143

144144
// FIXME: Rewrite this to CodableTransaction
145145
@available(*, message: "Available for only owner")
146-
func setContentHash(forNode node: String, hash: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
147-
var options = options ?? defaultTransaction
148-
options.to = self.resolverContractAddress
146+
func setContentHash(forNode node: String, hash: String, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
147+
var transaction = transaction ?? defaultTransaction
148+
transaction.to = self.resolverContractAddress
149149
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
150150
guard let transaction = self.resolverContract.createWriteOperation("setContenthash", parameters: [nameHash, hash]) else { throw Web3Error.transactionSerializationError }
151151
guard let result = try? await transaction.writeToChain(password: password)
@@ -164,9 +164,9 @@ public extension ENS {
164164

165165
// FIXME: Rewrite this to CodableTransaction
166166
@available(*, message: "Available for only owner")
167-
func setContractABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
168-
var options = options ?? defaultTransaction
169-
options.to = self.resolverContractAddress
167+
func setContractABI(forNode node: String, contentType: ENS.Resolver.ContentType, data: Data, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
168+
var transaction = transaction ?? defaultTransaction
169+
transaction.to = self.resolverContractAddress
170170
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
171171
guard let transaction = self.resolverContract.createWriteOperation("setABI", parameters: [nameHash, contentType.rawValue, data]) else { throw Web3Error.transactionSerializationError }
172172
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}
@@ -185,9 +185,9 @@ public extension ENS {
185185

186186
// FIXME: Rewrite this to CodableTransaction
187187
@available(*, message: "Available for only owner")
188-
public func setPublicKey(forNode node: String, publicKey: PublicKey, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
189-
var options = options ?? defaultTransaction
190-
options.to = self.resolverContractAddress
188+
public func setPublicKey(forNode node: String, publicKey: PublicKey, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
189+
var transaction = transaction ?? defaultTransaction
190+
transaction.to = self.resolverContractAddress
191191
let pubkeyWithoutPrefix = publicKey.getComponentsWithoutPrefix()
192192
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
193193
guard let transaction = self.resolverContract.createWriteOperation("setPubkey", parameters: [nameHash, pubkeyWithoutPrefix.x, pubkeyWithoutPrefix.y]) else { throw Web3Error.transactionSerializationError }
@@ -205,9 +205,9 @@ public extension ENS {
205205

206206
// FIXME: Rewrite this to CodableTransaction
207207
@available(*, message: "Available for only owner")
208-
public func setTextData(forNode node: String, key: String, value: String, options: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
209-
var options = options ?? defaultTransaction
210-
options.to = self.resolverContractAddress
208+
public func setTextData(forNode node: String, key: String, value: String, transaction: CodableTransaction? = nil, password: String) async throws -> TransactionSendingResult {
209+
var transaction = transaction ?? defaultTransaction
210+
transaction.to = self.resolverContractAddress
211211
guard let nameHash = NameHash.nameHash(node) else {throw Web3Error.processingError(desc: "Failed to get name hash")}
212212
guard let transaction = self.resolverContract.createWriteOperation("setText", parameters: [nameHash, key, value]) else { throw Web3Error.transactionSerializationError }
213213
guard let result = try? await transaction.writeToChain(password: password) else {throw Web3Error.processingError(desc: "Can't send transaction")}

0 commit comments

Comments
 (0)