Skip to content

Commit 33f4f76

Browse files
Fixes by PR review
1 parent 8d64dc8 commit 33f4f76

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/web3swift/Web3/Web3+GasOracle.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ extension Web3 {
3131
/// Oracle initializer
3232
/// - Parameters:
3333
/// - provider: Web3 Ethereum provider
34-
/// - blocksCount: Count of block to calculate statistics
35-
/// - transactionsCount: Count of transacrtions to filter block for tip calculation
34+
/// - blockCount: Count of block to calculate statistics
35+
/// - transactionCount: Count of transaction to filter block for tip calculation
3636
public init(_ provider: web3, blockCount: BigUInt = 20, transactionCount: BigUInt = 50) {
3737
self.web3Provider = provider
3838
self.blockCount = blockCount
@@ -44,14 +44,15 @@ extension Web3 {
4444
return Web3.calcBaseFee(block)
4545
}
4646

47-
private func calculateStatistic(_ data: [BigUInt], _ statistic: Statistic) throws -> BigUInt {
47+
private func calculateStatistic(for statistic: Statistic, data: [BigUInt]) throws -> BigUInt {
4848
let noAnomalyArray = data.cropAnomalyValues()
4949

5050
// FIXME: Set appropriate error thrown.
5151
guard let unwrappedArray = noAnomalyArray, !unwrappedArray.isEmpty else { throw Web3Error.unknownError }
5252

5353
switch statistic {
5454
// Force unwrapping is ok, since array checked for epmtiness above
55+
// swiftlint:disable force_unwrapping
5556
case .minimum: return unwrappedArray.min()!
5657
case .mean: return unwrappedArray.mean()!
5758
case .median: return unwrappedArray.median()!
@@ -60,6 +61,7 @@ extension Web3 {
6061
// because in the maximum statistic we should guarantee that transaction would be included in it.
6162
return max(calcBaseFee(for: latestBlock), unwrappedArray.max()!)
6263
}
64+
// swiftlint:enable force_unwrapping
6365
}
6466

6567
private func suggestTipValue(_ statistic: Statistic) throws -> BigUInt {
@@ -83,7 +85,7 @@ extension Web3 {
8385
// TODO: Add filter for transaction types
8486
.map { $0.maxPriorityFeePerGas }
8587

86-
return try calculateStatistic(transactionsTips, statistic)
88+
return try calculateStatistic(for: statistic, data: transactionsTips)
8789
}
8890

8991
private func suggestBaseFee(_ statistic: Statistic) throws -> BigUInt {
@@ -97,7 +99,7 @@ extension Web3 {
9799
.filter { !$0.transactions.isEmpty }
98100
.map { $0.baseFeePerGas }
99101

100-
return try calculateStatistic(lastNthBlocksBaseFees, statistic)
102+
return try calculateStatistic(for: statistic, data: lastNthBlocksBaseFees)
101103
}
102104

103105
private func suggestGasFeeLegacy(_ statistic: Statistic) throws -> BigUInt {
@@ -116,7 +118,7 @@ extension Web3 {
116118
}
117119
.map { $0.gasPrice }
118120

119-
return try calculateStatistic(lastNthBlockGasPrice, statistic)
121+
return try calculateStatistic(for: statistic, data: lastNthBlockGasPrice)
120122
}
121123
}
122124
}

0 commit comments

Comments
 (0)