Skip to content

Commit efd6672

Browse files
committed
replaced [AnyObject] with [Any?] to handle any data type: classes or structs
1 parent 68d6bb0 commit efd6672

File tree

6 files changed

+12
-65
lines changed

6 files changed

+12
-65
lines changed

Sources/Web3Core/RLP/RLP.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ public struct RLP {
113113
}
114114

115115
// FIXME: Make encode generic to avoid casting it's argument to [AnyObject]
116-
internal static func encode(_ elements: [AnyObject]) -> Data? {
116+
internal static func encode(_ elements: [Any?]) -> Data? {
117117
var encodedData = Data()
118118
for e in elements {
119-
if let encoded = encode(e) {
119+
if let encoded = encode(e as AnyObject) {
120120
encodedData.append(encoded)
121121
} else {
122122
guard let asArray = e as? [AnyObject] else {return nil}

Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,14 @@ extension EIP1559Envelope {
245245
// }
246246

247247
public func encode(for type: EncodeType = .transaction) -> Data? {
248-
let fields: [AnyObject]
248+
let fields: [Any?]
249249
let list = accessList.map { $0.encodeAsList() as AnyObject }
250250

251251
switch type {
252252
case .transaction:
253-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s].toAnyObject()
253+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s]
254254
case .signature:
255-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list].toAnyObject()
255+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list]
256256
}
257257
guard var result = RLP.encode(fields) else { return nil }
258258
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Web3Core/Transaction/Envelope/EIP2930Envelope.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ extension EIP2930Envelope {
206206
}
207207

208208
public func encode(for type: EncodeType = .transaction) -> Data? {
209-
let fields: [AnyObject]
209+
let fields: [Any?]
210210
let list = accessList.map { $0.encodeAsList() as AnyObject }
211211

212212
switch type {
213213
case .transaction:
214-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s].toAnyObject()
214+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s]
215215
case .signature:
216-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list].toAnyObject()
216+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list]
217217
}
218218
guard var result = RLP.encode(fields) else { return nil }
219219
result.insert(UInt8(self.type.rawValue), at: 0)

Sources/Web3Core/Transaction/Envelope/LegacyEnvelope.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ extension LegacyEnvelope {
192192
// }
193193

194194
public func encode(for type: EncodeType = .transaction) -> Data? {
195-
let fields: [AnyObject]
195+
let fields: [Any?]
196196
switch type {
197197
case .transaction:
198-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s].toAnyObject()
198+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s]
199199
case .signature:
200200
if let chainID = chainID, chainID != 0 {
201-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)].toAnyObject()
201+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)]
202202
} else {
203-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data].toAnyObject()
203+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data]
204204
}
205205
}
206206
return RLP.encode(fields)

Sources/Web3Core/Utility/Array+Extension.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,3 @@ extension Array where Element: BinaryInteger {
106106
return sorted_data[index]
107107
}
108108
}
109-
110-
// MARK: - Conversion
111-
112-
/// Transforms `[Any?]` into `[AnyObject]`
113-
extension Array where Element == Any? {
114-
func toAnyObject() -> [AnyObject] {
115-
self.map { $0 as AnyObject }
116-
}
117-
}

Tests/web3swiftTests/localTests/ArrayExtensionTests.swift

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)