Skip to content

Commit 65cfd50

Browse files
Clean Eth scope network calls.
- Delete redundant - Move out unnecessary logic from calls. Delete default passwords
1 parent f1c295b commit 65cfd50

32 files changed

+101
-155
lines changed

Sources/Core/KeystoreManager/BIP32Keystore.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public class BIP32Keystore: AbstractKeystore {
8888
rootPrefix = keystoreParams!.rootPath!
8989
}
9090

91-
public convenience init?(mnemonics: String, password: String = "web3swift", mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathMetamaskPrefix, aesMode: String = "aes-128-cbc") throws {
91+
public convenience init?(mnemonics: String, password: String, mnemonicsPassword: String = "", language: BIP39Language = BIP39Language.english, prefixPath: String = HDNode.defaultPathMetamaskPrefix, aesMode: String = "aes-128-cbc") throws {
9292
guard var seed = BIP39.seedFromMmemonics(mnemonics, password: mnemonicsPassword, language: language) else {
9393
throw AbstractKeystoreError.noEntropyError
9494
}
@@ -98,7 +98,7 @@ public class BIP32Keystore: AbstractKeystore {
9898
try self.init(seed: seed, password: password, prefixPath: prefixPath, aesMode: aesMode)
9999
}
100100

101-
public init? (seed: Data, password: String = "web3swift", prefixPath: String = HDNode.defaultPathMetamaskPrefix, aesMode: String = "aes-128-cbc") throws {
101+
public init? (seed: Data, password: String, prefixPath: String = HDNode.defaultPathMetamaskPrefix, aesMode: String = "aes-128-cbc") throws {
102102
addressStorage = PathAddressStorage()
103103
guard let rootNode = HDNode(seed: seed)?.derive(path: prefixPath, derivePrivateKey: true) else {return nil}
104104
self.rootPrefix = prefixPath
@@ -109,7 +109,7 @@ public class BIP32Keystore: AbstractKeystore {
109109
try encryptDataToStorage(password, data: serializedRootNode, aesMode: aesMode)
110110
}
111111

112-
public func createNewChildAccount(password: String = "web3swift") throws {
112+
public func createNewChildAccount(password: String) throws {
113113
guard let decryptedRootNode = try? self.getPrefixNodeData(password) else {
114114
throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")
115115
}
@@ -127,7 +127,7 @@ public class BIP32Keystore: AbstractKeystore {
127127
try encryptDataToStorage(password, data: serializedRootNode, aesMode: self.keystoreParams!.crypto.cipher)
128128
}
129129

130-
func createNewAccount(parentNode: HDNode, password: String = "web3swift") throws {
130+
func createNewAccount(parentNode: HDNode, password: String ) throws {
131131
var newIndex = UInt32(0)
132132
for p in addressStorage.paths {
133133
guard let idx = UInt32(p.components(separatedBy: "/").last!) else {continue}
@@ -151,7 +151,7 @@ public class BIP32Keystore: AbstractKeystore {
151151
addressStorage.add(address: newAddress, for: newPath)
152152
}
153153

154-
public func createNewCustomChildAccount(password: String = "web3swift", path: String) throws {guard let decryptedRootNode = try? self.getPrefixNodeData(password) else {
154+
public func createNewCustomChildAccount(password: String, path: String) throws {guard let decryptedRootNode = try? self.getPrefixNodeData(password) else {
155155
throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")
156156
}
157157
guard let rootNode = HDNode(decryptedRootNode) else {
@@ -369,7 +369,7 @@ public class BIP32Keystore: AbstractKeystore {
369369
return data
370370
}
371371

372-
public func serializeRootNodeToString(password: String = "web3swift") throws -> String {
372+
public func serializeRootNodeToString(password: String ) throws -> String {
373373
guard let decryptedRootNode = try? self.getPrefixNodeData(password) else {
374374
throw AbstractKeystoreError.encryptionError("Failed to decrypt a keystore")
375375
}

Sources/Core/KeystoreManager/EthereumKeystoreV3.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class EthereumKeystoreV3: AbstractKeystore {
6969
}
7070
}
7171

72-
public init?(password: String = "web3swift", aesMode: String = "aes-128-cbc") throws {
72+
public init?(password: String, aesMode: String = "aes-128-cbc") throws {
7373
guard var newPrivateKey = SECP256K1.generatePrivateKey() else {
7474
return nil
7575
}
@@ -79,7 +79,7 @@ public class EthereumKeystoreV3: AbstractKeystore {
7979
try encryptDataToStorage(password, keyData: newPrivateKey, aesMode: aesMode)
8080
}
8181

82-
public init?(privateKey: Data, password: String = "web3swift", aesMode: String = "aes-128-cbc") throws {
82+
public init?(privateKey: Data, password: String, aesMode: String = "aes-128-cbc") throws {
8383
guard privateKey.count == 32 else {
8484
return nil
8585
}

Sources/Core/Structure/Transaction/TransactionDetails.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ public struct TransactionDetails: Decodable {
2828
self.transaction = try CodableTransaction(from: decoder)
2929
}
3030
}
31+
32+
extension TransactionDetails: APIResultType { }

Sources/Core/Structure/Transaction/TransactionReceipt.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,5 @@ extension TransactionReceipt: Decodable {
7474
self.logs = try container.decode([EventLog].self, forKey: .logs)
7575
}
7676
}
77+
78+
extension TransactionReceipt: APIResultType { }

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+Call.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
//
2-
// Created by Alex Vlasov.
3-
// Copyright © 2018 Alex Vlasov. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
44
//
55

66
import Foundation
77
import Core
88

99

1010
extension web3.Eth {
11-
12-
// FIXME: Rewrite this to CodableTransaction
13-
// FIXME: Not working yet.
1411
public func callTransaction(_ transaction: CodableTransaction) async throws -> Data {
15-
// FIXME: Make me CodableTransaction
1612
let request: APIRequest = .call(transaction, transaction.callOnBlock ?? .latest)
1713
let response: APIResponse<Data> = try await APIRequest.sendRequest(with: self.provider, for: request)
1814
return response.result

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+EstimateGas.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// Created by Alex Vlasov.
3-
// Copyright © 2018 Alex Vlasov. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
44
//
55

66
import Foundation
@@ -9,12 +9,8 @@ import Core
99

1010

1111
extension web3.Eth {
12-
13-
// FIXME: Rewrite this to CodableTransaction
14-
public func estimateGas(for transaction: CodableTransaction) async throws -> BigUInt {
15-
16-
// FIXME: Something wrong with this. We should not to get parameters + options in one method.
17-
let request: APIRequest = .estimateGas(transaction, transaction.callOnBlock ?? .latest)
12+
public func estimateGas(for transaction: CodableTransaction, onBlock: BlockNumber = .latest) async throws -> BigUInt {
13+
let request: APIRequest = .estimateGas(transaction, onBlock)
1814
let response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: provider, for: request)
1915

2016
if let policy = transaction.gasLimitPolicy {

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+FeeHistory.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//
2-
// Promise+Web3+Eth+FeeHistory.swift
3-
//
4-
// Created by Yaroslav on 11.04.2022.
5-
// Copyright © 2022 web3swift. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
64
//
75

86
import Foundation

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetAccounts.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// Created by Alex Vlasov.
3-
// Copyright © 2018 Alex Vlasov. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
44
//
55

66
import Foundation

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBalance.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// Created by Alex Vlasov.
3-
// Copyright © 2018 Alex Vlasov. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
44
//
55

66
import Foundation

Sources/web3swift/EthereumAPICalls/Ethereum/Eth+GetBlockByHash.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//
2-
// Created by Alex Vlasov.
3-
// Copyright © 2018 Alex Vlasov. All rights reserved.
2+
// Created by Yaroslav Yashin.
3+
// Copyright © 2022 Yaroslav Yashin. All rights reserved.
44
//
55

66
import Foundation
@@ -10,11 +10,7 @@ import Core
1010

1111
extension web3.Eth {
1212
public func block(by hash: Data, fullTransactions: Bool = false) async throws -> Block {
13-
try await block(by: hash.toHexString().addHexPrefix(), fullTransactions: fullTransactions)
14-
}
15-
16-
public func block(by hash: String, fullTransactions: Bool = false) async throws -> Block {
17-
let requestCall: APIRequest = .getBlockByHash(hash, fullTransactions)
13+
let requestCall: APIRequest = .getBlockByHash(hash.toHexString().addHexPrefix(), fullTransactions)
1814
let response: APIResponse<Block> = try await APIRequest.sendRequest(with: self.provider, for: requestCall)
1915
return response.result
2016
}

0 commit comments

Comments
 (0)