Skip to content

Commit 68b0dd5

Browse files
committed
removed warnings
1 parent ee26d1e commit 68b0dd5

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

Sources/Web3Core/Transaction/Envelope/EIP1559Envelope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ extension EIP1559Envelope {
250250

251251
switch type {
252252
case .transaction:
253-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
253+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list, v, r, s].toAnyObject()
254254
case .signature:
255-
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list] as [AnyObject]
255+
fields = [chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to.addressData, value, data, list].toAnyObject()
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ extension EIP2930Envelope {
211211

212212
switch type {
213213
case .transaction:
214-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s] as [AnyObject]
214+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list, v, r, s].toAnyObject()
215215
case .signature:
216-
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list] as [AnyObject]
216+
fields = [chainID, nonce, gasPrice, gasLimit, to.addressData, value, data, list].toAnyObject()
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
@@ -195,12 +195,12 @@ extension LegacyEnvelope {
195195
let fields: [AnyObject]
196196
switch type {
197197
case .transaction:
198-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s] as [AnyObject]
198+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s].toAnyObject()
199199
case .signature:
200-
if let chainID = chainID, chainID != 0 {
201-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)] as [AnyObject]
200+
if let chainID = self.chainID, chainID != 0 {
201+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data, chainID, BigUInt(0), BigUInt(0)].toAnyObject()
202202
} else {
203-
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data] as [AnyObject]
203+
fields = [nonce, gasPrice, gasLimit, to.addressData, value, data].toAnyObject()
204204
}
205205
}
206206
return RLP.encode(fields)

Sources/Web3Core/Utility/Array+Extension.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,12 @@ extension Array where Element: BinaryInteger {
106106
return sorted_data[index]
107107
}
108108
}
109+
110+
//MARK: - Conversion
111+
112+
/// Transforms an Array of Any? into an Array of AnyObject
113+
extension Array where Element == Any? {
114+
func toAnyObject() -> [AnyObject] {
115+
self.map{ $0 as AnyObject }
116+
}
117+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// ArrayExtensionTests.swift
3+
// Created by albertopeam on 25/11/22.
4+
//
5+
6+
@testable import Core
7+
import XCTest
8+
9+
final class ArrayExtensionTests: XCTestCase {
10+
func testToAnyObjectEmpty() {
11+
let result = [].toAnyObject()
12+
XCTAssertEqual(result.count, 0)
13+
}
14+
15+
func testToAnyObjectNils() throws {
16+
let result = [nil, nil].toAnyObject()
17+
XCTAssertEqual(result.count, 2)
18+
XCTAssertTrue(result.first is NSNull)
19+
XCTAssertTrue(result.dropFirst().first is NSNull)
20+
}
21+
22+
func testToAnyObjectNilAndNonNils() throws {
23+
let result = [1, nil, "", NSNull()].toAnyObject()
24+
XCTAssertEqual(result.count, 4)
25+
XCTAssertEqual(result.first as? Int, 1)
26+
XCTAssertTrue(result.dropFirst().first is NSNull)
27+
XCTAssertNil(result.dropFirst().first as? String, "2")
28+
XCTAssertTrue(result.dropFirst().first is NSNull)
29+
}
30+
}

0 commit comments

Comments
 (0)