@@ -188,27 +188,6 @@ public struct CodableTransaction {
188
188
return self . envelope. encode ( for: type)
189
189
}
190
190
191
- public mutating func resolve( provider: Web3Provider ) async throws {
192
- // FIXME: Delete force try
193
- self . gasLimit = try await self . gasLimitPolicy. resolve ( provider: provider, transaction: self )
194
-
195
- if from != nil || sender != nil {
196
- self . nonce = try await self . resolveNonce ( provider: provider)
197
- }
198
- if case . eip1559 = type {
199
- self . maxFeePerGas = try await self . maxFeePerGasPolicy. resolve ( provider: provider)
200
- self . maxPriorityFeePerGas = try await self . maxPriorityFeePerGasPolicy. resolve ( provider: provider)
201
- } else {
202
- self . gasPrice = try await self . gasPricePolicy. resolve ( provider: provider)
203
- }
204
- }
205
-
206
- public var noncePolicy : NoncePolicy
207
- public var maxFeePerGasPolicy : FeePerGasPolicy
208
- public var maxPriorityFeePerGasPolicy : PriorityFeePerGasPolicy
209
- public var gasPricePolicy : GasPricePolicy
210
- public var gasLimitPolicy : GasLimitPolicy
211
-
212
191
public static var emptyTransaction = CodableTransaction ( to: EthereumAddress . contractDeploymentAddress ( ) )
213
192
}
214
193
@@ -285,95 +264,6 @@ extension CodableTransaction: Codable {
285
264
286
265
}
287
266
288
- public protocol Policyable {
289
- func resolve( provider: Web3Provider , transaction: CodableTransaction ? ) async throws -> BigUInt
290
- }
291
-
292
- extension CodableTransaction {
293
- public enum GasLimitPolicy {
294
- case automatic
295
- case manual( BigUInt )
296
- case limited( BigUInt )
297
- case withMargin( Double )
298
-
299
- func resolve( provider: Web3Provider , transaction: CodableTransaction ? ) async throws -> BigUInt {
300
- guard let transaction = transaction else { throw Web3Error . valueError }
301
- let request : APIRequest = . estimateGas( transaction, transaction. callOnBlock ?? . latest)
302
- let response : APIResponse < BigUInt > = try await APIRequest . sendRequest ( with: provider, for: request)
303
- switch self {
304
- case . automatic, . withMargin:
305
- return response. result
306
- case . manual( let value) :
307
- return value
308
- case . limited( let limit) :
309
- if limit <= response. result {
310
- return response. result
311
- } else {
312
- return limit
313
- }
314
- }
315
- }
316
- }
317
-
318
- public enum GasPricePolicy {
319
- case automatic
320
- case manual( BigUInt )
321
- case withMargin( Double )
322
-
323
- func resolve( provider: Web3Provider , transaction: CodableTransaction ? = nil ) async throws -> BigUInt {
324
- let oracle = Oracle ( provider)
325
- switch self {
326
- case . automatic, . withMargin:
327
- return await oracle. gasPriceLegacyPercentiles ( ) . max ( ) ?? 0
328
- case . manual( let value) :
329
- return value
330
- }
331
- }
332
- }
333
-
334
- public enum PriorityFeePerGasPolicy : Policyable {
335
- case automatic
336
- case manual( BigUInt )
337
-
338
- public func resolve( provider: Web3Provider , transaction: CodableTransaction ? = nil ) async throws -> BigUInt {
339
- let oracle = Oracle ( provider)
340
- switch self {
341
- case . automatic:
342
- return await oracle. tipFeePercentiles ( ) . max ( ) ?? 0
343
- case . manual( let value) :
344
- return value
345
- }
346
- }
347
- }
348
-
349
- public enum FeePerGasPolicy : Policyable {
350
- case automatic
351
- case manual( BigUInt )
352
-
353
- public func resolve( provider: Web3Provider , transaction: CodableTransaction ? = nil ) async throws -> BigUInt {
354
- let oracle = Oracle ( provider)
355
- switch self {
356
- case . automatic:
357
- return await oracle. baseFeePercentiles ( ) . max ( ) ?? 0
358
- case . manual( let value) :
359
- return value
360
- }
361
- }
362
- }
363
-
364
- func resolveNonce( provider: Web3Provider ) async throws -> BigUInt {
365
- switch noncePolicy {
366
- case . pending, . latest, . earliest:
367
- guard let address = from ?? sender else { throw Web3Error . valueError }
368
- let request : APIRequest = . getTransactionCount( address. address, callOnBlock ?? . latest)
369
- let response : APIResponse < BigUInt > = try await APIRequest . sendRequest ( with: provider, for: request)
370
- return response. result
371
- case . exact( let value) :
372
- return value
373
- }
374
- }
375
- }
376
-
377
267
extension CodableTransaction : CustomStringConvertible {
378
268
/// required by CustomString convertable
379
269
/// returns a string description for the transaction and its data
0 commit comments