@@ -31,8 +31,8 @@ extension Web3 {
31
31
/// Oracle initializer
32
32
/// - Parameters:
33
33
/// - 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
36
36
public init ( _ provider: web3 , blockCount: BigUInt = 20 , transactionCount: BigUInt = 50 ) {
37
37
self . web3Provider = provider
38
38
self . blockCount = blockCount
@@ -44,14 +44,15 @@ extension Web3 {
44
44
return Web3 . calcBaseFee ( block)
45
45
}
46
46
47
- private func calculateStatistic( _ data : [ BigUInt ] , _ statistic : Statistic ) throws -> BigUInt {
47
+ private func calculateStatistic( for statistic : Statistic , data : [ BigUInt ] ) throws -> BigUInt {
48
48
let noAnomalyArray = data. cropAnomalyValues ( )
49
49
50
50
// FIXME: Set appropriate error thrown.
51
51
guard let unwrappedArray = noAnomalyArray, !unwrappedArray. isEmpty else { throw Web3Error . unknownError }
52
52
53
53
switch statistic {
54
54
// Force unwrapping is ok, since array checked for epmtiness above
55
+ // swiftlint:disable force_unwrapping
55
56
case . minimum: return unwrappedArray. min ( ) !
56
57
case . mean: return unwrappedArray. mean ( ) !
57
58
case . median: return unwrappedArray. median ( ) !
@@ -60,6 +61,7 @@ extension Web3 {
60
61
// because in the maximum statistic we should guarantee that transaction would be included in it.
61
62
return max ( calcBaseFee ( for: latestBlock) , unwrappedArray. max ( ) !)
62
63
}
64
+ // swiftlint:enable force_unwrapping
63
65
}
64
66
65
67
private func suggestTipValue( _ statistic: Statistic ) throws -> BigUInt {
@@ -83,7 +85,7 @@ extension Web3 {
83
85
// TODO: Add filter for transaction types
84
86
. map { $0. maxPriorityFeePerGas }
85
87
86
- return try calculateStatistic ( transactionsTips , statistic)
88
+ return try calculateStatistic ( for : statistic, data : transactionsTips )
87
89
}
88
90
89
91
private func suggestBaseFee( _ statistic: Statistic ) throws -> BigUInt {
@@ -97,7 +99,7 @@ extension Web3 {
97
99
. filter { !$0. transactions. isEmpty }
98
100
. map { $0. baseFeePerGas }
99
101
100
- return try calculateStatistic ( lastNthBlocksBaseFees , statistic)
102
+ return try calculateStatistic ( for : statistic, data : lastNthBlocksBaseFees )
101
103
}
102
104
103
105
private func suggestGasFeeLegacy( _ statistic: Statistic ) throws -> BigUInt {
@@ -116,7 +118,7 @@ extension Web3 {
116
118
}
117
119
. map { $0. gasPrice }
118
120
119
- return try calculateStatistic ( lastNthBlockGasPrice , statistic)
121
+ return try calculateStatistic ( for : statistic, data : lastNthBlockGasPrice )
120
122
}
121
123
}
122
124
}
0 commit comments