Skip to content

Commit e28a5f7

Browse files
Update DID resolution parsing (#30)
Signed-off-by: Alexander Shenshin <[email protected]>
1 parent bbec93a commit e28a5f7

File tree

7 files changed

+3009
-2348
lines changed

7 files changed

+3009
-2348
lines changed

hiero_did_sdk_python/did/hedera_did_resolver.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ async def resolve(self, did: str) -> DIDResolutionResult:
124124

125125
if not did_document.deactivated:
126126
document_meta.update({
127-
"created": datetime.date.fromtimestamp(cast(float, did_document.created)).isoformat(),
128-
"updated": datetime.date.fromtimestamp(cast(float, did_document.updated)).isoformat(),
127+
"created": datetime.date.fromtimestamp(cast(float, did_document.created)).isoformat()
128+
if did_document.created
129+
else None,
130+
"updated": datetime.date.fromtimestamp(cast(float, did_document.updated)).isoformat()
131+
if did_document.updated
132+
else None,
129133
})
130134

131135
status = {"deactivated": True} if did_document.deactivated else {}

hiero_did_sdk_python/hcs/hcs_message_transaction.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async def execute(self, client: Client):
3030
message_content = self.message.to_json()
3131

3232
transaction = TopicMessageSubmitTransaction(
33-
topic_id=TopicId.from_string(self.topic_id), message=message_content
33+
topic_id=TopicId.from_string(self.topic_id), # pyright: ignore - Hiero SDK seems to have a wrong expected type
34+
message=message_content,
3435
)
3536

3637
if self._transaction_builder:

hiero_did_sdk_python/hcs/hcs_topic_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async def create_topic(self, topic_options: HcsTopicOptions, signing_keys: list[
5757

5858
async def update_topic(self, topic_id: str, topic_options: HcsTopicOptions, signing_keys: list[PrivateKey]):
5959
transaction = _set_topic_transaction_options(
60-
TopicUpdateTransaction(topic_id=TopicId.from_string(topic_id)), topic_options
60+
TopicUpdateTransaction(topic_id=TopicId.from_string(topic_id)), # pyright: ignore - Hiero SDK seems to have a wrong expected type
61+
topic_options,
6162
).freeze_with(self._client)
6263
signed_transaction = await sign_hcs_transaction_async(transaction, signing_keys)
6364
await execute_hcs_transaction_async(signed_transaction, self._client)

hiero_did_sdk_python/hcs/utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 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
55
from hiero_sdk_python.query.query import Query
66
from hiero_sdk_python.transaction.transaction import Transaction
77

@@ -22,10 +22,22 @@ def sign_transaction():
2222
async 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

2835
async 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

Comments
 (0)