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 1 commit
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
Prev Previous commit
Next Next commit
propagate async changes
  • Loading branch information
pharms-eth committed Apr 9, 2022
commit d712c42a4448bc8ea2f8c53f01fec52e91d20cd4
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.

Empty file modified Package.resolved
100755 → 100644
Empty file.
43 changes: 0 additions & 43 deletions Sources/web3swift/Promises/Promise+HttpProvider.swift

This file was deleted.

32 changes: 11 additions & 21 deletions Sources/web3swift/Promises/Promise+Web3+Eth+Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,18 @@ import Foundation

extension web3.Eth {

public func callPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?) -> Promise<Data>{
let queue = web3.requestDispatcher.queue
do {
guard let request = EthereumTransaction.createRequest(method: .call, transaction: transaction, transactionOptions: transactionOptions) else {
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let rp = web3.dispatch(request)
return rp.map(on: queue) { response in
guard let value: Data = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
} catch {
let returnPromise = Promise<Data>.pending()
queue.async {
returnPromise.resolver.reject(error)
public func callPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?) async throws -> Data {
guard let request = EthereumTransaction.createRequest(method: .call, transaction: transaction, transactionOptions: transactionOptions) else {
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let response = try await web3.dispatch(request)

guard let value: Data = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return returnPromise.promise
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
}
63 changes: 28 additions & 35 deletions Sources/web3swift/Promises/Promise+Web3+Eth+EstimateGas.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,36 @@ import BigInt

extension web3.Eth {

public func estimateGasPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?) -> Promise<BigUInt>{
let queue = web3.requestDispatcher.queue
do {
guard let request = EthereumTransaction.createRequest(method: .estimateGas, transaction: transaction, transactionOptions: transactionOptions) else {
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let rp = web3.dispatch(request)
return rp.map(on: queue) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}

if let policy = transactionOptions?.gasLimit {
switch policy {
case .automatic:
return value
case .limited(let limitValue):
return limitValue < value ? limitValue: value
case .manual(let exactValue):
return exactValue
case .withMargin:
// MARK: - update value according margin
return value
}
} else {
return value
}
public func estimateGasPromise(_ transaction: EthereumTransaction, transactionOptions: TransactionOptions?) async throws -> BigUInt {

guard let request = EthereumTransaction.createRequest(method: .estimateGas, transaction: transaction, transactionOptions: transactionOptions) else {
throw Web3Error.processingError(desc: "Transaction is invalid")
}
let response = try await web3.dispatch(request)

guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
} catch {
let returnPromise = Promise<BigUInt>.pending()
queue.async {
returnPromise.resolver.reject(error)
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}

if let policy = transactionOptions?.gasLimit {
switch policy {
case .automatic:
return value
case .limited(let limitValue):
return limitValue < value ? limitValue: value
case .manual(let exactValue):
return exactValue
case .withMargin:
// MARK: - update value according margin
return value
}
return returnPromise.promise
} else {
return value
}


}
}
23 changes: 11 additions & 12 deletions Sources/web3swift/Promises/Promise+Web3+Eth+GetBalance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ import Foundation
import BigInt

extension web3.Eth {
public func getBalancePromise(address: EthereumAddress, onBlock: String = "latest") -> Promise<BigUInt> {
public func getBalancePromise(address: EthereumAddress, onBlock: String = "latest") async throws -> BigUInt {
let addr = address.address
return getBalancePromise(address: addr, onBlock: onBlock)
return try await getBalancePromise(address: addr, onBlock: onBlock)
}
public func getBalancePromise(address: String, onBlock: String = "latest") -> Promise<BigUInt> {
public func getBalancePromise(address: String, onBlock: String = "latest") async throws -> BigUInt {
let request = JSONRPCRequestFabric.prepareRequest(.getBalance, parameters: [address.lowercased(), onBlock])
let rp = web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
let response = try await web3.dispatch(request)

guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value

}
}
23 changes: 11 additions & 12 deletions Sources/web3swift/Promises/Promise+Web3+Eth+GetBlockByHash.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ import BigInt


extension web3.Eth {
public func getBlockByHashPromise(_ hash: Data, fullTransactions: Bool = false) -> Promise<Block> {
public func getBlockByHashPromise(_ hash: Data, fullTransactions: Bool = false) async throws -> Block {
let hashString = hash.toHexString().addHexPrefix()
return getBlockByHashPromise(hashString, fullTransactions: fullTransactions)
return try await getBlockByHashPromise(hashString, fullTransactions: fullTransactions)
}

public func getBlockByHashPromise(_ hash: String, fullTransactions: Bool = false) -> Promise<Block> {
public func getBlockByHashPromise(_ hash: String, fullTransactions: Bool = false) async throws -> Block {
let request = JSONRPCRequestFabric.prepareRequest(.getBlockByHash, parameters: [hash, fullTransactions])
let rp = web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
let response = try await web3.dispatch(request)

guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value

}
}
27 changes: 13 additions & 14 deletions Sources/web3swift/Promises/Promise+Web3+Eth+GetBlockByNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ import BigInt


extension web3.Eth {
public func getBlockByNumberPromise(_ number: UInt64, fullTransactions: Bool = false) -> Promise<Block> {
public func getBlockByNumberPromise(_ number: UInt64, fullTransactions: Bool = false) async throws -> Block {
let block = String(number, radix: 16).addHexPrefix()
return getBlockByNumberPromise(block, fullTransactions: fullTransactions)
return try await getBlockByNumberPromise(block, fullTransactions: fullTransactions)
}

public func getBlockByNumberPromise(_ number: BigUInt, fullTransactions: Bool = false) -> Promise<Block> {
public func getBlockByNumberPromise(_ number: BigUInt, fullTransactions: Bool = false) async throws -> Block {
let block = String(number, radix: 16).addHexPrefix()
return getBlockByNumberPromise(block, fullTransactions: fullTransactions)
return try await getBlockByNumberPromise(block, fullTransactions: fullTransactions)
}

public func getBlockByNumberPromise(_ number: String, fullTransactions: Bool = false) -> Promise<Block> {
public func getBlockByNumberPromise(_ number: String, fullTransactions: Bool = false) async throws -> Block {
let request = JSONRPCRequestFabric.prepareRequest(.getBlockByNumber, parameters: [number, fullTransactions])
let rp = web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
let response = try await web3.dispatch(request)

guard let value: Block = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value

}
}
23 changes: 11 additions & 12 deletions Sources/web3swift/Promises/Promise+Web3+Eth+GetCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@ import Foundation
import BigInt

extension web3.Eth {
public func getCodePromise(address: EthereumAddress, onBlock: String = "latest") -> Promise<String> {
public func getCodePromise(address: EthereumAddress, onBlock: String = "latest") async throws -> String {
let addr = address.address
return getCodePromise(address: addr, onBlock: onBlock)
return try await getCodePromise(address: addr, onBlock: onBlock)
}
public func getCodePromise(address: String, onBlock: String = "latest") -> Promise<String> {
public func getCodePromise(address: String, onBlock: String = "latest") async throws -> String {
let request = JSONRPCRequestFabric.prepareRequest(.getCode, parameters: [address.lowercased(), onBlock])
let rp = web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: String = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
let response = try await web3.dispatch(request)

guard let value: String = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ import BigInt


extension web3.Eth {
public func getTransactionCountPromise(address: EthereumAddress, onBlock: String = "latest") -> Promise<BigUInt> {
public func getTransactionCountPromise(address: EthereumAddress, onBlock: String = "latest") async throws -> BigUInt {
let addr = address.address
return getTransactionCountPromise(address: addr, onBlock: onBlock)
return try await getTransactionCountPromise(address: addr, onBlock: onBlock)
}

public func getTransactionCountPromise(address: String, onBlock: String = "latest") -> Promise<BigUInt> {
public func getTransactionCountPromise(address: String, onBlock: String = "latest") async throws -> BigUInt {
let request = JSONRPCRequestFabric.prepareRequest(.getTransactionCount, parameters: [address.lowercased(), onBlock])
let rp = web3.dispatch(request)
let response = try await web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")

guard let value: BigUInt = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ import BigInt


extension web3.Eth {
public func getTransactionDetailsPromise(_ txhash: Data) -> Promise<TransactionDetails> {
public func getTransactionDetailsPromise(_ txhash: Data) async throws -> TransactionDetails {
let hashString = txhash.toHexString().addHexPrefix()
return self.getTransactionDetailsPromise(hashString)
return try await self.getTransactionDetailsPromise(hashString)
}

public func getTransactionDetailsPromise(_ txhash: String) -> Promise<TransactionDetails> {
public func getTransactionDetailsPromise(_ txhash: String) async throws -> TransactionDetails {
let request = JSONRPCRequestFabric.prepareRequest(.getTransactionByHash, parameters: [txhash])
let rp = web3.dispatch(request)
let queue = web3.requestDispatcher.queue
return rp.map(on: queue) { response in
guard let value: TransactionDetails = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
let response = try await web3.dispatch(request)

guard let value: TransactionDetails = response.getValue() else {
if response.error != nil {
throw Web3Error.nodeError(desc: response.error!.message)
}
return value
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
}
return value

}
}
Loading