Skip to content

Commit f7db2ea

Browse files
committed
resolve conflicts
1 parent ad3d00d commit f7db2ea

File tree

4 files changed

+161
-141
lines changed

4 files changed

+161
-141
lines changed

Sources/web3swift/Promises/Promise+Web3+Eth+FeeHistory.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@
77
//
88

99
import Foundation
10-
import PromiseKit
1110
import BigInt
1211

1312
extension web3.Eth {
14-
func feeHistory(blockCount: BigUInt, block: String, percentiles:[Double]) throws -> Web3.Oracle.FeeHistory {
13+
func feeHistory(blockCount: BigUInt, block: String, percentiles:[Double]) async throws -> Web3.Oracle.FeeHistory {
1514
let request = JSONRPCRequestFabric.prepareRequest(.feeHistory, parameters: [blockCount.description.addHexPrefix(), block, percentiles])
16-
let rp = web3.dispatch(request)
17-
let queue = web3.requestDispatcher.queue
18-
return try rp.map(on: queue) { response in
19-
guard let value: Web3.Oracle.FeeHistory = response.getValue() else {
20-
if response.error != nil {
21-
throw Web3Error.nodeError(desc: response.error!.message)
22-
}
23-
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
15+
let response = try await web3.dispatch(request)
16+
17+
guard let value: Web3.Oracle.FeeHistory = response.getValue() else {
18+
if response.error != nil {
19+
throw Web3Error.nodeError(desc: response.error!.message)
2420
}
25-
return value
26-
}.wait()
21+
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
22+
}
23+
return value
2724
}
2825
}

Sources/web3swift/Promises/Promise+Web3+Eth+SendRawTransaction.swift

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,33 @@ import Foundation
88

99

1010
extension web3.Eth {
11-
public func sendRawTransactionPromise(_ transaction: Data) -> Promise<TransactionSendingResult> {
11+
public func sendRawTransactionPromise(_ transaction: Data) async throws -> TransactionSendingResult {
1212
guard let deserializedTX = EthereumTransaction(rawValue: transaction) else {
13-
let promise = Promise<TransactionSendingResult>.pending()
14-
promise.resolver.reject(Web3Error.processingError(desc: "Serialized TX is invalid"))
15-
return promise.promise
13+
throw Web3Error.processingError(desc: "Serialized TX is invalid")
1614
}
1715
return try await sendRawTransactionPromise(deserializedTX)
1816
}
1917

20-
public func sendRawTransactionPromise(_ transaction: EthereumTransaction) -> Promise<TransactionSendingResult>{
21-
let queue = web3.requestDispatcher.queue
22-
do {
23-
guard let request = EthereumTransaction.createRawTransaction(transaction: transaction) else {
24-
throw Web3Error.processingError(desc: "Transaction is invalid")
25-
}
26-
let rp = web3.dispatch(request)
27-
return rp.map(on: queue) { response in
28-
guard let value: String = response.getValue() else {
29-
if response.error != nil {
30-
throw Web3Error.nodeError(desc: response.error!.message)
31-
}
32-
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
33-
}
34-
let result = TransactionSendingResult(transaction: transaction, hash: value)
35-
for hook in self.web3.postSubmissionHooks {
36-
hook.queue.async {
37-
hook.function(result)
38-
}
39-
}
40-
return result
18+
public func sendRawTransactionPromise(_ transaction: EthereumTransaction) async throws -> TransactionSendingResult {
19+
20+
guard let request = EthereumTransaction.createRawTransaction(transaction: transaction) else {
21+
throw Web3Error.processingError(desc: "Transaction is invalid")
22+
}
23+
let response = try await web3.dispatch(request)
24+
25+
26+
guard let value: String = response.getValue() else {
27+
if response.error != nil {
28+
throw Web3Error.nodeError(desc: response.error!.message)
4129
}
4230
throw Web3Error.nodeError(desc: "Invalid value from Ethereum node")
4331
}
4432
let result = TransactionSendingResult(transaction: transaction, hash: value)
4533
for hook in self.web3.postSubmissionHooks {
46-
Task {
47-
hook.function(result)
48-
}
34+
hook.function(result)
4935
}
5036
return result
5137

38+
5239
}
5340
}

Sources/web3swift/Web3/Web3+GasOracle.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,23 @@ extension Web3 {
8383
}
8484
}
8585

86-
private func suggestGasValues() throws -> FeeHistory {
86+
private func suggestGasValues() async throws -> FeeHistory {
8787
// This is some kind of cache.
8888
// It stores about 9 seconds, than it rewrites it with newer data.
8989
// TODO: Disabled until 3.0 version, coz `distance` available from iOS 13.
9090
// guard feeHistory == nil, forceDropCache, feeHistory!.timestamp.distance(to: Date()) > cacheTimeout else { return feeHistory! }
9191

92-
return try eth.feeHistory(blockCount: blockCount, block: block.hexValue, percentiles: percentiles)
92+
return try await eth.feeHistory(blockCount: blockCount, block: block.hexValue, percentiles: percentiles)
9393
}
9494

9595
/// Suggesting tip values
9696
/// - Returns: `[percentile_1, percentile_2, percentile_3, ...].count == self.percentile.count`
9797
/// by default there's 3 percentile.
98-
private func suggestTipValue() throws -> [BigUInt] {
98+
private func suggestTipValue() async throws -> [BigUInt] {
9999
var rearrengedArray: [[BigUInt]] = []
100100

101101
/// reaarange `[[min, middle, max]]` to `[[min], [middle], [max]]`
102-
try suggestGasValues().reward
102+
try await suggestGasValues().reward
103103
.forEach { percentiles in
104104
percentiles.enumerated().forEach { (index, percentile) in
105105
/// if `rearrengedArray` have not that enough items
@@ -116,23 +116,25 @@ extension Web3 {
116116
return soft(twoDimentsion: rearrengedArray)
117117
}
118118

119-
private func suggestBaseFee() throws -> [BigUInt] {
120-
self.feeHistory = try suggestGasValues()
119+
private func suggestBaseFee() async throws -> [BigUInt] {
120+
self.feeHistory = try await suggestGasValues()
121121
return calculatePercentiles(for: feeHistory!.baseFeePerGas)
122122
}
123123

124-
private func suggestGasFeeLegacy() throws -> [BigUInt] {
124+
private func suggestGasFeeLegacy() async throws -> [BigUInt] {
125125
var latestBlockNumber: BigUInt = 0
126126
switch block {
127-
case .latest: latestBlockNumber = try eth.getBlockNumber()
127+
case .latest: latestBlockNumber = try await eth.getBlockNumber()
128128
case let .exact(number): latestBlockNumber = number
129129
}
130130

131131
guard latestBlockNumber != 0 else { return [] }
132132

133133
// TODO: Make me work with cache
134134
let lastNthBlockGasPrice = try (latestBlockNumber - blockCount ... latestBlockNumber)
135-
.map { try eth.getBlockByNumber($0, fullTransactions: true) }
135+
.map {
136+
try eth.getBlockByNumber($0, fullTransactions: true)
137+
}
136138
.flatMap { b -> [EthereumTransaction] in
137139
b.transactions.compactMap { t -> EthereumTransaction? in
138140
guard case let .transaction(transaction) = t else { return nil }

0 commit comments

Comments
 (0)