Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions scripts/config.swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
--acronyms ID,URL,UUID
--allman false
--anonymous-for-each convert
--asset-literals visual-width
--async-capturing
--before-marks
--binary-grouping 4,8
--call-site-paren default
--category-mark "MARK: %c"
--class-threshold 0
--closing-paren balanced
--closure-void remove
--complex-attributes preserve
--computed-var-attributes preserve
--conditional-assignment after-property
--conflict-markers reject
--date-format system
--decimal-grouping 3,6
--doc-comments before-declarations
--else-position same-line
--empty-braces no-space
--enum-namespaces always
--enum-threshold 0
--equatable-macro none
--exponent-case lowercase
--exponent-grouping disabled
--extension-acl on-extension
--extension-mark "MARK: - %t + %c"
--extension-threshold 0
--file-macro "#file"
--fraction-grouping disabled
--fragment false
--func-attributes prev-line
--generic-types
--group-blank-lines true
--grouped-extension "MARK: %c"
--guard-else same-line
--header "//\n// web3.swift\n// Copyright © Argent Labs Limited. All rights reserved.\n//"
--hex-grouping 4,8
--hex-literal-case uppercase
--ifdef indent
--import-grouping length
--indent 4
--indent-case false
--indent-strings false
--inferred-types always
--init-coder-nil false
--language-mode 0
--lifecycle
--line-after-marks false
--line-between-guards false
--linebreaks lf
--mark-categories true
--mark-extensions always
--mark-types always
--max-width none
--modifier-order
--never-trailing
--nil-init remove
--no-space-operators
--no-wrap-operators
--non-complex-attributes
--octal-grouping 4,8
--operator-func spaced
--organization-mode visibility
--organize-types actor,class,enum,struct
--pattern-let hoist
--preserve-acronyms
--preserve-decls
--preserved-property-types Package
--property-types infer-locals-only
--ranges spaced
--self remove
--self-required
--semicolons inline
--short-optionals always
--single-line-for-each ignore
--smart-tabs enabled
--some-any true
--sort-swiftui-properties none
--sorted-patterns
--stored-var-attributes preserve
--strip-unused-args always
--struct-threshold 0
--swift-version 5.9
--tab-width unspecified
--throw-capturing
--timezone system
--trailing-closures
--trailing-commas always
--trim-whitespace always
--type-attributes prev-line
--type-blank-lines remove
--type-delimiter space-after
--type-mark "MARK: - %t"
--type-marks
--type-order
--url-macro none
--visibility-marks
--visibility-order
--void-type void
--wrap-arguments before-first
--wrap-collections before-first
--wrap-conditions preserve
--wrap-effects preserve
--wrap-enum-cases always
--wrap-parameters before-first
--wrap-return-type preserve
--wrap-string-interpolation default
--wrap-ternary default
--wrap-type-aliases preserve
--xcode-indentation disabled
--xctest-symbols
--yoda-swap always
--disable consecutiveSpaces,enumNamespaces,extensionAccessControl,genericExtensions,headerFileName,modifierOrder,numberFormatting,opaqueGenericParameters,preferKeyPath,redundantBackticks,redundantExtensionACL,redundantFileprivate,redundantPattern,redundantRawValues,redundantSelf,sortDeclarations,spaceAroundGenerics,strongOutlets,trailingClosures,trailingCommas,unusedArguments,wrap,wrapMultilineStatementBraces,wrapSingleLineComments,yodaConditions
--enable blankLinesBetweenImports,isEmpty,wrapConditionalBodies
10 changes: 5 additions & 5 deletions scripts/runSwiftFormat.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

SWIFT_VERSION=5.3
SWIFT_VERSION=5.9

cd "$(dirname "$0")"

Expand All @@ -17,8 +17,8 @@ if ! which bin/swiftformat >/dev/null; then
cd bin
rm -r ./*

downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.50.3/swiftformat.artifactbundle.zip"
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.50.3-macos/bin/swiftformat .
downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.57.2/swiftformat.artifactbundle.zip"
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.57.2-macos/bin/swiftformat .
find . -name "*Tmp" -type d -prune -exec rm -rf '{}' +
for entry in ./*
do
Expand All @@ -38,12 +38,12 @@ cleanup() {
}

format() {
bin/swiftformat ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
bin/swiftformat ../web3swift/src/ --config "config.swiftformat" --swiftversion $SWIFT_VERSION
cleanup
}

lint() {
bin/swiftformat --lint ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
bin/swiftformat --lint ../web3swift/src/ --config "config.swiftformat" --swiftversion $SWIFT_VERSION
cleanup
}

Expand Down
79 changes: 0 additions & 79 deletions scripts/swiftformat.yml

This file was deleted.

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

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

import Logging
Expand Down
2 changes: 1 addition & 1 deletion web3swift/src/Account/EthereumKeyStorage+Password.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// web3.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
// Copyright © Argent Labs Limited. All rights reserved.
//

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

import Foundation
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 web3swift/src/Account/Signature.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// web3.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
// Copyright © Argent Labs Limited. All rights reserved.
//

import Foundation
Expand Down
7 changes: 3 additions & 4 deletions web3swift/src/Account/TypedData.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// web3.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
// Copyright © Argent Labs Limited. All rights reserved.
//

import BigInt
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 All @@ -88,7 +88,6 @@ extension TypedData {
}

let recursiveEncoded: [UInt8] = try valueTypes.flatMap { variable -> [UInt8] in

// Decomposite the type if it is array type
let components = variable.type.components(separatedBy: CharacterSet(charactersIn: "[]"))
let parsedType = components[0]
Expand Down
10 changes: 5 additions & 5 deletions web3swift/src/Client/BaseEthereumClient+Call.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// web3.swift
// Copyright © 2022 Argent Labs Limited. All rights reserved.
// Copyright © Argent Labs Limited. All rights reserved.
//

import Foundation
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
Loading
Loading