Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHANGE] Restructure Swift Package #374

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
[CHANGE] SwiftFormat Source Files
  • Loading branch information
dioKaratzas committed Aug 13, 2024
commit 4025553df4e96e4a3449bf08b6cbea7789d8d827
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumAccount+SignTransaction.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Account/EthereumAccount.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumAccount.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumKeyStorage+Password.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
14 changes: 7 additions & 7 deletions Sources/Web3Swift/Account/EthereumKeyStorage.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumKeyStorage.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -32,7 +32,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
private let localFileName = "ethereumkey"

private var addressPath: String? {
guard let address = address else {
guard let address else {
return nil
}
if let url = folderPath {
Expand All @@ -58,7 +58,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
private let fileManager = FileManager.default

public func storePrivateKey(key: Data) throws {
guard let localPath = localPath else {
guard let localPath else {
throw EthereumKeyStorageError.failedToSave
}

Expand All @@ -70,7 +70,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {
}

public func loadPrivateKey() throws -> Data {
guard let localPath = localPath else {
guard let localPath else {
throw EthereumKeyStorageError.failedToLoad
}

Expand All @@ -84,7 +84,7 @@ public class EthereumKeyLocalStorage: EthereumSingleKeyStorageProtocol {

extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {
public func fetchAccounts() throws -> [EthereumAddress] {
guard let folderPath = folderPath else {
guard let folderPath else {
throw EthereumKeyStorageError.failedToLoad
}

Expand Down Expand Up @@ -139,7 +139,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {

public func deleteAllKeys() throws {
do {
if let folderPath = folderPath {
if let folderPath {
let directoryContents = try fileManager.contentsOfDirectory(atPath: folderPath.path)
let addresses = directoryContents.filter({ $0.web3.isAddress || $0 == localFileName })
for address in addresses {
Expand All @@ -154,7 +154,7 @@ extension EthereumKeyLocalStorage: EthereumMultipleKeyStorageProtocol {

public func deletePrivateKey(for address: EthereumAddress) throws {
do {
if let folderPath = folderPath {
if let folderPath {
let filePathName = folderPath.appendingPathComponent(address.asString())
try fileManager.removeItem(at: filePathName)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Account/Signature.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// Signature.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
6 changes: 3 additions & 3 deletions Sources/Web3Swift/Account/TypedData.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// TypedData.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -61,8 +61,8 @@ extension TypedData {
// Whole data blob hash to sign
public func signableHash() throws -> Data {
var data = Data([0x19, 0x01])
data.append(try encodeData(data: domain, type: "EIP712Domain").web3.keccak256)
data.append(try encodeData(data: message, type: primaryType).web3.keccak256)
try data.append(encodeData(data: domain, type: "EIP712Domain").web3.keccak256)
try data.append(encodeData(data: message, type: primaryType).web3.keccak256)
return data.web3.keccak256
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/Web3Swift/Client/BaseEthereumClient+Call.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// BaseEthereumClient+Call.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -48,7 +48,7 @@ extension BaseEthereumClient {
func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
var nested = container.nestedContainer(keyedBy: TransactionCodingKeys.self)
if let from = from {
if let from {
try nested.encode(from, forKey: .from)
}
try nested.encode(to, forKey: .to)
Expand Down Expand Up @@ -212,11 +212,11 @@ fileprivate extension OffchainReadError {
var isNextURLAllowed: Bool {
switch self {
case let .server(code, _):
return code >= 500 // 4xx responses -> Don't continue with next url
code >= 500 // 4xx responses -> Don't continue with next url
case .network, .invalidParams, .invalidResponse:
return true
true
case .tooManyRedirections:
return false
false
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Web3Swift/Client/BaseEthereumClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// BaseEthereumClient.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -34,11 +34,11 @@ open class BaseEthereumClient: EthereumClientProtocol {

func failureHandler(_ error: Error) -> EthereumClientError {
if case let .executionError(result) = error as? JSONRPCError {
return EthereumClientError.executionError(result.error)
EthereumClientError.executionError(result.error)
} else if case .executionError = error as? EthereumClientError, let error = error as? EthereumClientError {
return error
error
} else {
return EthereumClientError.unexpectedReturnValue
EthereumClientError.unexpectedReturnValue
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/HTTP/EthereumHttpClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumHttpClient.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumAddress.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumAddress.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
28 changes: 14 additions & 14 deletions Sources/Web3Swift/Client/Models/EthereumBlock.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumBlock.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand All @@ -14,22 +14,22 @@ public enum EthereumBlock: Hashable {
public var stringValue: String {
switch self {
case .Latest:
return "latest"
"latest"
case .Earliest:
return "earliest"
"earliest"
case .Pending:
return "pending"
"pending"
case let .Number(int):
return int.web3.hexString
int.web3.hexString
}
}

public var intValue: Int? {
switch self {
case let .Number(int):
return int
int
default:
return nil
nil
}
}

Expand Down Expand Up @@ -71,21 +71,21 @@ extension EthereumBlock: Comparable {
static public func < (lhs: EthereumBlock, rhs: EthereumBlock) -> Bool {
switch lhs {
case .Earliest:
return false
false
case .Latest:
return rhs != .Pending ? true : false
rhs != .Pending ? true : false
case .Pending:
return true
true
case let .Number(lhsInt):
switch rhs {
case .Earliest:
return false
false
case .Latest:
return true
true
case .Pending:
return true
true
case let .Number(rhsInt):
return lhsInt < rhsInt
lhsInt < rhsInt
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumBlockInfo.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumBlockInfo.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumHeader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumHeader.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumLog.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumLog.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
20 changes: 10 additions & 10 deletions Sources/Web3Swift/Client/Models/EthereumNetwork.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumNetwork.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand All @@ -12,33 +12,33 @@ public enum EthereumNetwork: Equatable, Decodable {
public static func fromString(_ networkId: String) -> EthereumNetwork {
switch networkId {
case "1":
return .mainnet
.mainnet
case "11155111":
return .sepolia
.sepolia
default:
return .custom(networkId)
.custom(networkId)
}
}

public var stringValue: String {
switch self {
case .mainnet:
return "1"
"1"
case .sepolia:
return "11155111"
"11155111"
case let .custom(str):
return str
str
}
}

public var intValue: Int {
switch self {
case .mainnet:
return 1
1
case .sepolia:
return 11155111
11155111
case let .custom(str):
return Int(str) ?? 0
Int(str) ?? 0
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Web3Swift/Client/Models/EthereumSubscription.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumSubscription.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand All @@ -14,13 +14,13 @@ public enum EthereumSubscriptionType: Equatable, Hashable {
var params: [EthereumSubscriptionParamElement] {
switch self {
case .newBlockHeaders:
return [.method("newHeads")]
[.method("newHeads")]
case let .logs(params):
return [.method("logs"), .logsParams(params ?? .init(address: nil, topics: nil))]
[.method("logs"), .logsParams(params ?? .init(address: nil, topics: nil))]
case .newPendingTransactions:
return [.method("newPendingTransactions")]
[.method("newPendingTransactions")]
case .syncing:
return [.method("syncing")]
[.method("syncing")]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumSyncStatus.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumSyncStatus.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
2 changes: 1 addition & 1 deletion Sources/Web3Swift/Client/Models/EthereumTransaction.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumTransaction.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EthereumTransactionReceipt.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// EventLoopGroupProvider.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// HttpNetworkProvider.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -35,7 +35,7 @@ public class HttpNetworkProvider: NetworkProviderProtocol {
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")

headers.forEach { key, value in
for (key, value) in headers {
request.addValue(value, forHTTPHeaderField: key)
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Web3Swift/Client/NetworkProviders/JSONRPC.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// web3.swift
// JSONRPC.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
//

Expand Down Expand Up @@ -78,9 +78,9 @@ public enum JSONRPCError: Error {
public var isExecutionError: Bool {
switch self {
case .executionError:
return true
true
default:
return false
false
}
}
}
Loading