Skip to content

Commit 5b2884e

Browse files
Merge branch 'chore/swiftlint-auto-fixes' into chore/swift-lint-cleanup
2 parents 52919e7 + d1d2d9a commit 5b2884e

File tree

9 files changed

+62
-41
lines changed

9 files changed

+62
-41
lines changed

Example/myWeb3Wallet/myWeb3Wallet/Appdelegate/AppDelegate.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import UIKit
1010
@main
1111
class AppDelegate: UIResponder, UIApplicationDelegate {
1212

13-
14-
1513
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1614
// Override point for customization after application launch.
1715
return true
@@ -31,6 +29,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3129
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
3230
}
3331

34-
3532
}
36-

Example/myWeb3Wallet/myWeb3Wallet/Appdelegate/SceneDelegate.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1111

1212
var window: UIWindow?
1313

14-
1514
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
1615
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
1716
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
@@ -47,6 +46,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
4746
// to restore the scene back to its current state.
4847
}
4948

50-
5149
}
52-

Example/myWeb3Wallet/myWeb3Wallet/ViewController.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ class ViewController: UIViewController {
1414
// Do any additional setup after loading the view.
1515
}
1616

17-
1817
}
19-

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/DashboardViewController.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class DashboardViewController: UIViewController {
1919

2020
}
2121
}
22-
2322

