@@ -289,7 +289,7 @@ private func executeAnyInner<E: Execute>(
289289 }
290290}
291291
292- // MARK: - Execution Result Type
292+ // MARK: - Helper Types
293293
294294/// Result of attempting to execute a request on a node.
295295private enum ExecutionResult < Response> {
@@ -306,6 +306,33 @@ private enum ExecutionResult<Response> {
306306 case regenerateTransactionAndRetry( HError )
307307}
308308
309+ /// Parameters for pre-check status handling.
310+ ///
311+ /// This struct groups all parameters needed for handling pre-check status responses,
312+ /// avoiding the need for functions with many parameters and improving code clarity.
313+ private struct PrecheckParameters < E: Execute > {
314+ /// The parsed pre-check status code from the response
315+ internal let status : Status
316+
317+ /// The full GRPC response from the node
318+ internal let response : E . GrpcResponse
319+
320+ /// Context data from request creation
321+ internal let context : E . Context
322+
323+ /// Account ID of the node that processed the request
324+ internal let nodeAccountId : AccountId
325+
326+ /// Transaction ID used for the request (if applicable)
327+ internal let transactionId : TransactionId ?
328+
329+ /// The transaction or query being executed
330+ internal let executable : E
331+
332+ /// Execution context with network and backoff configuration
333+ internal let ctx : ExecuteContext
334+ }
335+
309336// MARK: - Transaction ID Management
310337
311338/// Generates the initial transaction ID for a request.
@@ -392,13 +419,15 @@ private func executeOnNode<E: Execute>(
392419 let precheckStatus = Status ( rawValue: rawPrecheckStatus)
393420
394421 return try handlePrecheckStatus (
395- precheckStatus,
396- response: response,
397- context: context,
398- nodeAccountId: nodeAccountId,
399- transactionId: transactionId,
400- executable: executable,
401- ctx: ctx
422+ params: PrecheckParameters (
423+ status: precheckStatus,
424+ response: response,
425+ context: context,
426+ nodeAccountId: nodeAccountId,
427+ transactionId: transactionId,
428+ executable: executable,
429+ ctx: ctx
430+ )
402431 )
403432}
404433
@@ -443,50 +472,37 @@ private func handleGrpcError<Response>(
443472/// - Custom retry statuses: Retry with backoff
444473/// - Everything else: Throw error
445474///
446- /// - Parameters:
447- /// - status: Parsed pre-check status
448- /// - response: GRPC response containing the status
449- /// - context: Context data from request creation
450- /// - nodeAccountId: Account ID of the node
451- /// - transactionId: Transaction ID used for the request
452- /// - executable: The transaction or query being executed
453- /// - ctx: Execution context
475+ /// - Parameter params: Parameters containing status, response, context, and execution state
454476/// - Returns: Execution result indicating success or retry strategy
455477/// - Throws: HError for unrecoverable status codes
456- private func handlePrecheckStatus< E: Execute > (
457- _ status: Status ,
458- response: E . GrpcResponse ,
459- context: E . Context ,
460- nodeAccountId: AccountId ,
461- transactionId: TransactionId ? ,
462- executable: E ,
463- ctx: ExecuteContext
464- ) throws -> ExecutionResult < E . Response > {
465- switch status {
466- case . ok where executable. shouldRetry ( forResponse: response) :
467- return . retryWithBackoff( executable. makeErrorPrecheck ( status, transactionId) )
478+ private func handlePrecheckStatus< E: Execute > ( params: PrecheckParameters < E > ) throws -> ExecutionResult < E . Response > {
479+ switch params. status {
480+ case . ok where params. executable. shouldRetry ( forResponse: params. response) :
481+ return . retryWithBackoff( params. executable. makeErrorPrecheck ( params. status, params. transactionId) )
468482
469483 case . ok:
470- let response = try executable. makeResponse ( response, context, nodeAccountId, transactionId)
484+ let response = try params. executable. makeResponse (
485+ params. response, params. context, params. nodeAccountId, params. transactionId)
471486 return . success( response)
472487
473488 case . busy, . platformNotActive:
474- return . retryImmediately( executable. makeErrorPrecheck ( status, transactionId) )
489+ return . retryImmediately( params . executable. makeErrorPrecheck ( params . status, params . transactionId) )
475490
476- case . transactionExpired where executable. explicitTransactionId == nil && ctx. operatorAccountId != nil :
477- return . regenerateTransactionAndRetry( executable. makeErrorPrecheck ( status, transactionId) )
491+ case . transactionExpired
492+ where params. executable. explicitTransactionId == nil && params. ctx. operatorAccountId != nil :
493+ return . regenerateTransactionAndRetry( params. executable. makeErrorPrecheck ( params. status, params. transactionId) )
478494
479495 case . unrecognized( let value) :
480496 throw HError (
481497 kind: . responseStatusUnrecognized,
482498 description: " response status \( value) unrecognized "
483499 )
484500
485- case let status where executable. shouldRetryPrecheck ( forStatus: status) :
486- return . retryWithBackoff( executable. makeErrorPrecheck ( status, transactionId) )
501+ case let status where params . executable. shouldRetryPrecheck ( forStatus: status) :
502+ return . retryWithBackoff( params . executable. makeErrorPrecheck ( status, params . transactionId) )
487503
488504 default :
489- throw executable. makeErrorPrecheck ( status, transactionId)
505+ throw params . executable. makeErrorPrecheck ( params . status, params . transactionId)
490506 }
491507}
492508
0 commit comments