Skip to content

Commit ffbf4e7

Browse files
chore: replaced data.indices.startIndex with data.startIndex
1 parent 8cd4c44 commit ffbf4e7

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

Sources/Web3Core/Contract/ContractProtocol.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ extension ContractProtocol {
210210

211211
func decodeInputData(_ data: Data) -> [String: Any]? {
212212
guard data.count >= 4 else { return nil }
213-
let methodId = data[data.indices.startIndex ..< data.indices.startIndex + 4].toHexString()
214-
let data = data[(data.indices.startIndex + 4)...]
213+
let methodId = data[data.startIndex ..< data.startIndex + 4].toHexString()
214+
let data = data[(data.startIndex + 4)...]
215215
return decodeInputData(methodId, data: data)
216216
}
217217
}
@@ -326,21 +326,21 @@ extension DefaultContractProtocol {
326326
if method == "fallback" {
327327
return nil
328328
}
329-
return methods[method]?.compactMap({ function in
329+
return methods[method]?.compactMap({ functio n in
330330
return function.decodeInputData(data)
331331
}).first
332332
}
333333

334334
public func decodeInputData(_ data: Data) -> [String: Any]? {
335335
guard data.count % 32 == 4 else { return nil }
336-
let methodSignature = data[data.indices.startIndex ..< data.indices.startIndex + 4].toHexString().addHexPrefix().lowercased()
336+
let methodSignature = data[data.startIndex ..< data.startIndex + 4].toHexString().addHexPrefix().lowercased()
337337

338338
guard let function = methods[methodSignature]?.first else { return nil }
339-
return function.decodeInputData(Data(data[data.indices.startIndex + 4 ..< data.indices.startIndex + data.count]))
339+
return function.decodeInputData(Data(data[data.startIndex + 4 ..< data.startIndex + data.count]))
340340
}
341341

342342
public func getFunctionCalled(_ data: Data) -> ABI.Element.Function? {
343343
guard data.count >= 4 else { return nil }
344-
return methods[data[data.indices.startIndex ..< data.indices.startIndex + 4].toHexString().addHexPrefix()]?.first
344+
return methods[data[data.startIndex ..< data.startIndex + 4].toHexString().addHexPrefix()]?.first
345345
}
346346
}

Sources/Web3Core/EthereumABI/ABIDecoding.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ extension ABIDecoder {
189189
fileprivate static func followTheData(type: ABI.Element.ParameterType, data: Data, pointer: UInt64 = 0) -> (elementEncoding: Data?, nextElementPointer: UInt64?) {
190190
if type.isStatic {
191191
guard data.count >= pointer + type.memoryUsage else {return (nil, nil)}
192-
let elementItself = data[data.indices.startIndex + Int(pointer) ..< data.indices.startIndex + Int(pointer + type.memoryUsage)]
192+
let elementItself = data[data.startIndex + Int(pointer) ..< data.startIndex + Int(pointer + type.memoryUsage)]
193193
let nextElement = pointer + type.memoryUsage
194194
return (Data(elementItself), nextElement)
195195
} else {
196196
guard data.count >= pointer + type.memoryUsage else {return (nil, nil)}
197-
let dataSlice = data[data.indices.startIndex + Int(pointer) ..< data.indices.startIndex + Int(pointer + type.memoryUsage)]
197+
let dataSlice = data[data.startIndex + Int(pointer) ..< data.startIndex + Int(pointer + type.memoryUsage)]
198198
let bn = BigUInt(dataSlice)
199199
if bn > UInt64.max || bn >= data.count {
200200
// there are ERC20 contracts that use bytes32 instead of string. Let's be optimistic and return some data

Sources/Web3Core/EthereumABI/ABIElements.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,9 @@ extension ABI.Element.Function {
397397
/// 4) `messageLength` is used to determine where message bytes end to decode string correctly.
398398
/// 5) The rest of the `data` must be 0 bytes or empty.
399399
if data.bytes.count >= 100,
400-
Data(data[data.indices.startIndex ..< data.indices.startIndex + 4]) == Data.fromHex("08C379A0"),
401-
BigInt(data[data.indices.startIndex + 4 ..< data.indices.startIndex + 36]) == 32,
402-
let messageLength = Int(Data(data[data.indices.startIndex + 36 ..< data.indices.startIndex + 68]).toHexString(), radix: 16),
400+
Data(data[data.startIndex ..< data.startIndex + 4]) == Data.fromHex("08C379A0"),
401+
BigInt(data[data.startIndex + 4 ..< data.startIndex + 36]) == 32,
402+
let messageLength = Int(Data(data[data.startIndex + 36 ..< data.startIndex + 68]).toHexString(), radix: 16),
403403
let message = String(bytes: data.bytes[68..<(68+messageLength)], encoding: .utf8),
404404
(68+messageLength == data.count || data.bytes[68+messageLength..<data.count].reduce(0) { $0 + $1 } == 0) {
405405
return ["_success": false,
@@ -410,11 +410,11 @@ extension ABI.Element.Function {
410410

411411
if data.count >= 4,
412412
let errors = errors,
413-
let customError = errors[data[data.indices.startIndex ..< data.indices.startIndex + 4].toHexString().stripHexPrefix()] {
413+
let customError = errors[data[data.startIndex ..< data.startIndex + 4].toHexString().stripHexPrefix()] {
414414
var errorResponse: [String: Any] = ["_success": false, "_abortedByRevertOrRequire": true, "_error": customError.errorDeclaration]
415415

416416
if (data.count > 32 && !customError.inputs.isEmpty),
417-
let decodedInputs = ABIDecoder.decode(types: customError.inputs, data: Data(data[data.indices.startIndex + 4 ..< data.indices.startIndex + data.count])) {
417+
let decodedInputs = ABIDecoder.decode(types: customError.inputs, data: Data(data[data.startIndex + 4 ..< data.startIndex + data.count])) {
418418
for idx in decodedInputs.indices {
419419
errorResponse["\(idx)"] = decodedInputs[idx]
420420
if !customError.inputs[idx].name.isEmpty {

0 commit comments

Comments
 (0)