@@ -131,11 +131,26 @@ extension Web3 {
131
131
guard latestBlockNumber != 0 else { return [ ] }
132
132
133
133
// TODO: Make me work with cache
134
- let lastNthBlockGasPrice = try ( latestBlockNumber - blockCount ... latestBlockNumber)
135
- . map {
136
- try eth. getBlockByNumber ( $0, fullTransactions: true )
134
+ let blocks = try await withThrowingTaskGroup ( of: Block . self, returning: [ Block ] . self) { group in
135
+
136
+ ( latestBlockNumber - blockCount ... latestBlockNumber)
137
+ . forEach { transaction in
138
+ group. addTask {
139
+ try await self . eth. getBlockByNumber ( transaction, fullTransactions: true )
140
+ }
141
+ }
142
+
143
+
144
+ var collected = [ Block] ( )
145
+
146
+ for try await value in group {
147
+ collected. append ( value)
137
148
}
138
- . flatMap { b -> [ EthereumTransaction ] in
149
+
150
+ return collected
151
+ }
152
+
153
+ let lastNthBlockGasPrice = blocks. flatMap { b -> [ EthereumTransaction ] in
139
154
b. transactions. compactMap { t -> EthereumTransaction ? in
140
155
guard case let . transaction( transaction) = t else { return nil }
141
156
return transaction
@@ -154,8 +169,8 @@ public extension Web3.Oracle {
154
169
///
155
170
/// - Returns: `[percentile_1, percentile_2, percentile_3, ...].count == self.percentile.count`
156
171
/// empty array if failed to predict. By default there's 3 percentile.
157
- var baseFeePercentiles : [ BigUInt ] {
158
- guard let value = try ? suggestBaseFee ( ) else { return [ ] }
172
+ func baseFeePercentiles( ) async -> [ BigUInt ] {
173
+ guard let value = try ? await suggestBaseFee ( ) else { return [ ] }
159
174
return value
160
175
}
161
176
@@ -164,8 +179,8 @@ public extension Web3.Oracle {
164
179
///
165
180
/// - Returns: `[percentile_1, percentile_2, percentile_3, ...].count == self.percentile.count`
166
181
/// empty array if failed to predict. By default there's 3 percentile.
167
- var tipFeePercentiles : [ BigUInt ] {
168
- guard let value = try ? suggestTipValue ( ) else { return [ ] }
182
+ func tipFeePercentiles( ) async -> [ BigUInt ] {
183
+ guard let value = try ? await suggestTipValue ( ) else { return [ ] }
169
184
return value
170
185
}
171
186
@@ -174,13 +189,13 @@ public extension Web3.Oracle {
174
189
///
175
190
/// - Returns: `[percentile_1, percentile_2, percentile_3, ...].count == self.percentile.count`
176
191
/// nil if failed to predict. By default there's 3 percentile.
177
- var bothFeesPercentiles : ( baseFee: [ BigUInt ] , tip: [ BigUInt ] ) ? {
192
+ func bothFeesPercentiles( ) async -> ( baseFee: [ BigUInt ] , tip: [ BigUInt ] ) ? {
178
193
var baseFeeArr : [ BigUInt ] = [ ]
179
194
var tipArr : [ BigUInt ] = [ ]
180
- if let baseFee = try ? suggestBaseFee ( ) {
195
+ if let baseFee = try ? await suggestBaseFee ( ) {
181
196
baseFeeArr = baseFee
182
197
}
183
- if let tip = try ? suggestTipValue ( ) {
198
+ if let tip = try ? await suggestTipValue ( ) {
184
199
tipArr = tip
185
200
}
186
201
return ( baseFee: baseFeeArr, tip: tipArr)
@@ -191,8 +206,8 @@ public extension Web3.Oracle {
191
206
///
192
207
/// - Returns: `[percentile_1, percentile_2, percentile_3, ...].count == self.percentile.count`
193
208
/// empty array if failed to predict. By default there's 3 percentile.
194
- var gasPriceLegacyPercentiles : [ BigUInt ] {
195
- guard let value = try ? suggestGasFeeLegacy ( ) else { return [ ] }
209
+ func gasPriceLegacyPercentiles( ) async -> [ BigUInt ] {
210
+ guard let value = try ? await suggestGasFeeLegacy ( ) else { return [ ] }
196
211
return value
197
212
}
198
213
}
0 commit comments