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 24 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
5 changes: 0 additions & 5 deletions Cartfile.resolved

This file was deleted.

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(.v12), .iOS(.v15)
pharms-eth marked this conversation as resolved.
Show resolved Hide resolved
],
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

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

47 changes: 24 additions & 23 deletions Sources/web3swift/HookedFunctions/Web3+BrowserFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import BigInt

extension web3.BrowserFunctions {

public func getAccounts() -> [String]? {
public func getAccounts() async -> [String]? {
do {
let accounts = try self.web3.eth.getAccounts()
let accounts = try await self.web3.eth.getAccounts()
return accounts.compactMap({$0.address})
} catch {
return [String]()
}
}

public func getCoinbase() -> String? {
guard let addresses = self.getAccounts() else {return nil}
public func getCoinbase() async -> String? {
guard let addresses = await self.getAccounts() else {return nil}
guard addresses.count > 0 else {return nil}
return addresses[0]
}
Expand Down Expand Up @@ -69,7 +69,7 @@ extension web3.BrowserFunctions {
return Web3.Utils.publicToAddressString(publicKey)
}

public func sendTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> [String: Any]? {
public func sendTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") async -> [String: Any]? {
do {
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
Expand All @@ -80,20 +80,20 @@ extension web3.BrowserFunctions {
transactionOptions.value = options.value ?? 0
transactionOptions.gasLimit = options.gasLimit ?? .automatic
transactionOptions.gasPrice = options.gasPrice ?? .automatic
return self.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
return await self.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
} catch { return nil }
}

public func sendTransaction(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") -> [String: Any]? {
public func sendTransaction(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") async -> [String: Any]? {
do {
let result = try self.web3.eth.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
let result = try await self.web3.eth.sendTransaction(transaction, transactionOptions: transactionOptions, password: password)
return ["txhash": result.hash]
} catch {
return nil
}
}

public func estimateGas(_ transactionJSON: [String: Any]) -> BigUInt? {
public func estimateGas(_ transactionJSON: [String: Any]) async -> BigUInt? {
do {
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
Expand All @@ -104,40 +104,41 @@ extension web3.BrowserFunctions {
transactionOptions.value = options.value ?? 0
transactionOptions.gasLimit = .automatic
transactionOptions.gasPrice = options.gasPrice ?? .automatic
return self.estimateGas(transaction, transactionOptions: transactionOptions)
return await self.estimateGas(transaction, transactionOptions: transactionOptions)
} catch { return nil }
}

public func estimateGas(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions) -> BigUInt? {
public func estimateGas(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions) async -> BigUInt? {
do {
let result = try self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
let result = try await self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
return result
} catch {
return nil
}
}

public func prepareTxForApproval(_ transactionJSON: [String: Any]) -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
public func prepareTxForApproval(_ transactionJSON: [String: Any]) async -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
do {
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
let options: TransactionOptions = try JSONDecoder().decode(TransactionOptions.self, from: jsonData)
return try self.prepareTxForApproval(transaction, options: options)
return try await self.prepareTxForApproval(transaction, options: options)
} catch {
return (nil, nil)
}
}

public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: TransactionOptions) throws -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
public func prepareTxForApproval(_ trans: EthereumTransaction, options opts: TransactionOptions) async throws -> (transaction: EthereumTransaction?, options: TransactionOptions?) {
do {
var transaction = trans
var options = opts
guard let _ = options.from else {return (nil, nil)}
let gasPrice = try self.web3.eth.getGasPrice()
let gasPrice = try await self.web3.eth.getGasPrice()
transaction.parameters.gasPrice = gasPrice
options.gasPrice = .manual(gasPrice)
guard let gasEstimate = self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
guard let gasEstimate = await self.estimateGas(transaction, transactionOptions: options) else {return (nil, nil)}
transaction.parameters.gasLimit = gasEstimate

options.gasLimit = .limited(gasEstimate)
print(transaction)
return (transaction, options)
Expand All @@ -146,7 +147,7 @@ extension web3.BrowserFunctions {
}
}

public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") -> String? {
public func signTransaction(_ transactionJSON: [String: Any], password: String = "web3swift") async -> String? {
do {
let jsonData: Data = try JSONSerialization.data(withJSONObject: transactionJSON, options: [])
let transaction: EthereumTransaction = try JSONDecoder().decode(EthereumTransaction.self, from: jsonData)
Expand All @@ -162,11 +163,11 @@ extension web3.BrowserFunctions {
} else {
transactionOptions.nonce = .pending
}
return self.signTransaction(transaction, transactionOptions: transactionOptions, password: password)
return await self.signTransaction(transaction, transactionOptions: transactionOptions, password: password)
} catch { return nil }
}

public func signTransaction(_ trans: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") -> String? {
public func signTransaction(_ trans: EthereumTransaction, transactionOptions: TransactionOptions, password: String = "web3swift") async -> String? {
do {
var transaction = trans
guard let from = transactionOptions.from else {return nil}
Expand All @@ -178,23 +179,23 @@ extension web3.BrowserFunctions {
case .manual(let gasPrice):
transaction.parameters.gasPrice = gasPrice
default:
let gasPrice = try self.web3.eth.getGasPrice()
let gasPrice = try await self.web3.eth.getGasPrice()
transaction.parameters.gasPrice = gasPrice
}

switch gasLimitPolicy {
case .manual(let gasLimit):
transaction.parameters.gasLimit = gasLimit
default:
let gasLimit = try self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
let gasLimit = try await self.web3.eth.estimateGas(transaction, transactionOptions: transactionOptions)
transaction.parameters.gasLimit = gasLimit
}

switch noncePolicy {
case .manual(let nonce):
transaction.nonce = nonce
default:
let nonce = try self.web3.eth.getTransactionCount(address: from, onBlock: "pending")
let nonce = try await self.web3.eth.getTransactionCount(address: from, onBlock: "pending")
transaction.nonce = nonce
}

Expand Down
138 changes: 0 additions & 138 deletions Sources/web3swift/Promises/Promise+Batching.swift

This file was deleted.

Loading