44
55from hiero_sdk_python .channels import _Channel
66from hiero_sdk_python .consensus .topic_id import TopicId
7- from hiero_sdk_python .crypto .private_key import PrivateKey
87from hiero_sdk_python .executable import _Method
98from hiero_sdk_python .hapi .services import consensus_submit_message_pb2 , transaction_pb2
109from hiero_sdk_python .hapi .services .schedulable_transaction_body_pb2 import (
1110 SchedulableTransactionBody ,
1211)
12+ from hiero_sdk_python .schedule .schedule_create_transaction import ScheduleCreateTransaction
1313from hiero_sdk_python .transaction .chunked_transaction import ChunkedTransaction
1414from hiero_sdk_python .transaction .custom_fee_limit import CustomFeeLimit
1515
@@ -107,33 +107,6 @@ def set_message(self, message: bytes | str) -> TopicMessageSubmitTransaction:
107107 self ._total_chunks = self .get_required_chunks ()
108108 return self
109109
110- def set_chunk_size (self , chunk_size : int ) -> TopicMessageSubmitTransaction :
111- """
112- Set maximum chunk size in bytes.
113-
114- Args:
115- chunk_size (int): The size of each chunk in bytes.
116-
117- Returns:
118- TopicMessageSubmitTransaction: This transaction instance (for chaining).
119- """
120- super ().set_chunk_size (chunk_size )
121- self ._total_chunks = self .get_required_chunks ()
122- return self
123-
124- def set_max_chunks (self , max_chunks : int ) -> TopicMessageSubmitTransaction :
125- """
126- Set maximum allowed chunks.
127-
128- Args:
129- max_chunks (int): The maximum number of chunks allowed.
130-
131- Returns:
132- TopicMessageSubmitTransaction: This transaction instance (for chaining).
133- """
134- super ().set_max_chunks (max_chunks )
135- return self
136-
137110 def set_custom_fee_limits (self , custom_fee_limits : list [CustomFeeLimit ]) -> TopicMessageSubmitTransaction :
138111 """
139112 Sets the maximum custom fees that the user is willing to pay for the message.
@@ -186,27 +159,26 @@ def _build_proto_body(self) -> consensus_submit_message_pb2.ConsensusSubmitMessa
186159 if not self .message :
187160 raise ValueError ("Missing required fields: message." )
188161
189- content = self ._message_as_bytes ()
162+ contents = self ._message_as_bytes ()
190163
191- start_index = self ._current_chunk_index * self .chunk_size
192- end_index = min (start_index + self .chunk_size , len (content ))
193- chunk_content = content [start_index :end_index ]
164+ if self ._total_chunks > 1 and self ._current_chunk_index is not None :
165+ chunk_info = consensus_submit_message_pb2 .ConsensusMessageChunkInfo (
166+ initialTransactionID = self ._initial_transaction_id ._to_proto (),
167+ total = self ._total_chunks ,
168+ number = self ._current_chunk_index + 1 ,
169+ )
194170
195- body = consensus_submit_message_pb2 .ConsensusSubmitMessageTransactionBody (
196- topicID = self .topic_id ._to_proto () if self .topic_id else None , message = chunk_content
197- )
171+ chunk_content = self ._current_chunk_slice (contents )
198172
199- # Multi-chunk metadata
200- if self ._total_chunks > 1 :
201- body .chunkInfo .CopyFrom (
202- consensus_submit_message_pb2 .ConsensusMessageChunkInfo (
203- initialTransactionID = self ._initial_transaction_id ._to_proto (),
204- total = self ._total_chunks ,
205- number = self ._current_chunk_index + 1 ,
206- )
173+ return consensus_submit_message_pb2 .ConsensusSubmitMessageTransactionBody (
174+ topicID = self .topic_id ._to_proto () if self .topic_id else None ,
175+ message = chunk_content ,
176+ chunkInfo = chunk_info ,
207177 )
208178
209- return body
179+ return consensus_submit_message_pb2 .ConsensusSubmitMessageTransactionBody (
180+ topicID = self .topic_id ._to_proto () if self .topic_id else None , message = contents
181+ )
210182
211183 def build_transaction_body (self ) -> transaction_pb2 .TransactionBody :
212184 """
@@ -220,6 +192,18 @@ def build_transaction_body(self) -> transaction_pb2.TransactionBody:
220192 transaction_body .consensusSubmitMessage .CopyFrom (consensus_submit_message_body )
221193 return transaction_body
222194
195+ def schedule (self ) -> ScheduleCreateTransaction :
196+ """
197+ Converts this transaction into a scheduled transaction.
198+ """
199+ if self .message is not None and len (self ._message_as_bytes ()) > self .chunk_size :
200+ raise RuntimeError (
201+ f"Cannot schedule TopicMessageSubmitTransaction because the message exceeds "
202+ f"the maximum chunk size of { self .chunk_size } bytes"
203+ )
204+
205+ return super ().schedule ()
206+
223207 def build_scheduled_body (self ) -> SchedulableTransactionBody :
224208 """
225209 Builds the scheduled transaction body for this topic message submit transaction.
@@ -243,16 +227,3 @@ def _get_method(self, channel: _Channel) -> _Method:
243227 _Method: The method object with bound transaction execution.
244228 """
245229 return _Method (transaction_func = channel .topic .submitMessage , query_func = None )
246-
247- def sign (self , private_key : PrivateKey ) -> TopicMessageSubmitTransaction :
248- """
249- Signs the transaction using the provided private key.
250-
251- Args:
252- private_key (PrivateKey): The private key to sign the transaction with.
253-
254- Returns:
255- TopicMessageSubmitTransaction: This transaction instance (for chaining).
256- """
257- super ().sign (private_key )
258- return self
0 commit comments