Skip to content

Commit 1018a9f

Browse files
fix: added space around return statements in '{return nil}'
1 parent 1b991c6 commit 1018a9f

21 files changed

+152
-152
lines changed

Sources/Web3Core/EthereumABI/ABIDecoding.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ extension ABIDecoder {
2121
var consumed: UInt64 = 0
2222
for i in 0 ..< types.count {
2323
let (v, c) = decodeSingleType(type: types[i], data: data, pointer: consumed)
24-
guard let valueUnwrapped = v, let consumedUnwrapped = c else {return nil}
24+
guard let valueUnwrapped = v, let consumedUnwrapped = c else { return nil }
2525
toReturn.append(valueUnwrapped)
2626
consumed = consumed + consumedUnwrapped
2727
}
28-
guard toReturn.count == types.count else {return nil}
28+
guard toReturn.count == types.count else { return nil }
2929
return toReturn
3030
}
3131

@@ -235,23 +235,23 @@ extension ABIDecoder {
235235
let nonIndexedTypes = nonIndexedInputs.compactMap { inp -> ABI.Element.ParameterType in
236236
return inp.type
237237
}
238-
guard logs.count == indexedInputs.count + 1 else {return nil}
238+
guard logs.count == indexedInputs.count + 1 else { return nil }
239239
var indexedValues = [Any]()
240240
for i in 0 ..< indexedInputs.count {
241241
let data = logs[i+1]
242242
let input = indexedInputs[i]
243243
if !input.type.isStatic || input.type.isArray || input.type.memoryUsage != 32 {
244244
let (v, _) = ABIDecoder.decodeSingleType(type: .bytes(length: 32), data: data)
245-
guard let valueUnwrapped = v else {return nil}
245+
guard let valueUnwrapped = v else { return nil }
246246
indexedValues.append(valueUnwrapped)
247247
} else {
248248
let (v, _) = ABIDecoder.decodeSingleType(type: input.type, data: data)
249-
guard let valueUnwrapped = v else {return nil}
249+
guard let valueUnwrapped = v else { return nil }
250250
indexedValues.append(valueUnwrapped)
251251
}
252252
}
253253
let v = ABIDecoder.decode(types: nonIndexedTypes, data: dataForProcessing)
254-
guard let nonIndexedValues = v else {return nil}
254+
guard let nonIndexedValues = v else { return nil }
255255
var indexedInputCounter = 0
256256
var nonIndexedInputCounter = 0
257257
for i in 0 ..< event.inputs.count {

Sources/Web3Core/EthereumABI/ABIElements.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ extension ABI.Element.Function {
215215

216216
extension ABI.Element.Event {
217217
public func decodeReturnedLogs(eventLogTopics: [Data], eventLogData: Data) -> [String: Any]? {
218-
guard let eventContent = ABIDecoder.decodeLog(event: self, eventLogTopics: eventLogTopics, eventLogData: eventLogData) else {return nil}
218+
guard let eventContent = ABIDecoder.decodeLog(event: self, eventLogTopics: eventLogTopics, eventLogData: eventLogData) else { return nil }
219219
return eventContent
220220
}
221221
}
@@ -478,7 +478,7 @@ private func decodeInputData(_ rawData: Data,
478478
guard inputs.count * 32 <= data.count else { return nil }
479479

480480
var i = 0
481-
guard let values = ABIDecoder.decode(types: inputs, data: data) else {return nil}
481+
guard let values = ABIDecoder.decode(types: inputs, data: data) else { return nil }
482482
for input in inputs {
483483
let name = "\(i)"
484484
returnArray[name] = values[i]

Sources/Web3Core/EthereumABI/ABIEncoding.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public struct ABIEncoder {
119119
case let d as [IntegerLiteralType]:
120120
var bytesArray = [UInt8]()
121121
for el in d {
122-
guard el >= 0, el <= 255 else {return nil}
122+
guard el >= 0, el <= 255 else { return nil }
123123
bytesArray.append(UInt8(el))
124124
}
125125
return Data(bytesArray)
@@ -138,7 +138,7 @@ public struct ABIEncoder {
138138
/// - `types.count != values.count`;
139139
/// - encoding of at least one value has failed (e.g. type mismatch).
140140
public static func encode(types: [ABI.Element.InOut], values: [Any]) -> Data? {
141-
guard types.count == values.count else {return nil}
141+
guard types.count == values.count else { return nil }
142142
let params = types.compactMap { el -> ABI.Element.ParameterType in
143143
return el.type
144144
}
@@ -154,12 +154,12 @@ public struct ABIEncoder {
154154
/// - `types.count != values.count`;
155155
/// - encoding of at least one value has failed (e.g. type mismatch).
156156
public static func encode(types: [ABI.Element.ParameterType], values: [Any]) -> Data? {
157-
guard types.count == values.count else {return nil}
157+
guard types.count == values.count else { return nil }
158158
var tails = [Data]()
159159
var heads = [Data]()
160160
for i in 0 ..< types.count {
161161
let enc = encodeSingleType(type: types[i], value: values[i])
162-
guard let encoding = enc else {return nil}
162+
guard let encoding = enc else { return nil }
163163
if types[i].isStatic {
164164
heads.append(encoding)
165165
tails.append(Data())
@@ -179,7 +179,7 @@ public struct ABIEncoder {
179179
let head = heads[i]
180180
let tail = tails[i]
181181
if !types[i].isStatic {
182-
guard let newHead = tailsPointer.abiEncode(bits: 256) else {return nil}
182+
guard let newHead = tailsPointer.abiEncode(bits: 256) else { return nil }
183183
headsConcatenated.append(newHead)
184184
tailsConcatenated.append(tail)
185185
tailsPointer = tailsPointer + BigUInt(tail.count)
@@ -225,7 +225,7 @@ public struct ABIEncoder {
225225
return bigint == nil ? nil : bigint!.abiEncode(bits: 256)
226226
case .address:
227227
if let string = value as? String {
228-
guard let address = EthereumAddress(string) else {return nil}
228+
guard let address = EthereumAddress(string) else { return nil }
229229
let data = address.addressData
230230
return data.setLengthLeft(32)
231231
} else if let address = value as? EthereumAddress {
@@ -293,7 +293,7 @@ public struct ABIEncoder {
293293
var heads = [Data]()
294294
for i in 0 ..< val.count {
295295
let enc = encodeSingleType(type: subType, value: val[i])
296-
guard let encoding = enc else {return nil}
296+
guard let encoding = enc else { return nil }
297297
heads.append(Data(repeating: 0x0, count: 32))
298298
tails.append(encoding)
299299
}
@@ -308,7 +308,7 @@ public struct ABIEncoder {
308308
let head = heads[i]
309309
let tail = tails[i]
310310
if tail != Data() {
311-
guard let newHead = tailsPointer.abiEncode(bits: 256) else {return nil}
311+
guard let newHead = tailsPointer.abiEncode(bits: 256) else { return nil }
312312
headsConcatenated.append(newHead)
313313
tailsConcatenated.append(tail)
314314
tailsPointer = tailsPointer + BigUInt(tail.count)
@@ -340,7 +340,7 @@ public struct ABIEncoder {
340340
var heads = [Data]()
341341
for i in 0 ..< val.count {
342342
let enc = encodeSingleType(type: subType, value: val[i])
343-
guard let encoding = enc else {return nil}
343+
guard let encoding = enc else { return nil }
344344
heads.append(Data(repeating: 0x0, count: 32))
345345
tails.append(encoding)
346346
}
@@ -353,7 +353,7 @@ public struct ABIEncoder {
353353
var tailsConcatenated = Data()
354354
for i in 0 ..< val.count {
355355
let tail = tails[i]
356-
guard let newHead = tailsPointer.abiEncode(bits: 256) else {return nil}
356+
guard let newHead = tailsPointer.abiEncode(bits: 256) else { return nil }
357357
headsConcatenated.append(newHead)
358358
tailsConcatenated.append(tail)
359359
tailsPointer = tailsPointer + BigUInt(tail.count)
@@ -370,7 +370,7 @@ public struct ABIEncoder {
370370
guard let val = value as? [Any] else {break}
371371
for i in 0 ..< subTypes.count {
372372
let enc = encodeSingleType(type: subTypes[i], value: val[i])
373-
guard let encoding = enc else {return nil}
373+
guard let encoding = enc else { return nil }
374374
if subTypes[i].isStatic {
375375
heads.append(encoding)
376376
tails.append(Data())
@@ -390,7 +390,7 @@ public struct ABIEncoder {
390390
let head = heads[i]
391391
let tail = tails[i]
392392
if !subTypes[i].isStatic {
393-
guard let newHead = tailsPointer.abiEncode(bits: 256) else {return nil}
393+
guard let newHead = tailsPointer.abiEncode(bits: 256) else { return nil }
394394
headsConcatenated.append(newHead)
395395
tailsConcatenated.append(tail)
396396
tailsPointer = tailsPointer + BigUInt(tail.count)

Sources/Web3Core/EthereumAddress/EthereumAddress.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public struct EthereumAddress: Equatable {
6363
/// represented as `ASCII` data. Otherwise, checksummed address is returned with `0x` prefix.
6464
public static func toChecksumAddress(_ addr: String) -> String? {
6565
let address = addr.lowercased().stripHexPrefix()
66-
guard let hash = address.data(using: .ascii)?.sha3(.keccak256).toHexString().stripHexPrefix() else {return nil}
66+
guard let hash = address.data(using: .ascii)?.sha3(.keccak256).toHexString().stripHexPrefix() else { return nil }
6767
var ret = "0x"
6868

6969
for (i, char) in address.enumerated() {
7070
let startIdx = hash.index(hash.startIndex, offsetBy: i)
7171
let endIdx = hash.index(hash.startIndex, offsetBy: i+1)
7272
let hashChar = String(hash[startIdx..<endIdx])
7373
let c = String(char)
74-
guard let int = Int(hashChar, radix: 16) else {return nil}
74+
guard let int = Int(hashChar, radix: 16) else { return nil }
7575
if int >= 8 {
7676
ret += c.uppercased()
7777
} else {
@@ -96,8 +96,8 @@ extension EthereumAddress {
9696
public init?(_ addressString: String, type: AddressType = .normal, ignoreChecksum: Bool = false) {
9797
switch type {
9898
case .normal:
99-
guard let data = Data.fromHex(addressString) else {return nil}
100-
guard data.count == 20 else {return nil}
99+
guard let data = Data.fromHex(addressString) else { return nil }
100+
guard data.count == 20 else { return nil }
101101
if !addressString.hasHexPrefix() {
102102
return nil
103103
}
@@ -113,7 +113,7 @@ extension EthereumAddress {
113113
return
114114
} else {
115115
let checksummedAddress = EthereumAddress.toChecksumAddress(data.toHexString().addHexPrefix())
116-
guard checksummedAddress == addressString else {return nil}
116+
guard checksummedAddress == addressString else { return nil }
117117
self._address = data.toHexString().addHexPrefix()
118118
self.type = .normal
119119
return
@@ -131,7 +131,7 @@ extension EthereumAddress {
131131
}
132132

133133
public init?(_ addressData: Data, type: AddressType = .normal) {
134-
guard addressData.count == 20 else {return nil}
134+
guard addressData.count == 20 else { return nil }
135135
self._address = addressData.toHexString().addHexPrefix()
136136
self.type = type
137137
}

Sources/Web3Core/KeystoreManager/BIP32HDNode.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class HDNode {
6969
}
7070

7171
public init?(_ data: Data) {
72-
guard data.count == 82 else {return nil}
72+
guard data.count == 82 else { return nil }
7373
let header = data[0..<4]
7474
var serializePrivate = false
7575
if header == HDNode.HDversion().privatePrefix {
@@ -81,30 +81,30 @@ public class HDNode {
8181
chaincode = data[13..<45]
8282
if serializePrivate {
8383
privateKey = data[46..<78]
84-
guard let pubKey = Utilities.privateToPublic(privateKey!, compressed: true) else {return nil}
85-
if pubKey[0] != 0x02 && pubKey[0] != 0x03 {return nil}
84+
guard let pubKey = Utilities.privateToPublic(privateKey!, compressed: true) else { return nil }
85+
if pubKey[0] != 0x02 && pubKey[0] != 0x03 { return nil }
8686
publicKey = pubKey
8787
} else {
8888
publicKey = data[45..<78]
8989
}
9090
let hashedData = data[0..<78].sha256().sha256()
9191
let checksum = hashedData[0..<4]
92-
if checksum != data[78..<82] {return nil}
92+
if checksum != data[78..<82] { return nil }
9393
}
9494

9595
public init?(seed: Data) {
96-
guard seed.count >= 16 else {return nil}
96+
guard seed.count >= 16 else { return nil }
9797
let hmacKey = "Bitcoin seed".data(using: .ascii)!
9898
let hmac: Authenticator = HMAC(key: hmacKey.bytes, variant: HMAC.Variant.sha2(.sha512))
99-
guard let entropy = try? hmac.authenticate(seed.bytes) else {return nil}
99+
guard let entropy = try? hmac.authenticate(seed.bytes) else { return nil }
100100
guard entropy.count == 64 else { return nil}
101101
let I_L = entropy[0..<32]
102102
let I_R = entropy[32..<64]
103103
chaincode = Data(I_R)
104104
let privKeyCandidate = Data(I_L)
105-
guard SECP256K1.verifyPrivateKey(privateKey: privKeyCandidate) else {return nil}
106-
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: privKeyCandidate, compressed: true) else {return nil}
107-
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else {return nil}
105+
guard SECP256K1.verifyPrivateKey(privateKey: privKeyCandidate) else { return nil }
106+
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: privKeyCandidate, compressed: true) else { return nil }
107+
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else { return nil }
108108
publicKey = pubKeyCandidate
109109
privateKey = privKeyCandidate
110110
depth = 0x00
@@ -165,11 +165,11 @@ extension HDNode {
165165
}
166166
return nil
167167
}
168-
guard let privKeyCandidate = newPK.serialize().setLengthLeft(32) else {return nil}
168+
guard let privKeyCandidate = newPK.serialize().setLengthLeft(32) else { return nil }
169169
guard SECP256K1.verifyPrivateKey(privateKey: privKeyCandidate) else {return nil }
170-
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: privKeyCandidate, compressed: true) else {return nil}
171-
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else {return nil}
172-
guard self.depth < UInt8.max else {return nil}
170+
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: privKeyCandidate, compressed: true) else { return nil }
171+
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else { return nil }
172+
guard self.depth < UInt8.max else { return nil }
173173
let newNode = HDNode()
174174
newNode.chaincode = cc
175175
newNode.depth = self.depth + 1
@@ -215,13 +215,13 @@ extension HDNode {
215215
}
216216
return nil
217217
}
218-
guard let tempKey = bn.serialize().setLengthLeft(32) else {return nil}
218+
guard let tempKey = bn.serialize().setLengthLeft(32) else { return nil }
219219
guard SECP256K1.verifyPrivateKey(privateKey: tempKey) else {return nil }
220-
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: tempKey, compressed: true) else {return nil}
221-
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else {return nil}
222-
guard let newPublicKey = SECP256K1.combineSerializedPublicKeys(keys: [self.publicKey, pubKeyCandidate], outputCompressed: true) else {return nil}
223-
guard newPublicKey.bytes[0] == 0x02 || newPublicKey.bytes[0] == 0x03 else {return nil}
224-
guard self.depth < UInt8.max else {return nil}
220+
guard let pubKeyCandidate = SECP256K1.privateToPublic(privateKey: tempKey, compressed: true) else { return nil }
221+
guard pubKeyCandidate.bytes[0] == 0x02 || pubKeyCandidate.bytes[0] == 0x03 else { return nil }
222+
guard let newPublicKey = SECP256K1.combineSerializedPublicKeys(keys: [self.publicKey, pubKeyCandidate], outputCompressed: true) else { return nil }
223+
guard newPublicKey.bytes[0] == 0x02 || newPublicKey.bytes[0] == 0x03 else { return nil }
224+
guard self.depth < UInt8.max else { return nil }
225225
let newNode = HDNode()
226226
newNode.chaincode = cc
227227
newNode.depth = self.depth + 1
@@ -255,22 +255,22 @@ extension HDNode {
255255
if component.hasSuffix("'") {
256256
hardened = true
257257
}
258-
guard let index = UInt32(component.trimmingCharacters(in: CharacterSet(charactersIn: "'"))) else {return nil}
259-
guard let newNode = currentNode.derive(index: index, derivePrivateKey: derivePrivateKey, hardened: hardened) else {return nil}
258+
guard let index = UInt32(component.trimmingCharacters(in: CharacterSet(charactersIn: "'"))) else { return nil }
259+
guard let newNode = currentNode.derive(index: index, derivePrivateKey: derivePrivateKey, hardened: hardened) else { return nil }
260260
currentNode = newNode
261261
}
262262
return currentNode
263263
}
264264

265265
public func serializeToString(serializePublic: Bool = true, version: HDversion = HDversion()) -> String? {
266-
guard let data = self.serialize(serializePublic: serializePublic, version: version) else {return nil}
266+
guard let data = self.serialize(serializePublic: serializePublic, version: version) else { return nil }
267267
let encoded = Base58.base58FromBytes(data.bytes)
268268
return encoded
269269
}
270270

271271
public func serialize(serializePublic: Bool = true, version: HDversion = HDversion()) -> Data? {
272272
var data = Data()
273-
if !serializePublic && !self.hasPrivate {return nil}
273+
if !serializePublic && !self.hasPrivate { return nil }
274274
if serializePublic {
275275
data.append(version.publicPrefix)
276276
} else {

Sources/Web3Core/KeystoreManager/BIP32Keystore.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public class BIP32Keystore: AbstractKeystore {
7474
}
7575

7676
public init?(_ jsonData: Data) {
77-
guard var keystorePars = try? JSONDecoder().decode(KeystoreParamsBIP32.self, from: jsonData) else {return nil}
78-
if keystorePars.version != Self.KeystoreParamsBIP32Version {return nil}
79-
if keystorePars.crypto.version != nil && keystorePars.crypto.version != "1" {return nil}
80-
if !keystorePars.isHDWallet {return nil}
77+
guard var keystorePars = try? JSONDecoder().decode(KeystoreParamsBIP32.self, from: jsonData) else { return nil }
78+
if keystorePars.version != Self.KeystoreParamsBIP32Version { return nil }
79+
if keystorePars.crypto.version != nil && keystorePars.crypto.version != "1" { return nil }
80+
if !keystorePars.isHDWallet { return nil }
8181

8282
addressStorage = PathAddressStorage(pathAddressPairs: keystorePars.pathAddressPairs)
8383

@@ -100,7 +100,7 @@ public class BIP32Keystore: AbstractKeystore {
100100

101101
public init? (seed: Data, password: String, prefixPath: String = HDNode.defaultPathMetamaskPrefix, aesMode: String = "aes-128-cbc") throws {
102102
addressStorage = PathAddressStorage()
103-
guard let rootNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else {return nil}
103+
guard let rootNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else { return nil }
104104
self.rootPrefix = prefixPath
105105
try createNewAccount(parentNode: rootNode, password: password)
106106
guard let serializedRootNode = rootNode.serialize(serializePublic: false) else {

0 commit comments

Comments
 (0)