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

Remove Promises #515

Merged
merged 46 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
3a4a482
remove promises
pharms-eth Apr 7, 2022
a9df4c7
first commit
pharms-eth Apr 7, 2022
fb5102c
Base and some cleanup
pharms-eth Apr 9, 2022
d712c42
propagate async changes
pharms-eth Apr 9, 2022
1008eef
Migrate from Promise to Async
pharms-eth Apr 10, 2022
d88a493
propagate async
pharms-eth Apr 10, 2022
4e49d11
propagate Async changes
pharms-eth Apr 11, 2022
6f2d7f2
update ERC with Async
pharms-eth Apr 13, 2022
27f504e
propagate async
pharms-eth Apr 13, 2022
a95bfb5
async
pharms-eth Apr 13, 2022
544171e
add async
pharms-eth Apr 13, 2022
ee7e3d9
Merge branch 'develop' into remove-Promises
pharms-eth Apr 13, 2022
08fe344
resolve confilct
pharms-eth Apr 13, 2022
ec3d2d3
bix fug
pharms-eth Apr 14, 2022
2bf9639
Create EthereumMetadata struct and add it to the project
mloit Apr 15, 2022
ba9aeea
Add the new metadata struct to EthereumTransaction
mloit Apr 15, 2022
fbb0726
Back out the workaround implemented tor gasPrice on EIP-1159 transact…
mloit Apr 15, 2022
4602cdf
update Oracle to use the new metadata struct
mloit Apr 15, 2022
45b60f6
Create EthereumMetadata struct and add it to the project
mloit Apr 15, 2022
878c2a9
Add the new metadata struct to EthereumTransaction
mloit Apr 15, 2022
e164bf6
Back out the workaround implemented tor gasPrice on EIP-1159 transact…
mloit Apr 15, 2022
d8a1daa
update Oracle to use the new metadata struct
mloit Apr 15, 2022
f28b306
Merge branch 'feature/transaction-metadata' of https://github.com/mlo…
mloit Apr 15, 2022
11b8260
typo fix
mloit Apr 15, 2022
ad3d00d
Merge branch 'develop' into remove-Promises
pharms-eth Apr 16, 2022
f7db2ea
resolve conflicts
pharms-eth Apr 16, 2022
91bd902
restore gas oracle
pharms-eth Apr 16, 2022
c8869dc
finish cleanup
pharms-eth Apr 16, 2022
7b64d5c
some cleanup per PR 515 comments
pharms-eth Apr 17, 2022
b411272
remove promise from carthage project
pharms-eth Apr 17, 2022
a1fface
update carthage project
pharms-eth Apr 17, 2022
b0b0179
renamed to remove Promise from syntax
pharms-eth Apr 17, 2022
63dda60
more promise renaming
pharms-eth Apr 17, 2022
a09ed12
Promis renaming
pharms-eth Apr 17, 2022
3f13dbb
Added mention of EIP-1559
mloit Apr 19, 2022
7424336
Added EIP-1559, EIP-2718, and EIP-2930 to the list of supported EIP's
mloit Apr 19, 2022
6bb47dd
added some basics for creating transactions with the new types
mloit Apr 19, 2022
f89cea8
typo fixes
mloit Apr 19, 2022
ff7ba8f
Merge pull request #530 from mloit/feature/document-1559
yaroslavyaroslav Apr 19, 2022
4b4ab1b
Merge pull request #523 from mloit/feature/transaction-metadata
yaroslavyaroslav Apr 19, 2022
add3342
Merge pull request #533 from skywinder/develop
yaroslavyaroslav Apr 19, 2022
6429bd4
Update Cocoapods version
yaroslavyaroslav Apr 19, 2022
d96ab6d
Merge pull request #534 from skywinder/master
yaroslavyaroslav Apr 19, 2022
f42f197
Merge branch 'develop' into remove-Promises
pharms-eth Apr 24, 2022
c4c5a7f
add backward compatibility support
pharms-eth Apr 24, 2022
d37ad4d
updated carthage
pharms-eth Apr 24, 2022
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
1 change: 0 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ github "attaswift/BigInt" ~> 5.3.0
github "attaswift/SipHash" ~> 1.2.2
github "daltoniam/Starscream" ~> 4.0.4
github "krzyzanowskim/CryptoSwift" ~> 1.4.2
github "mxcl/PromiseKit" ~> 6.16.2
3 changes: 1 addition & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
github "attaswift/BigInt" "v5.3.0"
github "attaswift/SipHash" "v1.2.2"
github "daltoniam/Starscream" "4.0.4"
github "krzyzanowskim/CryptoSwift" "1.4.2"
github "mxcl/PromiseKit" "6.16.2"
github "krzyzanowskim/CryptoSwift" "1.5.0"
20 changes: 13 additions & 7 deletions Documentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,41 @@ Here are quick references for essential features:

