Skip to content

Commit 99c9b55

Browse files
chore: merge with develop branch
2 parents 9f8f820 + 27e9d65 commit 99c9b55

File tree

7 files changed

+125
-91
lines changed

7 files changed

+125
-91
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-json
11+
- id: mixed-line-ending
12+
- id: no-commit-to-branch
13+
args: [--branch, staging, --branch, main, --branch, master, --branch, develop-4.0, --branch, develop-upstream]
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.2.2
16+
hooks:
17+
- id: codespell
18+
args: ["--count --ignore-words-list=ans,deriver,inout,packag --skip=\"*.js,*WordLists.swift,.git,Carthage,.build,build\""]
19+
# SwiftLint is commented out until we fix all SwiftLint warnings and errors.
20+
# https://github.com/web3swift-team/web3swift/pull/756
21+
#- repo: https://github.com/realm/SwiftLint
22+
# rev: 0.50.3
23+
# hooks:
24+
# - id: swiftlint
25+
# args: [--fix, Sources, Tests]

.swiftlint.yml

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
excluded:
2-
- Carthage
3-
- Pods
42
- .build
53
- Build
4+
- Carthage
65
- DerivedData
6+
- Pods
77

88
disabled_rules:
9-
- type_name
9+
- function_parameter_count
1010
- identifier_name
1111
- line_length
1212
- multiple_closures_with_trailing_closure
13-
- todo
14-
- function_parameter_count
1513
- nesting
14+
- todo
15+
- type_name
1616

1717
opt_in_rules:
18-
- weak_delegate
19-
- unused_import
20-
- unneeded_parentheses_in_closure_argument
21-
- trailing_closure
22-
- static_operator
23-
- redundant_nil_coalescing
24-
- override_in_extension
25-
- legacy_objc_type
26-
- implicitly_unwrapped_optional
27-
- force_unwrapping
28-
- empty_string
29-
- closure_body_length
30-
- fallthrough
31-
- indentation_width
18+
- closure_body_length
19+
- empty_string
20+
- fallthrough
21+
- force_unwrapping
22+
- implicitly_unwrapped_optional
23+
- indentation_width
24+
- legacy_objc_type
25+
- override_in_extension
26+
- redundant_nil_coalescing
27+
- static_operator
28+
- trailing_closure
29+
- unneeded_parentheses_in_closure_argument
30+
- unused_import
31+
- weak_delegate
3232

3333
# force warnings
3434
force_cast: error

