Skip to content

Commit 56e7eec

Browse files
There's a follow Oracle methods available for a user:
- `Oracle(_ provider: web3, blocksNumber: BigUInt = 20, transactionsNumber: BigUInt = 50)` to init object instance. - `predictBaseFee(_ statistic: Statistic) -> BigUInt?` to predict base fee according to given statistic. - `predictTip(_ statistic: Statistic) -> BigUInt?` to predict tip fee according to given statistic. - `predictBothFees(baseFee: Statistic, tip: Statistic) -> (BigUInt, BigUInt)?` to predict both fees according to given statistic All of the methods above returns nil if fails to predict. There's follow modes (statistics) are available yet: - `Statistic.minimum` — comes with minimum valid values - `Statistic.mean` — comes with mean valid values - `Statistic.median` — comes with median valid values - `Statistic.maximum` - comes with maximum valid values
1 parent 03f55e2 commit 56e7eec

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Sources/web3swift/Web3/Web3+GasOracle.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ extension Web3 {
3232
/// - Parameters:
3333
/// - provider: Web3 Ethereum provider
3434
/// - blocksNumber: Number of block to caltulate statistics
35+
/// - transactionsNumber: Number of transacrtions to filter block for tip calculation
3536
public init(_ provider: web3, blocksNumber: BigUInt = 20, transactionsNumber: BigUInt = 50) {
36-
web3Provider = provider
37+
self.web3Provider = provider
3738
self.blocksNumber = blocksNumber
3839
self.transactionsNumber = transactionsNumber
3940
}
@@ -55,18 +56,18 @@ extension Web3 {
5556
case .mean: return noAnomalyArray.mean()!
5657
case .median: return noAnomalyArray.median()!
5758
case .maximum:
58-
// Checking that suggestedBaseFee are not lower than next
59-
// because in tne maximum statistic we should guarantee that transaction would pass in the next block
59+
// Checking that suggestedBaseFee are not lower than will be in the next block
60+
// because in tne maximum statistic we should guarantee that transaction would be included in it.
6061
return max(calcBaseFee(for: latestBlock), noAnomalyArray.max()!)
6162
}
6263
}
6364

6465
private func suggestTipValue(_ statistic: Statistic) throws -> BigUInt {
6566
let latestBlockNumber = try eth.getBlockNumber()
6667

67-
// TODO: Make me work with cache
6868
var block: Block
6969

70+
// TODO: Make me work with cache
7071
repeat {
7172
block = try eth.getBlockByNumber(latestBlockNumber, fullTransactions: true)
7273
} while block.transactions.count < transactionsNumber
@@ -135,7 +136,7 @@ public extension Web3.Oracle {
135136
/// - Parameters:
136137
/// - baseFee: Statistic to apply for baseFee
137138
/// - tip: Statistic to apply for tip
138-
/// - Returns: Touple where [0] — base fee, [1] — tip, nil if failed to predict
139+
/// - Returns: Touple where [0] — base fee, [1] — tip, nil if failed to predict
139140
func predictBothFees(baseFee: Statistic, tip: Statistic) -> (BigUInt, BigUInt)? {
140141
guard let baseFee = try? suggestBaseFee(baseFee) else { return nil }
141142
guard let tip = try? suggestTipValue(tip) else { return nil }

0 commit comments

Comments
 (0)