- [x] [EIP-155](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-155.md) (Replay attacks protection) *enforced!*

- [x] [EIP-165](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-165.md) (Standard Interface Detection, also known as ERC-165)

- [x] [EIP-681](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-681.md) (A standard way of representing various transactions, especially payment requests in Ethers and ERC-20 tokens as URLs)

- [x] [EIP-721](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-721.md) (A standard interface for non-fungible tokens, also known as deeds - ERC-721)

- [x] [EIP-165](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-165.md) (Standard Interface Detection, also known as ERC-165)
- [x] [EIP-721x](https://github.com/loomnetwork/erc721x) (An extension of ERC721 that adds support for multi-fungible tokens and batch transfers, while being fully backward-compatible, also known as ERC-721x)

- [x] [EIP-777](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-777.md) (New Advanced Token Standard, also known as ERC-777)

- [x] [EIP-820](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-820.md) (Pseudo-introspection Registry Contract, also known as ERC-820)

- [x] [EIP-888](https://github.com/ethereum/EIPs/issues/888) (MultiDimensional Token Standard, also known as ERC-888)

- [x] [EIP-1155](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-1155.md) (Multi Token Standard, also known as ERC-1155)

- [x] [EIP-1376](https://github.com/ethereum/EIPs/issues/1376) (Service-Friendly Token, also known as ERC-1376)

- [x] [EIP-1400](https://github.com/ethereum/EIPs/issues/1411) (Security Token Standard, also known as ERC-1400)

- [x] [EIP-1410](https://github.com/ethereum/EIPs/issues/1410) (Partially Fungible Token Standard, also known as ERC-1410)

- [x] [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) (Fee market change for ETH 1.0 chain)

- [x] [EIP-1594](https://github.com/ethereum/EIPs/issues/1594) (Core Security Token Standard, also known as ERC-1594)

- [x] [EIP-1633](https://github.com/ethereum/EIPs/issues/1634) (Re-Fungible Token, also known as ERC-1633)

- [x] [EIP-1643](https://github.com/ethereum/EIPs/issues/1643) (Document Management Standard, also known as ERC-1643)

- [x] [EIP-1644](https://github.com/ethereum/EIPs/issues/1644) (Controller Token Operation Standard, also known as ERC-1644)

- [x] [EIP-1633](https://github.com/ethereum/EIPs/issues/1634) (Re-Fungible Token, also known as ERC-1633)

- [x] [EIP-721x](https://github.com/loomnetwork/erc721x) (An extension of ERC721 that adds support for multi-fungible tokens and batch transfers, while being fully backward-compatible, also known as ERC-721x)

- [x] [EIP-1155](https://github.com/ethereum/EIPs/blob/develop/EIPS/eip-1155.md) (Multi Token Standard, also known as ERC-1155)
- [x] [EIP-2718](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md) (Typed Transaction Envelope)

- [x] [EIP-1376](https://github.com/ethereum/EIPs/issues/1376) (Service-Friendly Token, also known as ERC-1376)
- [x] [EIP-2930](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2930.md) (Optional access lists)

- [x] [ST-20](https://github.com/PolymathNetwork/polymath-core) - ST-20 token is an Ethereum-based token implemented on top of the ERC-20 protocol that adds the ability for tokens to control transfers based on specific rules

Expand Down
35 changes: 35 additions & 0 deletions Documentation/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- [Send ERC-20 Token](#send-erc-20-token)
- [Write Transaction and call smart contract method](#write-transaction-and-call-smart-contract-method)
- [Read Transaction to call smart contract method](#read-transaction-to-call-smart-contract-method)
- [Other Transaction Types (EIP-1559)](#other-transaction-types)
- [Send Transaction](#send-transaction)
- [Write](#write)
- [Read](#read)
Expand Down Expand Up @@ -355,6 +356,40 @@ let result = try! transaction.send(password: password)
let result = try! transaction.call()
```

##### Other Transaction Types

By default a `legacy` transaction will be created which is compatible across all chains, regardless of which fork.
To create one of the new transaction types introduced with the `london` fork you will need to set some additonal parameters
in the `TransactionOptions` object. Note you should only try to send one of tehse new types of transactions if you are on a chain
that supports them.

To send an EIP-2930 style transacton with an access list you need to set the transaction type, and the access list,
in addition what is shown in the examples above.
```swift
let accessList: [AccessListEntry] = [
AccessListEntry(
address: EthereumAddress("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae"),
storageKeys: [BigUInt(3), BigUInt(7)]
),
AccessListEntry(
address: EthereumAddress("0xbb9bc244d798123fde783fcc1c72d3bb8c189413"),
storageKeys: []
)
]

options.type = .eip2930
options.accessList = accessList
```

To send an EIP-1559 style transaction you set the transaction type, and the new gas parameters `maxFeePerGas` and `maxPriorityFeePerGas`
(you may also send an AccessList with an EIP-1559 transaction) When sending an EIP-1559 transaction, the older `gasPrice` parameter is ignored.
```swift
options.type = .eip1559
options.maxFeePerGas = .manual(...) // the maximum price per unit of gas, inclusive of baseFee and tip
options.maxPriorityFeePerGas = .manual(...) // the tip to be paid to the miner, per unit of gas
```
Note there is a new `Oracle` object available that can be used to assist with estimating the new gas fees

### Chain state

#### Get Block number
Expand Down
2 changes: 1 addition & 1 deletion Documentation/web3swift 2.0 Migration Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ let contract = web3.contract(Web3.Utils.erc20ABI, at: contractAddress, abiVersio
let userAddress = EthereumAddress("<address>")!
guard let readTX = contract?.read("balanceOf", parameters: [addressOfUser] as [AnyObject]) else {return}
readTX.transactionOptions.from = EthereumAddress("<address>")!
let tokenBalance = try readTX.callPromise().wait()
let tokenBalance = try readTX.callPromise()
guard let balance = tokenBalance["0"] as? BigUInt else {return}
```

Expand Down
9 changes: 0 additions & 9 deletions Package.resolved
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
"version": "1.4.2"
}
},
{
"package": "PromiseKit",
"repositoryURL": "https://github.com/mxcl/PromiseKit.git",
"state": {
"branch": null,
"revision": "3fd8c77ded8a4bbee548e3bd6c987ffe8c1e3574",
"version": "6.17.0"
}
},
{
"package": "Starscream",
"repositoryURL": "https://github.com/daltoniam/Starscream.git",
Expand Down
7 changes: 3 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.4
// swift-tools-version: 5.5.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -14,23 +14,22 @@ let excludeFiles: String = []
let package = Package(
name: "Web3swift",
platforms: [
.macOS(.v10_12), .iOS(.v11)
.macOS(.v10_15), .iOS(.v13)
],
products: [
.library(name: "web3swift", targets: ["web3swift"])
],

dependencies: [
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
.package(url: "https://github.com/mxcl/PromiseKit.git", from: "6.16.2"),
.package(url: "https://github.com/daltoniam/Starscream.git", from: "4.0.4"),
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.4.2")
],
targets: [
.target(name: "secp256k1"),
.target(
name: "web3swift",
dependencies: ["BigInt", "secp256k1", "PromiseKit", "Starscream", "CryptoSwift"],
dependencies: ["BigInt", "secp256k1", "Starscream", "CryptoSwift"],
exclude: excludeFiles,
resources: [
.copy("./Browser/browser.js"),
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
- [x] ✅**Literally following the standards** (BIP, EIP, etc):

- [x] **[BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) (HD Wallets), [BIP39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) (Seed phrases), [BIP44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) (Key generation prefixes)**
- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standart interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection)
- [x] **[EIP-20](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md)** (Standart interface for tokens - ERC-20), **[EIP-67](https://github.com/ethereum/EIPs/issues/67)** (Standard URI scheme), **[EIP-155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md)** (Replay attacks protection), **[EIP-2718](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2718.md)** (Typed Transaction Envelope), **[EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md)** (Gas Fee market change)
- [x] **And many others** *(For details about this EIP's look at [Documentation page](https://github.com/skywinder/web3swift/blob/master/Documentation/))*: EIP-681, EIP-721, EIP-165, EIP-777, EIP-820, EIP-888, EIP-1400, EIP-1410, EIP-1594, EIP-1643, EIP-1644, EIP-1633, EIP-721, EIP-1155, EIP-1376, ST-20

- [x] 🗜 **Batched requests** in concurrent mode
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 24 additions & 18 deletions Sources/web3swift/Browser/BrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ open class BrowserViewController: UIViewController {
}, for: "getRPCurl")

self.webView.bridge.register({ (parameters, completion) in
let allAccounts = web3.browserFunctions.getAccounts()
completion(.success(["accounts": allAccounts as Any]))
Task {
let allAccounts = await web3.browserFunctions.getAccounts()
completion(.success(["accounts": allAccounts as Any]))
}
}, for: "eth_getAccounts")

self.webView.bridge.register({ (parameters, completion) in
let coinbase = web3.browserFunctions.getCoinbase()
completion(.success(["coinbase": coinbase as Any]))
Task {
let coinbase = await web3.browserFunctions.getCoinbase()
completion(.success(["coinbase": coinbase as Any]))
}
}, for: "eth_coinbase")

self.webView.bridge.register({ (parameters, completion) in
Expand Down Expand Up @@ -97,21 +101,23 @@ open class BrowserViewController: UIViewController {
}, for: "eth_sign")

self.webView.bridge.register({ (parameters, completion) in
if parameters == nil {
completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
return
}
let transaction = parameters!["transaction"] as? [String: Any]
if transaction == nil {
completion(.failure(Bridge.JSError(code: 0, description: "Not enough parameters provided")))
return
}
let result = web3.browserFunctions.signTransaction(transaction!)
if result == nil {
completion(.failure(Bridge.JSError(code: 0, description: "Data is invalid")))
return
Task {
if parameters == nil {
completion(.failure(Bridge.JSError(code: 0, description: "No parameters provided")))
return
}
let transaction = parameters!["transaction"] as? [String: Any]
if transaction == nil {
completion(.failure(Bridge.JSError(code: 0, description: "Not enough parameters provided")))
return
}
let result = await web3.browserFunctions.signTransaction(transaction!)
if result == nil {
completion(.failure(Bridge.JSError(code: 0, description: "Data is invalid")))
return
}
completion(.success(["signedTransaction": result as Any]))
}
completion(.success(["signedTransaction": result as Any]))
}, for: "eth_signTransaction")
}
}
Expand Down
Loading