README.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
- [Core features](#core-features)
2121
- [Installation](#installation)
22-
- [CocoaPods](#cocoapods)
2322
- [Swift Package](#swift-package)
23+
- [CocoaPods](#cocoapods)
2424
- [Example usage](#example-usage)
2525
- [Send Ether](#send-ether)
2626
- [Contract read method](#contract-read-method)
@@ -66,6 +66,27 @@
6666

6767
## Installation
6868

69+
### Swift Package (Recommended)
70+
The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code that is well integrated with Swift build system.
71+
72+
Once you have your Swift package set up, adding `web3swift` as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
73+
```swift
74+
dependencies: [
75+
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
76+
]
77+
```
78+
79+
Or if your project is not a package follow these guidelines on [how to add a Swift Package to your Xcode project](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app).
80+
81+
82+
## Example usage
83+
In the imports section:
84+
85+
```swift
86+
import web3swift
87+
import Web3Core
88+
```
89+
6990
### CocoaPods
7091

7192
[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:
@@ -91,23 +112,7 @@ Then, run the following command:
91112
$ pod install
92113
```
93114

94-
### Swift Package
95-
The [Swift Package Manager](https://swift.org/package-manager/ "") is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
96-
97-
Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
98-
```swift
99-
dependencies: [
100-
.package(url: "https://github.com/web3swift-team/web3swift.git", .upToNextMajor(from: "3.0.0"))
101-
]
102-
```
103-
104-
## Example usage
105-
In the imports section:
106-
107-
```swift
108-
import web3swift
109-
import Web3Core
110-
```
115+
> **WARNING**: CocoaPods is a powerful tool for managing dependencies in iOS development, but it also has some limitations that preventing us of providing first class support there. We highly recommend using SPM first as using CocoaPods will delay new updates and bug fixes being delivered to you.
111116
112117
### Send Ether
113118
```swift
@@ -188,6 +193,10 @@ $ ganache
188193
This will create a local blockchain and also some test accounts that are used throughout our tests.
189194
Make sure that `ganache` is running on its default port `8546`. To change the port in test cases locate `LocalTestCase.swift` and modify the static `url` variable.
190195

196+
### Before you commit
197+
198+
We are using [pre-commit](https://pre-commit.com) to run validations locally before a commit is created. Please, install pre-commit and run `pre-commit install` from project's root directory. After that before every commit git hook will run and execute `codespell`, `swiftlint` and other checks.
199+
191200
## Contribute
192201
Want to improve? It's awesome:
193202
Then good news for you: **We are ready to pay for your contribution via [@gitcoin bot](https://gitcoin.co/grants/358/web3swift)!**

Sources/Web3Core/EthereumABI/ABIElements.swift

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ extension ABI.Element {
262262

263263
extension ABI.Element.Function {
264264
public func decodeInputData(_ rawData: Data) -> [String: Any]? {
265-
return Web3Core.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs)
265+
return ABIDecoder.decodeInputData(rawData, methodEncoding: methodEncoding, inputs: inputs)
266266
}
267267

268268
/// Decodes data returned by a function call. Able to decode `revert(string)`, `revert CustomError(...)` and `require(expression, string)` calls.
@@ -432,61 +432,62 @@ extension ABI.Element.Function {
432432

433433
extension ABI.Element.Constructor {
434434
public func decodeInputData(_ rawData: Data) -> [String: Any]? {
435-
return Web3Core.decodeInputData(rawData, inputs: inputs)
435+
return ABIDecoder.decodeInputData(rawData, inputs: inputs)
436436
}
437437
}
438438

439-
/// Generic input decoding function.
440-
/// - Parameters:
441-
/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`.
442-
/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding.
443-
/// - inputs: expected input types. Order must be the same as in function declaration.
444-
/// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty.
445-
/// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned.
446-
private func decodeInputData(_ rawData: Data,
447-
methodEncoding: Data? = nil,
448-
inputs: [ABI.Element.InOut]) -> [String: Any]? {
449-
let data: Data
450-
let sig: Data?
451-
452-
switch rawData.count % 32 {
453-
case 0:
454-
sig = nil
455-
data = Data()
456-
break
457-
case 4:
458-
sig = rawData[0 ..< 4]
459-
data = Data(rawData[4 ..< rawData.count])
460-
default:
461-
return nil
462-
}
463-
464-
if methodEncoding != nil && sig != nil && sig != methodEncoding {
465-
return nil
466-
}
467-
468-
var returnArray = [String: Any]()
439+
extension ABIDecoder {
440+
/// Generic input decoding function.
441+
/// - Parameters:
442+
/// - rawData: data to decode. Must match the following criteria: `data.count == 0 || data.count % 32 == 4`.
443+
/// - methodEncoding: 4 bytes representing method signature like `0xFFffFFff`. Can be omitted to avoid checking method encoding.
444+
/// - inputs: expected input types. Order must be the same as in function declaration.
445+
/// - Returns: decoded dictionary of input arguments mapped to their indices and arguments' names if these are not empty.
446+
/// If decoding of at least one argument fails, `rawData` size is invalid or `methodEncoding` doesn't match - `nil` is returned.
447+
static func decodeInputData(_ rawData: Data,
448+
methodEncoding: Data? = nil,
449+
inputs: [ABI.Element.InOut]) -> [String: Any]? {
450+
let data: Data
451+
let sig: Data?
452+
453+
switch rawData.count % 32 {
454+
case 0:
455+
sig = nil
456+
data = Data()
457+
break
458+
case 4:
459+
sig = rawData[0 ..< 4]
460+
data = Data(rawData[4 ..< rawData.count])
461+
default:
462+
return nil
463+
}
469464

470-
if data.count == 0 && inputs.count == 1 {
471-
let name = "0"
472-
let value = inputs[0].type.emptyValue
473-
returnArray[name] = value
474-
if inputs[0].name != "" {
475-
returnArray[inputs[0].name] = value
465+
if methodEncoding != nil && sig != nil && sig != methodEncoding {
466+
return nil
476467
}
477-
} else {
478-
guard inputs.count * 32 <= data.count else { return nil }
479-
480-
var i = 0
481-
guard let values = ABIDecoder.decode(types: inputs, data: data) else { return nil }
482-
for input in inputs {
483-
let name = "\(i)"
484-
returnArray[name] = values[i]
485-
if input.name != "" {
486-
returnArray[input.name] = values[i]
468+
469+
var returnArray = [String: Any]()
470+
if data.count == 0 && inputs.count == 1 {
471+
let name = "0"
472+
let value = inputs[0].type.emptyValue
473+
returnArray[name] = value
474+
if inputs[0].name != "" {
475+
returnArray[inputs[0].name] = value
476+
}
477+
} else {
478+
guard inputs.count * 32 <= data.count else { return nil }
479+
480+
var i = 0
481+
guard let values = ABIDecoder.decode(types: inputs, data: data) else { return nil }
482+
for input in inputs {
483+
let name = "\(i)"
484+
returnArray[name] = values[i]
485+
if input.name != "" {
486+
returnArray[input.name] = values[i]
487+
}
488+
i = i + 1
487489
}
488-
i = i + 1
489490
}
491+
return returnArray
490492
}
491-
return returnArray
492493
}

Tests/web3swiftTests/localTests/TransactionsTests.swift

100755100644
File mode changed.

Web3Core.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Pod::Spec.new do |spec|
22
spec.compiler_flags = '-DCOCOAPODS'
33

44
spec.name = 'Web3Core'
5-
spec.version = '3.0.6'
6-
spec.module_name = 'Core'
5+
spec.version = '3.1.1'
76
spec.ios.deployment_target = "13.0"
87
spec.osx.deployment_target = "10.15"
98
spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' }
@@ -16,5 +15,5 @@ Pod::Spec.new do |spec|
1615
spec.dependency 'secp256k1.c', '~> 0.1'
1716
spec.dependency 'BigInt', '~> 5.2.0' # no newer version in pods.
1817
spec.dependency 'CryptoSwift', '~> 1.5.1'
19-
spec.source_files = "Sources/Core/**/*.swift"
18+
spec.source_files = "Sources/Web3Core/**/*.swift"
2019
end

web3swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
WEB3CORE_VERSION ||= '3.0.6'
1+
WEB3CORE_VERSION ||= '3.1.1'
22

33
Pod::Spec.new do |spec|
44
spec.name = 'web3swift'

0 commit comments

Comments
 (0)