@@ -99,6 +99,25 @@ extension Web3 {
99
99
100
100
return try calculateStatistic ( lastNthBlocksBaseFees, statistic)
101
101
}
102
+
103
+ private func suggestGasFeeLegacy( _ statistic: Statistic ) throws -> BigUInt {
104
+ let latestBlockNumber = try eth. getBlockNumber ( )
105
+
106
+ // Assigning last block to object var to predict baseFee of the next block
107
+ latestBlock = try eth. getBlockByNumber ( latestBlockNumber)
108
+ // TODO: Make me work with cache
109
+ let lastNthBlockGasPrice = try ( latestBlockNumber - blocksNumber ... latestBlockNumber)
110
+ . map { try eth. getBlockByNumber ( $0, fullTransactions: true ) }
111
+ . flatMap { b -> [ EthereumTransaction ] in
112
+ b. transactions. compactMap { t -> EthereumTransaction ? in
113
+ guard case let . transaction( transaction) = t else { return nil }
114
+ return transaction
115
+ }
116
+ }
117
+ . map { $0. gasPrice }
118
+
119
+ return try calculateStatistic ( lastNthBlockGasPrice, statistic)
120
+ }
102
121
}
103
122
}
104
123
@@ -143,6 +162,15 @@ public extension Web3.Oracle {
143
162
144
163
return ( baseFee, tip)
145
164
}
165
+
166
+ // MARK: - Legacy GasPrice
167
+ /// Method to get legacy gas price
168
+ /// - Parameter statistic: Statistic to apply for gas price
169
+ /// - Returns: Suggested gas price amount according to statistic, nil if failed to predict
170
+ func predictGasPriceLegacy( _ statistic: Statistic ) -> BigUInt ? {
171
+ guard let value = try ? suggestGasFeeLegacy ( statistic) else { return nil }
172
+ return value
173
+ }
146
174
}
147
175
148
176
public extension Web3 . Oracle {
0 commit comments