|
7 | 7 | import Foundation
|
8 | 8 | import BigInt
|
9 | 9 |
|
| 10 | + |
10 | 11 | /// Structure capable of carying the parameters for any transaction type.
|
11 | 12 | /// while all fields in this struct are optional, they are not necessarily
|
12 | 13 | /// optional for the type of transaction they apply to.
|
@@ -187,22 +188,6 @@ public struct CodableTransaction {
|
187 | 188 | return self.envelope.encode(for: type)
|
188 | 189 | }
|
189 | 190 |
|
190 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
191 |
| - public mutating func resolve(provider: Web3Provider) async { |
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 | 191 | public var noncePolicy: NoncePolicy
|
207 | 192 | public var maxFeePerGasPolicy: FeePerGasPolicy
|
208 | 193 | public var maxPriorityFeePerGasPolicy: PriorityFeePerGasPolicy
|
@@ -264,7 +249,7 @@ extension CodableTransaction: Codable {
|
264 | 249 | if let accessList = accessList, !accessList.isEmpty {
|
265 | 250 | try containier.encode(accessList, forKey: .accessList)
|
266 | 251 | }
|
267 |
| - |
| 252 | + |
268 | 253 | if !gasLimit.isZero {
|
269 | 254 | try containier.encode(gasLimit.hexString, forKey: .gasLimit)
|
270 | 255 | }
|
@@ -293,97 +278,6 @@ extension CodableTransaction: Codable {
|
293 | 278 |
|
294 | 279 | }
|
295 | 280 |
|
296 |
| -extension CodableTransaction { |
297 |
| - public enum GasLimitPolicy { |
298 |
| - case automatic |
299 |
| - case manual(BigUInt) |
300 |
| - case limited(BigUInt) |
301 |
| - case withMargin(Double) |
302 |
| - |
303 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
304 |
| - func resolve(provider: Web3Provider, transaction: CodableTransaction?) async throws -> BigUInt { |
305 |
| - guard let transaction = transaction else { throw Web3Error.valueError } |
306 |
| - let request: APIRequest = .estimateGas(transaction, transaction.callOnBlock ?? .latest) |
307 |
| - let response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: provider, for: request) |
308 |
| - switch self { |
309 |
| - case .automatic, .withMargin: |
310 |
| - return response.result |
311 |
| - case .manual(let value): |
312 |
| - return value |
313 |
| - case .limited(let limit): |
314 |
| - if limit <= response.result { |
315 |
| - return response.result |
316 |
| - } else { |
317 |
| - return limit |
318 |
| - } |
319 |
| - } |
320 |
| - } |
321 |
| - } |
322 |
| - |
323 |
| - public enum GasPricePolicy { |
324 |
| - case automatic |
325 |
| - case manual(BigUInt) |
326 |
| - case withMargin(Double) |
327 |
| - |
328 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
329 |
| - func resolve(provider: Web3Provider, transaction: CodableTransaction? = nil) async throws -> BigUInt { |
330 |
| - let oracle = Oracle(provider) |
331 |
| - switch self { |
332 |
| - case .automatic, .withMargin: |
333 |
| - return await oracle.gasPriceLegacyPercentiles().max() ?? 0 |
334 |
| - case .manual(let value): |
335 |
| - return value |
336 |
| - } |
337 |
| - } |
338 |
| - } |
339 |
| - |
340 |
| - public enum PriorityFeePerGasPolicy: Policyable { |
341 |
| - case automatic |
342 |
| - case manual(BigUInt) |
343 |
| - |
344 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
345 |
| - public func resolve(provider: Web3Provider, transaction: CodableTransaction? = nil) async throws -> BigUInt { |
346 |
| - let oracle = Oracle(provider) |
347 |
| - switch self { |
348 |
| - case .automatic: |
349 |
| - return await oracle.tipFeePercentiles().max() ?? 0 |
350 |
| - case .manual(let value): |
351 |
| - return value |
352 |
| - } |
353 |
| - } |
354 |
| - } |
355 |
| - |
356 |
| - public enum FeePerGasPolicy: Policyable { |
357 |
| - case automatic |
358 |
| - case manual(BigUInt) |
359 |
| - |
360 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
361 |
| - public func resolve(provider: Web3Provider, transaction: CodableTransaction? = nil) async throws -> BigUInt { |
362 |
| - let oracle = Oracle(provider) |
363 |
| - switch self { |
364 |
| - case .automatic: |
365 |
| - return await oracle.baseFeePercentiles().max() ?? 0 |
366 |
| - case .manual(let value): |
367 |
| - return value |
368 |
| - } |
369 |
| - } |
370 |
| - } |
371 |
| - |
372 |
| - @available(*, deprecated, message: "Please use PolicyResolver instead") |
373 |
| - func resolveNonce(provider: Web3Provider) async throws -> BigUInt { |
374 |
| - switch noncePolicy { |
375 |
| - case .pending, .latest, .earliest: |
376 |
| - guard let address = from ?? sender else { throw Web3Error.valueError } |
377 |
| - let request: APIRequest = .getTransactionCount(address.address, callOnBlock ?? .latest) |
378 |
| - let response: APIResponse<BigUInt> = try await APIRequest.sendRequest(with: provider, for: request) |
379 |
| - return response.result |
380 |
| - case .exact(let value): |
381 |
| - return value |
382 |
| - } |
383 |
| - } |
384 |
| - |
385 |
| -} |
386 |
| - |
387 | 281 | extension CodableTransaction: CustomStringConvertible {
|
388 | 282 | /// required by CustomString convertable
|
389 | 283 | /// returns a string description for the transaction and its data
|
@@ -413,7 +307,7 @@ extension CodableTransaction {
|
413 | 307 | /// - parameters: EthereumParameters object containing additional parametrs for the transaction like gas
|
414 | 308 | public init(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt = 0,
|
415 | 309 | chainID: BigUInt = 0, value: BigUInt = 0, data: Data = Data(),
|
416 |
| - gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil, |
| 310 | + gasLimit: BigUInt = 0, maxFeePerGas: BigUInt? = nil, maxPriorityFeePerGas: BigUInt? = nil, gasPrice: BigUInt? = nil, |
417 | 311 | accessList: [AccessListEntry]? = nil, v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0) {
|
418 | 312 | // FIXME: This is duplication and should be fixed.
|
419 | 313 | self.data = data
|
|
0 commit comments