Skip to content

Commit 27bb0ac

Browse files
committed
chore: updated example for topic_info
Signed-off-by: Manish Dait <daitmanish88@gmail.com>
1 parent 15531e6 commit 27bb0ac

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
"""
2828

2929
from hiero_sdk_python.account.account_id import AccountId
30+
from hiero_sdk_python.consensus.topic_id import TopicId
3031
from hiero_sdk_python.consensus.topic_info import TopicInfo
3132
from hiero_sdk_python.crypto.private_key import PrivateKey
3233
from hiero_sdk_python.Duration import Duration
33-
from hiero_sdk_python.hapi.services import consensus_topic_info_pb2
34+
from hiero_sdk_python.hapi.services import consensus_get_topic_info_pb2, consensus_topic_info_pb2
3435
from hiero_sdk_python.hapi.services.basic_types_pb2 import AccountID, Key
3536
from hiero_sdk_python.hapi.services.timestamp_pb2 import Timestamp
3637
from hiero_sdk_python.tokens.custom_fixed_fee import CustomFixedFee
@@ -92,6 +93,7 @@ def mock_ledger_id() -> bytes:
9293
def build_mock_topic_info() -> TopicInfo:
9394
"""Manually construct a TopicInfo instance with mock data."""
9495
return TopicInfo(
96+
topic_id=TopicId.from_string("0.0.101"),
9597
memo="Example topic memo",
9698
running_hash=mock_running_hash(),
9799
sequence_number=42,
@@ -109,24 +111,30 @@ def build_mock_topic_info() -> TopicInfo:
109111

110112
def build_topic_info_from_proto() -> TopicInfo:
111113
"""Build a TopicInfo from a mocked protobuf message using _from_proto()."""
112-
proto = consensus_topic_info_pb2.ConsensusTopicInfo()
113-
proto.memo = "Topic from protobuf"
114-
proto.runningHash = mock_running_hash()
115-
proto.sequenceNumber = 100
116-
proto.expirationTime.CopyFrom(mock_expiration_time())
117-
proto.adminKey.CopyFrom(mock_admin_key())
118-
proto.submitKey.CopyFrom(mock_submit_key())
119-
proto.autoRenewPeriod.seconds = 7776000
120-
proto.autoRenewAccount.CopyFrom(mock_auto_renew_account())
121-
proto.ledger_id = mock_ledger_id()
122-
proto.custom_fees.append(mock_custom_fee()._to_topic_fee_proto())
114+
proto = consensus_get_topic_info_pb2.ConsensusGetTopicInfoResponse()
115+
proto.topicID.CopyFrom(TopicId(0, 0, 1)._to_proto())
116+
117+
topic_info_proto = consensus_topic_info_pb2.ConsensusTopicInfo()
118+
topic_info_proto.memo = "Topic from protobuf"
119+
topic_info_proto.runningHash = mock_running_hash()
120+
topic_info_proto.sequenceNumber = 100
121+
topic_info_proto.expirationTime.CopyFrom(mock_expiration_time())
122+
topic_info_proto.adminKey.CopyFrom(mock_admin_key())
123+
topic_info_proto.submitKey.CopyFrom(mock_submit_key())
124+
topic_info_proto.autoRenewPeriod.seconds = 7776000
125+
topic_info_proto.autoRenewAccount.CopyFrom(mock_auto_renew_account())
126+
topic_info_proto.ledger_id = mock_ledger_id()
127+
topic_info_proto.custom_fees.append(mock_custom_fee()._to_topic_fee_proto())
128+
129+
proto.topicInfo.CopyFrom(topic_info_proto)
123130

124131
return TopicInfo._from_proto(proto)
125132

126133

127134
def print_topic_info(topic: TopicInfo) -> None:
128135
"""Display the key attributes of a TopicInfo instance."""
129136
print("\nTopicInfo Details:")
137+
print(f" TopicId: {topic.topic_id}")
130138
print(f" Memo: {topic.memo}")
131139
print(f" Sequence Number: {topic.sequence_number}")
132140
print(f" Running Hash: {topic.running_hash.hex()}")

src/hiero_sdk_python/consensus/topic_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def __str__(self) -> str:
165165

166166
return (
167167
"TopicInfo(\n"
168-
f" topic_id={self.topic_id}"
168+
f" topic_id={self.topic_id},\n"
169169
f" memo='{self.memo}',\n"
170170
f" running_hash={running_hash_str},\n"
171171
f" sequence_number={self.sequence_number},\n"

0 commit comments

Comments
 (0)