11import asyncio
2- from typing import Any
2+ from typing import Any , cast
33
4- from hiero_sdk_python import Client , PrivateKey , TransactionReceipt
4+ from hiero_sdk_python import Client , PrivateKey , ResponseCode , TransactionReceipt
55from hiero_sdk_python .query .query import Query
66from hiero_sdk_python .transaction .transaction import Transaction
77
@@ -22,10 +22,22 @@ def sign_transaction():
2222async def execute_hcs_transaction_async (transaction : Transaction , client : Client ) -> TransactionReceipt :
2323 execution_task = asyncio .create_task (asyncio .to_thread (lambda : transaction .execute (client )))
2424 await execution_task
25- return execution_task .result ()
25+ receipt = cast (TransactionReceipt , execution_task .result ())
26+
27+ # We need additional validation since Hiero SDK Python do not catch error statuses in some cases (in recent versions)
28+ if receipt .status != ResponseCode .SUCCESS :
29+ error_reason = ResponseCode .get_name (receipt .status ) if receipt .status else "Response code is empty"
30+ raise Exception (f"Error retrieving transaction receipt: { error_reason } " )
31+
32+ return receipt
2633
2734
2835async def execute_hcs_query_async (query : Query , client : Client ) -> Any :
29- query_task = asyncio .create_task (asyncio .to_thread (lambda : query .execute (client )))
36+ # Hiero Python SDK removed 'execute' method from 'Query' base class
37+ # It looks non-optimal for public API and there is actually no 'Query' subclasses that do not implement 'execute'
38+ # It makes sense to use simple runtime check until this problem is addressed
39+ if not query .execute : # pyright: ignore [reportAttributeAccessIssue]
40+ raise Exception ("Query instance do not implement 'execute' method" )
41+ query_task = asyncio .create_task (asyncio .to_thread (lambda : query .execute (client ))) # pyright: ignore [reportAttributeAccessIssue]
3042 await query_task
3143 return query_task .result ()
0 commit comments