Skip to content

Commit 2bbb2f2

Browse files
authored
Merge pull request #316 from argentlabs/develop
Sync to master (1.5.0)
2 parents 3c4d4a5 + 1ad8cc4 commit 2bbb2f2

File tree

86 files changed

+2472
-1527
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2472
-1527
lines changed

.github/workflows/CI.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
name: CI
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches: [ develop ]
6+
workflow_dispatch:
67

78
jobs:
9+
lint:
10+
runs-on: macos-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Lint
14+
run: ./scripts/runSwiftFormat.sh -l
815
macos:
16+
needs: lint
917
runs-on: macos-latest
18+
env:
19+
TESTS_PRIVATEKEY: ${{ secrets.TESTS_PRIVATEKEY }}
1020
steps:
1121
- uses: actions/checkout@v3
22+
- name: SetupKey
23+
run: ./scripts/setupKey.sh "${{ secrets.TESTS_PRIVATEKEY }}"
1224
- name: Build
1325
run: swift build -v
1426
- name: Tests
1527
run: swift test -v
1628
linux:
29+
needs: lint
1730
runs-on: ubuntu-latest
1831
container:
1932
image: swift:5.5-bionic
33+
env:
34+
TESTS_PRIVATEKEY: ${{ secrets.TESTS_PRIVATEKEY }}
2035
steps:
2136
- uses: actions/checkout@v3
37+
- name: SetupKey
38+
run: ./scripts/setupKey.sh "${{ secrets.TESTS_PRIVATEKEY }}"
2239
- name: Build
2340
run: swift build -v
2441
- name: Tests
25-
run: swift test -v
42+
run: swift test -v

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@ fastlane/report.xml
6464
fastlane/Preview.html
6565
fastlane/screenshots
6666
fastlane/test_output
67+
68+
scripts/bin/*
69+
TestConfig_private.swift

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GEM
33
specs:
44
CFPropertyList (3.0.5)
55
rexml
6-
activesupport (6.1.5)
6+
activesupport (6.1.7.2)
77
concurrent-ruby (~> 1.0, >= 1.0.2)
88
i18n (>= 1.6, < 2)
99
minitest (>= 5.1)
@@ -54,7 +54,7 @@ GEM
5454
netrc (~> 0.11)
5555
cocoapods-try (1.2.0)
5656
colored2 (3.1.2)
57-
concurrent-ruby (1.1.10)
57+
concurrent-ruby (1.2.0)
5858
escape (0.0.4)
5959
ethon (0.15.0)
6060
ffi (>= 1.15.0)
@@ -63,10 +63,10 @@ GEM
6363
fuzzy_match (2.0.4)
6464
gh_inspector (1.1.3)
6565
httpclient (2.8.3)
66-
i18n (1.10.0)
66+
i18n (1.12.0)
6767
concurrent-ruby (~> 1.0)
6868
json (2.6.1)
69-
minitest (5.15.0)
69+
minitest (5.17.0)
7070
molinillo (0.8.0)
7171
nanaimo (0.3.0)
7272
nap (1.1.0)
@@ -76,7 +76,7 @@ GEM
7676
ruby-macho (2.5.1)
7777
typhoeus (1.4.0)
7878
ethon (>= 0.9.0)
79-
tzinfo (2.0.4)
79+
tzinfo (2.0.6)
8080
concurrent-ruby (~> 1.0)
8181
xcodeproj (1.21.0)
8282
CFPropertyList (>= 2.3.3, < 4.0)
@@ -85,7 +85,7 @@ GEM
8585
colored2 (~> 3.1)
8686
nanaimo (~> 0.3.0)
8787
rexml (~> 3.2.4)
88-
zeitwerk (2.5.4)
88+
zeitwerk (2.6.6)
8989

9090
PLATFORMS
9191
ruby

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Create an instance of `EthereumHttpClient` or `EthereumWebSocketClient`. This wi
4343
`EthereumHttpClient`
4444
```swift
4545
guard let clientUrl = URL(string: "https://an-infura-or-similar-url.com/123") else { return }
46-
let client = EthereumClient(url: clientUrl)
46+
let client = EthereumHttpClient(url: clientUrl)
4747
```
4848

4949
OR
@@ -117,13 +117,18 @@ If using `async/await` you can `await` on the result
117117
let txHash = try await client.eth_sendRawTransaction(transaction, withAccount: account)
118118
```
119119

120+
## Generating ABI from a smart contract ABI file
121+
Currently we don't support code generation as making it properly is a bigger project, and should possibly live outside of this repository.
122+
123+
You can try this project instead: [imanrep/swiftabigen](https://github.com/imanrep/swiftabigen)
124+
120125
### Data types
121126

122127
The library provides some types and helpers to make interacting with web3 and Ethereum easier.
123128

124129
- `EthereumAddress`: For representation of addresses, including checksum support.
125130
- `BigInt` and `BigUInt`: Using [BigInt](https://github.com/attaswift/BigInt) library
126-
- `EthereumBlock`: Represents the block, either number of RPC-specific defintions like 'Earliest' or 'Latest'
131+
- `EthereumBlock`: Represents the block, either number of RPC-specific definitions like 'Earliest' or 'Latest'
127132
- `EthereumTransaction`: Wraps a transaction. Encoders and decoders can work with it to generate proper `data` fields.
128133

129134
#### Conversion from and to Foundation types
@@ -159,7 +164,9 @@ We support querying ERC721 token data via the `ERC721` struct. Including:
159164

160165
### Running Tests
161166

162-
The tests will all pass when running against Goerli. You will need to provide a URL for the blockchain proxy (e.g. on Infura), and a key-pair in `TestConfig.swift`. Some of the account signing tests will fail, given the signature assertions are against a specific (unprovided) key.
167+
Some of the tests require a private key, which is not stored in the repository. You can ignore these while testing locally, as CI will use the encrypted secret key from Github.
168+
169+
It's better to run only the tests you need, instead of the whole test suite while developing. If you ever need to set up the key locally, take a look at `TestConfig.swift` where you can manually set it up. Alternatively you can set it up by calling the script `setupKey.sh` and passing the value (adding 0x) so it's written to an ignored file.
163170

164171
## Dependencies
165172

@@ -169,17 +176,14 @@ We built web3.swift to be as lightweight as possible. However, given the cryptog
169176
- [Tiny AES](https://github.com/kokke/tiny-AES-c): A small and portable implementation of the AES ECB, CTR and CBC encryption algorithms.
170177
- [secp256k1.swift](https://github.com/Boilertalk/secp256k1.swift)
171178

172-
We also use Apple's own CommonCrypto (via [this](https://github.com/sergejp/CommonCrypto) method) and [BigInt](https://github.com/attaswift/BigInt) via CocoaPod dependency.
173-
174-
## Todos
175-
176-
There are some features that have yet to be fully implemented! Not every RPC method is currently supported, and here's some other suggestions we would like to see in the future:
177-
179+
Package dependencies:
180+
- [BigInt](https://github.com/attaswift/BigInt)
181+
- [GenericJSON](https://github.com/iwill/generic-json-swift)
182+
- [secp256k1](https://github.com/GigaBitcoin/secp256k1.swift.git)
183+
- [Vapor Websocket](https://github.com/vapor/websocket-kit.git)
184+
- [Apple Swift-log](https://github.com/apple/swift-log.git)
178185

179-
- Batch support for JSONRPC interface
180-
- Use a Hex struct for values to be more explicit in expected types
181-
- Use [Truffle](https://github.com/trufflesuite/ganache-cli) for running tests
182-
- Bloom Filter support
186+
Also for Linux build, we can't se Apple crypto APIs, so we embedded a small subset of CryptoSwift (instead of importing the whole library). Credit to [Marcin Krzyżanowski](https://github.com/krzyzanowskim/CryptoSwift)
183187

184188
## Contributors
185189

scripts/prepareForPush.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
SWIFT_VERSION=5.3
4+
5+
cd "$(dirname "$0")"
6+
7+
./runSwiftFormat.sh

scripts/runSwiftFormat.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh
2+
3+
SWIFT_VERSION=5.3
4+
5+
cd "$(dirname "$0")"
6+
7+
function downloadAndUnzip {
8+
curl -L -o tool.zip $2
9+
unzip -o -d $1/ tool.zip
10+
rm tool.zip
11+
}
12+
13+
if ! which bin/swiftformat >/dev/null; then
14+
echo "warning: SwiftFormat not installed, installing..."
15+
16+
mkdir -p -- "bin"
17+
cd bin
18+
rm -r ./*
19+
20+
downloadAndUnzip "SwiftFormatTmp" "https://github.com/nicklockwood/SwiftFormat/releases/download/0.50.3/swiftformat.artifactbundle.zip"
21+
mv -f ./SwiftFormatTmp/swiftformat.artifactbundle/swiftformat-0.50.3-macos/bin/swiftformat .
22+
find . -name "*Tmp" -type d -prune -exec rm -rf '{}' +
23+
for entry in ./*
24+
do
25+
chmod +x "$entry"
26+
done
27+
cd ../
28+
fi
29+
30+
cleanup() {
31+
exit_code=$?
32+
if [[ ${exit_code} -eq 0 ]]; then
33+
exit 0
34+
else
35+
echo "Need to run scripts/prepareForPush.sh script to prepare the code before a PullRequest."
36+
exit 1
37+
fi
38+
}
39+
40+
format() {
41+
bin/swiftformat ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
42+
cleanup
43+
}
44+
45+
lint() {
46+
bin/swiftformat --lint ../web3swift/src/ --config "swiftformat.yml" --swiftversion $SWIFT_VERSION
47+
cleanup
48+
}
49+
50+
while getopts "fl" o; do
51+
case "${o}" in
52+
f)
53+
format;
54+
exit;;
55+
l)
56+
lint;
57+
exit;;
58+
*)
59+
exit;;
60+
esac
61+
done
62+
63+
format

scripts/setupKey.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
3+
# write first argument to a Test
4+
echo "extension TestConfig {\nstatic let privateKey = \"$1\"\nstatic let publicKey = \"0xE78e5ecb061fE3DD1672dDDA7b5116213B23B99A\"\n}" > web3sTests/TestConfig_private.swift

scripts/swiftformat.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
--acronyms ID,URL,UUID
2+
--allman false
3+
--assetliterals visual-width
4+
--beforemarks
5+
--binarygrouping 4,8
6+
--categorymark "MARK: %c"
7+
--classthreshold 0
8+
--closingparen balanced
9+
--closurevoid remove
10+
--commas always
11+
--conflictmarkers reject
12+
--decimalgrouping 3,6
13+
--elseposition same-line
14+
--emptybraces no-space
15+
--enumnamespaces always
16+
--enumthreshold 0
17+
--exponentcase lowercase
18+
--exponentgrouping disabled
19+
--extensionacl on-extension
20+
--extensionlength 0
21+
--extensionmark "MARK: - %t + %c"
22+
--fractiongrouping disabled
23+
--fragment false
24+
--funcattributes prev-line
25+
--generictypes
26+
--groupedextension "MARK: %c"
27+
--guardelse same-line
28+
--header ignore
29+
--hexgrouping 4,8
30+
--hexliteralcase uppercase
31+
--ifdef indent
32+
--importgrouping length
33+
--indent 4
34+
--indentcase false
35+
--indentstrings false
36+
--lifecycle
37+
--lineaftermarks false
38+
--linebreaks lf
39+
--markcategories true
40+
--markextensions always
41+
--marktypes always
42+
--maxwidth none
43+
--modifierorder
44+
--nevertrailing
45+
--nospaceoperators
46+
--nowrapoperators
47+
--octalgrouping 4,8
48+
--operatorfunc spaced
49+
--organizetypes actor,class,enum,struct
50+
--patternlet hoist
51+
--ranges spaced
52+
--redundanttype infer-locals-only
53+
--self remove
54+
--selfrequired
55+
--semicolons inline
56+
--shortoptionals always
57+
--smarttabs enabled
58+
--someAny true
59+
--stripunusedargs always
60+
--structthreshold 0
61+
--tabwidth unspecified
62+
--trailingclosures
63+
--trimwhitespace always
64+
--typeattributes prev-line
65+
--typeblanklines remove
66+
--typemark "MARK: - %t"
67+
--varattributes same-line
68+
--voidtype void
69+
--wraparguments before-first
70+
--wrapcollections before-first
71+
--wrapconditions preserve
72+
--wrapparameters before-first
73+
--wrapreturntype preserve
74+
--wrapternary default
75+
--wraptypealiases preserve
76+
--xcodeindentation disabled
77+
--yodaswap always
78+
--disable enumNamespaces,extensionAccessControl,fileHeader,genericExtensions,modifierOrder,numberFormatting,opaqueGenericParameters,preferKeyPath,redundantBackticks,redundantExtensionACL,redundantFileprivate,redundantPattern,redundantRawValues,redundantSelf,sortDeclarations,spaceAroundGenerics,strongOutlets,trailingClosures,trailingCommas,unusedArguments,wrap,wrapMultilineStatementBraces,wrapSingleLineComments,yodaConditions
79+
--enable blankLineAfterImports,blankLinesBetweenImports,isEmpty,wrapConditionalBodies

web3.swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'web3.swift'
3-
s.version = '1.4.1'
3+
s.version = '1.5.0'
44
s.license = 'MIT'
55
s.summary = 'Ethereum API for Swift'
66
s.homepage = 'https://github.com/argentlabs/web3.swift'

0 commit comments

Comments
 (0)