1111
1212from datetime import datetime , timezone
1313
14+ from hiero_sdk_python .account .account_id import AccountId
15+ from hiero_sdk_python .consensus .topic_id import TopicId
16+ from hiero_sdk_python .crypto .key import Key
1417from hiero_sdk_python .crypto .public_key import PublicKey
1518from hiero_sdk_python .Duration import Duration
16- from hiero_sdk_python .hapi .services import consensus_topic_info_pb2
17- from hiero_sdk_python .hapi .services .basic_types_pb2 import AccountID , Key
19+ from hiero_sdk_python .hapi .services import consensus_get_topic_info_pb2
20+ from hiero_sdk_python .hapi .services .basic_types_pb2 import AccountID
1821from hiero_sdk_python .hapi .services .timestamp_pb2 import Timestamp
1922from hiero_sdk_python .tokens .custom_fixed_fee import CustomFixedFee
2023from hiero_sdk_python .utils .key_format import format_key
@@ -31,6 +34,7 @@ class TopicInfo:
3134
3235 def __init__ (
3336 self ,
37+ topic_id : TopicId ,
3438 memo : str ,
3539 running_hash : bytes ,
3640 sequence_number : int ,
@@ -48,6 +52,7 @@ def __init__(
4852 Initializes a new instance of the TopicInfo class.
4953
5054 Args:
55+ topic_id (TopicId): The id of the topic.
5156 memo (str): The memo associated with the topic.
5257 running_hash (bytes): The current running hash of the topic.
5358 sequence_number (int): The sequence number of the topic.
@@ -61,21 +66,22 @@ def __init__(
6166 fee_exempt_keys (list[PublicKey]): The fee exempt keys for the topic.
6267 custom_fees (list[CustomFixedFee]): The custom fees for the topic.
6368 """
69+ self .topic_id : TopicId = topic_id
6470 self .memo : str = memo
6571 self .running_hash : bytes = running_hash
6672 self .sequence_number : int = sequence_number
6773 self .expiration_time : Timestamp | None = expiration_time
6874 self .admin_key : Key | None = admin_key
6975 self .submit_key : Key | None = submit_key
7076 self .auto_renew_period : Duration | None = auto_renew_period
71- self .auto_renew_account : AccountID | None = auto_renew_account
77+ self .auto_renew_account : AccountId | None = auto_renew_account
7278 self .ledger_id : bytes | None = ledger_id
73- self .fee_schedule_key : PublicKey = fee_schedule_key
74- self .fee_exempt_keys : list [PublicKey ] = list (fee_exempt_keys ) if fee_exempt_keys is not None else []
79+ self .fee_schedule_key : Key = fee_schedule_key
80+ self .fee_exempt_keys : list [Key ] = list (fee_exempt_keys ) if fee_exempt_keys is not None else []
7581 self .custom_fees : list [CustomFixedFee ] = list (custom_fees ) if custom_fees is not None else []
7682
7783 @classmethod
78- def _from_proto (cls , topic_info_proto : consensus_topic_info_pb2 . ConsensusTopicInfo ) -> TopicInfo :
84+ def _from_proto (cls , topic_info_proto : consensus_get_topic_info_pb2 . ConsensusGetTopicInfoResponse ) -> TopicInfo :
7985 """
8086 Constructs a TopicInfo object from a protobuf ConsensusTopicInfo message.
8187
@@ -85,29 +91,30 @@ def _from_proto(cls, topic_info_proto: consensus_topic_info_pb2.ConsensusTopicIn
8591 Returns:
8692 TopicInfo: The constructed TopicInfo object.
8793 """
94+ topic_info = topic_info_proto .topicInfo
95+
8896 return cls (
89- memo = topic_info_proto .memo ,
90- running_hash = topic_info_proto .runningHash ,
91- sequence_number = topic_info_proto .sequenceNumber ,
92- expiration_time = (topic_info_proto .expirationTime if topic_info_proto .HasField ("expirationTime" ) else None ),
93- admin_key = (topic_info_proto .adminKey if topic_info_proto .HasField ("adminKey" ) else None ),
94- submit_key = (topic_info_proto .submitKey if topic_info_proto .HasField ("submitKey" ) else None ),
97+ topic_id = TopicId ._from_proto (topic_info_proto .topicID ),
98+ memo = topic_info .memo ,
99+ running_hash = topic_info .runningHash ,
100+ sequence_number = topic_info .sequenceNumber ,
101+ expiration_time = (topic_info .expirationTime if topic_info .HasField ("expirationTime" ) else None ),
102+ admin_key = (Key .from_proto_key (topic_info .adminKey ) if topic_info .HasField ("adminKey" ) else None ),
103+ submit_key = (Key .from_proto_key (topic_info .submitKey ) if topic_info .HasField ("submitKey" ) else None ),
95104 auto_renew_period = (
96- Duration ._from_proto (proto = topic_info_proto .autoRenewPeriod )
97- if topic_info_proto .HasField ("autoRenewPeriod" )
105+ Duration ._from_proto (proto = topic_info .autoRenewPeriod )
106+ if topic_info .HasField ("autoRenewPeriod" )
98107 else None
99108 ),
100109 auto_renew_account = (
101- topic_info_proto . autoRenewAccount if topic_info_proto .HasField ("autoRenewAccount" ) else None
110+ AccountId . _from_proto ( topic_info . autoRenewAccount ) if topic_info .HasField ("autoRenewAccount" ) else None
102111 ),
103- ledger_id = getattr ( topic_info_proto , " ledger_id" , None ) ,
112+ ledger_id = topic_info . ledger_id if topic_info . ledger_id else None ,
104113 fee_schedule_key = (
105- PublicKey ._from_proto (topic_info_proto .fee_schedule_key )
106- if topic_info_proto .HasField ("fee_schedule_key" )
107- else None
114+ Key .from_proto_key (topic_info .fee_schedule_key ) if topic_info .HasField ("fee_schedule_key" ) else None
108115 ),
109- fee_exempt_keys = [PublicKey . _from_proto (key ) for key in topic_info_proto .fee_exempt_key_list ],
110- custom_fees = [CustomFixedFee ._from_proto (fee ) for fee in topic_info_proto .custom_fees ],
116+ fee_exempt_keys = [Key . from_proto_key (key ) for key in topic_info .fee_exempt_key_list ],
117+ custom_fees = [CustomFixedFee ._from_proto (fee ) for fee in topic_info .custom_fees ],
111118 )
112119
113120 def __repr__ (self ) -> str :
@@ -158,6 +165,7 @@ def __str__(self) -> str:
158165
159166 return (
160167 "TopicInfo(\n "
168+ f" topic_id={ self .topic_id } ,\n "
161169 f" memo='{ self .memo } ',\n "
162170 f" running_hash={ running_hash_str } ,\n "
163171 f" sequence_number={ self .sequence_number } ,\n "
0 commit comments