From af0676312dd1c57230428b2e43e146e294a72b3d Mon Sep 17 00:00:00 2001 From: mtc1146 Date: Sun, 23 Mar 2025 17:09:49 +0800 Subject: [PATCH 1/3] guard let httpResponse = response as? HTTPURLResponse else { throw Web3Error.unknownError } guard 200 ..< 400 ~= httpResponse.statusCode else { if 400 ..< 500 ~= httpResponse.statusCode { throw Web3Error.clientError(code: httpResponse.statusCode) } else { throw Web3Error.serverError(code: httpResponse.statusCode) } } --- .../EthereumNetwork/Request/APIRequest+Methods.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift b/Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift index c25ee496d..60ff9a094 100644 --- a/Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift +++ b/Sources/Web3Core/EthereumNetwork/Request/APIRequest+Methods.swift @@ -120,11 +120,15 @@ extension APIRequest { public static func send(uRLRequest: URLRequest, with session: URLSession) async throws -> Data { let (data, response) = try await session.data(for: uRLRequest) - guard 200 ..< 400 ~= response.statusCode else { - if 400 ..< 500 ~= response.statusCode { - throw Web3Error.clientError(code: response.statusCode) + guard let httpResponse = response as? HTTPURLResponse else { + throw Web3Error.unknownError + } + + guard 200 ..< 400 ~= httpResponse.statusCode else { + if 400 ..< 500 ~= httpResponse.statusCode { + throw Web3Error.clientError(code: httpResponse.statusCode) } else { - throw Web3Error.serverError(code: response.statusCode) + throw Web3Error.serverError(code: httpResponse.statusCode) } } From 2a93091ecd1cb6a407cc1d5e432bd4df147c4dda Mon Sep 17 00:00:00 2001 From: mtc1146 Date: Sun, 23 Mar 2025 17:09:57 +0800 Subject: [PATCH 2/3] delete --- .../Utility/Async+BackwardCapability.swift | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 Sources/Web3Core/EthereumNetwork/Utility/Async+BackwardCapability.swift diff --git a/Sources/Web3Core/EthereumNetwork/Utility/Async+BackwardCapability.swift b/Sources/Web3Core/EthereumNetwork/Utility/Async+BackwardCapability.swift deleted file mode 100644 index e6b67ae83..000000000 --- a/Sources/Web3Core/EthereumNetwork/Utility/Async+BackwardCapability.swift +++ /dev/null @@ -1,25 +0,0 @@ -// -// Async+BackwardCapability.swift -// -// -// Created by Yaroslav Yashin on 05.06.2022. -// - -import Foundation - -@available(iOS, obsoleted: 15.0, message: "Use the built-in API instead") -@available(macOS, obsoleted: 12.0, message: "Use the built-in API instead") -extension URLSession { - func data(for request: URLRequest) async throws -> (Data, HTTPURLResponse) { - try await withCheckedThrowingContinuation { continuation in - let dataTask = self.dataTask(with: request) { data, response, error in - guard let data = data, let response = response as? HTTPURLResponse else { - let error = error ?? URLError(.badServerResponse) - return continuation.resume(throwing: error) - } - continuation.resume(returning: (data, response)) - } - dataTask.resume() - } - } -} From fc667c2db2f38c624cf737cacafd0dc23af74c84 Mon Sep 17 00:00:00 2001 From: mtc1146 Date: Sun, 23 Mar 2025 17:10:10 +0800 Subject: [PATCH 3/3] - case shortest = 1 - case medium = 5 - case longest = 60 + case shortest = 1_500_000_000 + case medium = 2_500_000_000 + case longest = 9_000_000_000 --- Sources/web3swift/Transaction/TransactionPollingTask.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/web3swift/Transaction/TransactionPollingTask.swift b/Sources/web3swift/Transaction/TransactionPollingTask.swift index 08593e42c..f5c69ff0f 100644 --- a/Sources/web3swift/Transaction/TransactionPollingTask.swift +++ b/Sources/web3swift/Transaction/TransactionPollingTask.swift @@ -11,9 +11,9 @@ import Web3Core final public class TransactionPollingTask { private enum DelayUnit: UInt64 { - case shortest = 1 - case medium = 5 - case longest = 60 + case shortest = 1_500_000_000 + case medium = 2_500_000_000 + case longest = 9_000_000_000 func shouldIncreaseDelay(_ startTime: Date) -> Bool { let timePassed = Date().timeIntervalSince1970 - startTime.timeIntervalSince1970