2423
/*
2524
// MARK: - Navigation

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/SplashViewController.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,19 @@ import UIKit
1010
class SplashViewController: UIViewController {
1111

1212
@IBOutlet weak var logoView: UIImageView!
13-
13+
1414
override func viewDidLoad() {
1515
super.viewDidLoad()
1616
UIView.animate(withDuration: 0.9) {
1717
self.logoView.center.y = self.view.center.y
1818
Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.moveToWalletView), userInfo: nil, repeats: false)
1919

2020
}
21-
2221

2322
// Do any additional setup after loading the view.
2423
}
25-
@objc func moveToWalletView(){
26-
24+
@objc func moveToWalletView() {
25+
2726
guard let walletScreen = self.storyboard?.instantiateViewController(withIdentifier: "WalletViewController") as? WalletViewController else {
2827
#if DEBUG
2928
printContent("Unable to get Wallet controller")

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/WalletController/WalletViewController.swift

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import UIKit
99
import web3swift
1010
class WalletViewController: UIViewController {
11-
11+
1212
@IBOutlet weak var continueButton: UIButton!
1313
@IBOutlet weak var walletAddressLabel: UILabel!
1414
@IBOutlet weak var importWalletButton: UIButton!
1515
@IBOutlet weak var createWalletButton: UIButton!
1616
var _walletAddress: String {
17-
set{
17+
set {
1818
self.continueButton.isHidden = false
1919
self.walletAddressLabel.text = newValue
2020
}
@@ -27,23 +27,22 @@ class WalletViewController: UIViewController {
2727
super.viewDidLoad()
2828
self.createWalletButton.layer.cornerRadius = 5.0
2929
self.importWalletButton.layer.cornerRadius = 5.0
30-
30+
3131
// Do any additional setup after loading the view.
3232
}
33-
34-
33+
3534
@IBAction func onClickCreateWallet(_ sender: UIButton) {
3635
#if DEBUG
3736
print("Clicked on Create Wallet Option")
3837
#endif
3938
self.createMnemonics()
40-
39+
4140
}
4241
@IBAction func onClickImportWalletButton(_ sender: UIButton) {
4342
print("Clicked on import Wallet Option")
4443
self.showImportALert()
4544
}
46-
45+
4746
@IBAction func onClickContinueButton(_ sender: UIButton) {
4847
print("Clicked on COntinue button")
4948
guard let dashboardScreen = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as? DashboardViewController else {
@@ -54,7 +53,7 @@ class WalletViewController: UIViewController {
5453
}
5554
self.navigationController?.pushViewController(dashboardScreen, animated: true)
5655
}
57-
fileprivate func showImportALert(){
56+
fileprivate func showImportALert() {
5857
let alert = UIAlertController(title: "MyWeb3Wallet", message: "", preferredStyle: .alert)
5958
alert.addTextField { textfied in
6059
textfied.placeholder = "Enter mnemonics/private Key"
@@ -69,15 +68,15 @@ class WalletViewController: UIViewController {
6968
guard let privateKey = alert.textFields?[0].text else { return }
7069
print(privateKey)
7170
self.importWalletWith(privateKey: privateKey)
72-
71+
7372
}
7473
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
7574
alert.addAction(mnemonicsAction)
7675
alert.addAction(privateKeyAction)
7776
alert.addAction(cancelAction)
7877
self.present(alert, animated: true, completion: nil)
7978
}
80-
func importWalletWith(privateKey: String){
79+
func importWalletWith(privateKey: String) {
8180
let formattedKey = privateKey.trimmingCharacters(in: .whitespacesAndNewlines)
8281
guard let dataKey = Data.fromHex(formattedKey) else {
8382
self.showAlertMessage(title: "Error", message: "Please enter a valid Private key ", actionName: "Ok")
@@ -94,7 +93,7 @@ class WalletViewController: UIViewController {
9493
#endif
9594
let walletAddress = manager.addresses?.first?.address
9695
self.walletAddressLabel.text = walletAddress ?? "0x"
97-
96+
9897
print(walletAddress)
9998
} else {
10099
print("error")
@@ -109,34 +108,31 @@ class WalletViewController: UIViewController {
109108
alert.addAction(okAction)
110109
self.present(alert, animated: true)
111110
}
112-
113-
114-
111+
115112
}
116113
func importWalletWith(mnemonics: String) {
117-
let walletAddress = try? BIP32Keystore(mnemonics: mnemonics , prefixPath: "m/44'/77777'/0'/0")
114+
let walletAddress = try? BIP32Keystore(mnemonics: mnemonics, prefixPath: "m/44'/77777'/0'/0")
118115
print(walletAddress?.addresses)
119116
self.walletAddressLabel.text = "\(walletAddress?.addresses?.first?.address ?? "0x")"
120-
117+
121118
}
122-
123-
119+
124120
}
125121
extension WalletViewController {
126-
127-
fileprivate func createMnemonics(){
122+
123+
fileprivate func createMnemonics() {
128124
let userDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
129125
let web3KeystoreManager = KeystoreManager.managerForPath(userDir + "/keystore")
130126
do {
131-
if (web3KeystoreManager?.addresses?.count ?? 0 >= 0) {
127+
if web3KeystoreManager?.addresses?.count ?? 0 >= 0 {
132128
let tempMnemonics = try? BIP39.generateMnemonics(bitsOfEntropy: 256, language: .english)
133129
guard let tMnemonics = tempMnemonics else {
134130
self.showAlertMessage(title: "", message: "We are unable to create wallet", actionName: "Ok")
135131
return
136132
}
137133
self._mnemonics = tMnemonics
138134
print(_mnemonics)
139-
let tempWalletAddress = try? BIP32Keystore(mnemonics: self._mnemonics , prefixPath: "m/44'/77777'/0'/0")
135+
let tempWalletAddress = try? BIP32Keystore(mnemonics: self._mnemonics, prefixPath: "m/44'/77777'/0'/0")
140136
print(tempWalletAddress?.addresses?.first?.address)
141137
guard let walletAddress = tempWalletAddress?.addresses?.first else {
142138
self.showAlertMessage(title: "", message: "We are unable to create wallet", actionName: "Ok")
@@ -151,9 +147,9 @@ extension WalletViewController {
151147
FileManager.default.createFile(atPath: userDir + "/keystore"+"/key.json", contents: keyData, attributes: nil)
152148
}
153149
} catch {
154-
150+
155151
}
156-
152+
157153
}
158154
}
159155
extension UIViewController {
@@ -163,5 +159,5 @@ extension UIViewController {
163159
alertController.addAction(action)
164160
self.present(alertController, animated: true)
165161
}
166-
162+
167163
}

Sources/Web3Core/EthereumABI/ABIEncoding.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public struct ABIEncoder {
9898

9999
/// Attempts to convert given object into `Data`.
100100
/// Used as a part of ABI encoding process.
101-
/// Supported types are `Data`, `String`, `[UInt8]`, ``EthereumAddress`` and `[IntegerLiteralType]`.
101+
/// Supported types are `Data`, `String`, `[UInt8]`, ``EthereumAddress``, `[IntegerLiteralType]` and `Bool`.
102102
/// Note: if `String` has `0x` prefix an attempt to interpret it as a hexadecimal number will take place. Otherwise, UTF-8 bytes are returned.
103103
/// - Parameter value: any object.
104104
/// - Returns: `Data` representation of an object ready for ABI encoding.
@@ -123,6 +123,8 @@ public struct ABIEncoder {
123123
bytesArray.append(UInt8(el))
124124
}
125125
return Data(bytesArray)
126+
case let b as Bool:
127+
return b ? Data([UInt8(1)]) : Data(count: 1)
126128
default:
127129
return nil
128130
}

Tests/web3swiftTests/localTests/EIP1559BlockTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import BigInt
44
@testable
55
import web3swift
66

7-
@testable
87
import Web3Core
98

109
class EIP1559BlockTests: LocalTestCase {

Tests/web3swiftTests/localTests/UtilitiesTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,39 @@ class UtilitiesTests: XCTestCase {
4747
XCTAssertEqual(test.input.decimals, test.output)
4848
}
4949
}
50+
51+
func testPublicKeyWithNoPrefixToAddress() throws {
52+
var address = Utilities.publicToAddress(Data.fromHex("0x18ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address
53+
XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00")
54+
address = Utilities.publicToAddress(Data.fromHex("0x52972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address
55+
XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F")
56+
}
57+
58+
func testPublicKeyWithPrefixToAddress() throws {
59+
var address = Utilities.publicToAddress(Data.fromHex("0x0418ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address
60+
XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00")
61+
address = Utilities.publicToAddress(Data.fromHex("0x0452972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address
62+
XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F")
63+
}
64+
65+
func testPublicKeyWithInvalidPrefixToAddress() throws {
66+
var address = Utilities.publicToAddress(Data.fromHex("0x0318ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f504c220d01e1ca419cb1ba4b3393b615e99dd20aa6bf071078f70fd949008e7411")!)?.address
67+
XCTAssertEqual(address, nil)
68+
address = Utilities.publicToAddress(Data.fromHex("0x0152972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab288742f4dc97d9edb6fd946babc002fdfb06f26caf117b9405ed79275763fdb1c")!)?.address
69+
XCTAssertEqual(address, nil)
70+
}
71+
72+
func testCompressedPublicKeyToAddress() throws {
73+
var address = Utilities.publicToAddress(Data.fromHex("0x0318ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f50")!)?.address
74+
XCTAssertEqual(address, "0x28828f43df370651AC5A6cFd02fBD0885Fbb3c00")
75+
address = Utilities.publicToAddress(Data.fromHex("0x0252972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2")!)?.address
76+
XCTAssertEqual(address, "0x6eDBe1F6D48FbF1b053D6c9FA7997C710B84f55F")
77+
}
78+
79+
func testCompressedPublicKeyWithInvalidPrefixToAddress() throws {
80+
var address = Utilities.publicToAddress(Data.fromHex("0x0718ed2e1ec629e2d3dae7be1103d4f911c24e0c80e70038f5eb5548245c475f50")!)?.address
81+
XCTAssertEqual(address, nil)
82+
address = Utilities.publicToAddress(Data.fromHex("0x0852972572d465d016d4c501887b8df303eee3ed602c056b1eb09260dfa0da0ab2")!)?.address
83+
XCTAssertEqual(address, nil)
84+
}
5085
}

0 commit comments

Comments
 (0)