1- import asyncio
2- import inspect
31import math
42from contextlib import suppress
53from typing import List , Optional , Union , Dict , Any
@@ -175,29 +173,10 @@ def estimated_byte_length(self) -> int:
175173
176174 estimated_size = estimated_byte_length
177175
178- # Private helper method for handling asynchronous fee resolution and application
179- async def _resolve_and_apply_fee (self , fee_estimate , change_distribution ):
180- """
181- A helper method to resolve and apply the transaction fee asynchronously.
182-
183- :param fee_estimate: An awaitable object that resolves to the estimated fee
184- :param change_distribution: The method of distributing change ('equal' or 'random')
185- :return: The resolved fee value (int) or None in case of an error
186- """
187- try :
188- # Resolve the fee asynchronously
189- resolved_fee = await fee_estimate
190- # Apply the resolved fee to the transaction
191- self ._apply_fee_amount (resolved_fee , change_distribution )
192- return resolved_fee
193- except Exception as e :
194- # Handle any errors and return None on failure
195- return None
196-
197176 def fee (self , model_or_fee = None , change_distribution = 'equal' ):
198177 """
199178 Computes the transaction fee and adjusts the change outputs accordingly.
200- This method can be called synchronously, even if it internally uses asynchronous operations .
179+ This method can be called synchronously or from async contexts .
201180
202181 :param model_or_fee: A fee model or a fee amount. If not provided, it defaults to an instance
203182 of `LivePolicy` that fetches the latest mining fees.
@@ -214,15 +193,10 @@ def fee(self, model_or_fee=None, change_distribution='equal'):
214193 self ._apply_fee_amount (model_or_fee , change_distribution )
215194 return model_or_fee
216195
217- # If the fee estimation requires asynchronous computation
196+ # Compute the fee using the fee model
218197 fee_estimate = model_or_fee .compute_fee (self )
219-
220- if inspect .isawaitable (fee_estimate ):
221- # Execute the asynchronous task synchronously and get the result
222- resolved_fee = asyncio .run (self ._resolve_and_apply_fee (fee_estimate , change_distribution ))
223- return resolved_fee
224-
225- # Apply the fee directly if it is computed synchronously
198+
199+ # Apply the fee directly
226200 self ._apply_fee_amount (fee_estimate , change_distribution )
227201 return fee_estimate
228202
0 commit comments