88
99from hiero_sdk_python .timestamp import Timestamp
1010from hiero_sdk_python .hapi .mirror import consensus_service_pb2 as mirror_proto
11+ from hiero_sdk_python .transaction .transaction_id import TransactionId
1112
1213
1314class TopicMessageChunk :
@@ -40,7 +41,7 @@ def __init__(
4041 consensus_timestamp : datetime ,
4142 message_data : Dict [str , Union [bytes , int ]],
4243 chunks : List [TopicMessageChunk ],
43- transaction_id : Optional [str ] = None ,
44+ transaction_id : Optional [TransactionId ] = None ,
4445 ) -> None :
4546 """
4647 Args:
@@ -52,14 +53,14 @@ def __init__(
5253 "sequence_number": int
5354 }
5455 chunks (List[TopicMessageChunk]): All individual chunks that form this message.
55- transaction_id (Optional[str ]): The transaction ID string if available.
56+ transaction_id (Optional[Transaction ]): The transaction ID if available.
5657 """
5758 self .consensus_timestamp : datetime = consensus_timestamp
5859 self .contents : Union [bytes , int ] = message_data ["contents" ]
5960 self .running_hash : Union [bytes , int ] = message_data ["running_hash" ]
6061 self .sequence_number : Union [bytes , int ] = message_data ["sequence_number" ]
6162 self .chunks : List [TopicMessageChunk ] = chunks
62- self .transaction_id : Optional [str ] = transaction_id
63+ self .transaction_id : Optional [TransactionId ] = transaction_id
6364
6465 @classmethod
6566 def of_single (cls , response : mirror_proto .ConsensusTopicResponse ) -> "TopicMessage" : # type: ignore
@@ -72,13 +73,9 @@ def of_single(cls, response: mirror_proto.ConsensusTopicResponse) -> "TopicMessa
7273 running_hash : Union [bytes , int ] = response .runningHash
7374 sequence_number : Union [bytes , int ] = chunk .sequence_number
7475
75- transaction_id : Optional [str ] = None
76+ transaction_id : Optional [TransactionId ] = None
7677 if response .HasField ("chunkInfo" ) and response .chunkInfo .HasField ("initialTransactionID" ):
77- tx_id = response .chunkInfo .initialTransactionID
78- transaction_id = (
79- f"{ tx_id .shardNum } .{ tx_id .realmNum } .{ tx_id .accountNum } -"
80- f"{ tx_id .transactionValidStart .seconds } .{ tx_id .transactionValidStart .nanos } "
81- )
78+ transaction_id = TransactionId ._from_proto (response .chunkInfo .initialTransactionID )
8279
8380 return cls (
8481 consensus_timestamp ,
@@ -102,25 +99,24 @@ def of_many(cls, responses: List[mirror_proto.ConsensusTopicResponse]) -> "Topic
10299
103100 chunks : List [TopicMessageChunk ] = []
104101 total_size : int = 0
105- transaction_id : Optional [str ] = None
106-
102+ transaction_id : Optional [TransactionId ] = None
103+
107104 for r in sorted_responses :
108105 c = TopicMessageChunk (r )
109106 chunks .append (c )
107+
110108 total_size += len (r .message )
109+
111110
112111 if (
113112 transaction_id is None
114113 and r .HasField ("chunkInfo" )
115114 and r .chunkInfo .HasField ("initialTransactionID" )
116115 ):
117- tx_id = r .chunkInfo .initialTransactionID
118- transaction_id = (
119- f"{ tx_id .shardNum } .{ tx_id .realmNum } .{ tx_id .accountNum } -"
120- f"{ tx_id .transactionValidStart .seconds } .{ tx_id .transactionValidStart .nanos } "
121- )
116+ transaction_id = TransactionId ._from_proto (r .chunkInfo .initialTransactionID )
122117
123118 contents = bytearray (total_size )
119+
124120 offset : int = 0
125121 for r in sorted_responses :
126122 end = offset + len (r .message )
0 commit comments