22
33from hiero_sdk_python .account .account_id import AccountId
44from hiero_sdk_python .consensus .topic_create_transaction import TopicCreateTransaction
5+ from hiero_sdk_python .consensus .topic_id import TopicId
6+ from hiero_sdk_python .consensus .topic_message_submit_transaction import TopicMessageSubmitTransaction
57from hiero_sdk_python .response_code import ResponseCode
68from hiero_sdk_python .tokens .custom_fixed_fee import CustomFixedFee
79from hiero_sdk_python .tokens .token_id import TokenId
10+ from hiero_sdk_python .transaction .custom_fee_limit import CustomFeeLimit
811from hiero_sdk_python .transaction .transaction_receipt import TransactionReceipt
912from tck .handlers .registry import rpc_method
10- from tck .param .topic import CreateTopicCustomFeeParams , CreateTopicParams
11- from tck .response .topic import CreateTopicResponse
13+ from tck .param .custom_fee import CustomFeeLimitParams , CustomFeeParams
14+ from tck .param .topic import CreateTopicParams , TopicMessageSubmitParams
15+ from tck .response .topic import CreateTopicResponse , TopicMessageSubmitResponse
1216from tck .util .client_utils import get_client
1317from tck .util .constants import DEFAULT_GRPC_TIMEOUT
1418from tck .util .key_utils import get_key_from_string
1519
1620
17- def _build_custom_fee (custom_fee_params : CreateTopicCustomFeeParams ) -> CustomFixedFee :
21+ def _build_custom_fee (custom_fee_params : CustomFeeParams ) -> CustomFixedFee :
1822 custom_fee = CustomFixedFee ()
1923
20- if custom_fee_params .feeCollectorAccountId == "" :
21- # Keep TCK behavior: explicitly empty collector should surface as internal error.
22- raise ValueError ("feeCollectorAccountId cannot be empty" )
23-
2424 if custom_fee_params .feeCollectorAccountId is not None :
2525 custom_fee .set_fee_collector_account_id (AccountId .from_string (custom_fee_params .feeCollectorAccountId ))
2626
@@ -29,7 +29,7 @@ def _build_custom_fee(custom_fee_params: CreateTopicCustomFeeParams) -> CustomFi
2929
3030 if custom_fee_params .fixedFee is not None :
3131 if custom_fee_params .fixedFee .amount is not None :
32- custom_fee .amount = custom_fee_params .fixedFee .amount
32+ custom_fee .amount = int ( custom_fee_params .fixedFee .amount )
3333
3434 if custom_fee_params .fixedFee .denominatingTokenId :
3535 custom_fee .set_denominating_token_id (TokenId .from_string (custom_fee_params .fixedFee .denominatingTokenId ))
@@ -84,3 +84,65 @@ def create_topic(params: CreateTopicParams) -> CreateTopicResponse:
8484 topic_id = str (receipt .topic_id )
8585
8686 return CreateTopicResponse (topic_id , ResponseCode (receipt .status ).name )
87+
88+
89+ def _build_custom_fee_limit (params : CustomFeeLimitParams ) -> CustomFeeLimit :
90+ """Build custom fee limit from params."""
91+ custom_fee_limit = CustomFeeLimit ()
92+
93+ if params .payerId is not None :
94+ custom_fee_limit .set_payer_id (AccountId .from_string (params .payerId ))
95+ if params .fixedFees is not None :
96+ fixed_fees = []
97+ for fee in params .fixedFees :
98+ fixed_fee = CustomFixedFee ()
99+ if fee .amount is not None :
100+ fixed_fee .set_amount_in_tinybars (int (fee .amount ))
101+
102+ if fee .denominatingTokenId is not None :
103+ fixed_fee .set_denominating_token_id (TokenId .from_string (fee .denominatingTokenId ))
104+
105+ fixed_fees .append (fixed_fee )
106+
107+ custom_fee_limit .set_custom_fees (fixed_fees )
108+ return custom_fee_limit
109+
110+
111+ def _build_topic_message_submit_transaction (params : TopicMessageSubmitParams ) -> TopicMessageSubmitTransaction :
112+ """Build topic message submit transaction from params."""
113+ transaction = TopicMessageSubmitTransaction ().set_grpc_deadline (DEFAULT_GRPC_TIMEOUT )
114+
115+ if params .topicId is not None :
116+ transaction .set_topic_id (TopicId .from_string (params .topicId ))
117+
118+ if params .message is not None :
119+ transaction .set_message (params .message )
120+
121+ if params .maxChunks is not None :
122+ transaction .set_max_chunks (params .maxChunks )
123+
124+ if params .chunkSize is not None :
125+ transaction .set_chunk_size (params .chunkSize )
126+
127+ if params .customFeeLimits is not None :
128+ custom_fee_limits = [_build_custom_fee_limit (fee ) for fee in params .customFeeLimits ]
129+
130+ transaction .set_custom_fee_limits (custom_fee_limits )
131+
132+ return transaction
133+
134+
135+ @rpc_method ("submitTopicMessage" )
136+ def submit_topic_message (params : TopicMessageSubmitParams ) -> TopicMessageSubmitResponse :
137+ """Submit message to a topic."""
138+ client = get_client (params .sessionId )
139+
140+ transaction = _build_topic_message_submit_transaction (params )
141+
142+ if params .commonTransactionParams is not None :
143+ params .commonTransactionParams .apply_common_params (transaction , client )
144+
145+ response = transaction .execute (client , wait_for_receipt = False )
146+ receipt : TransactionReceipt = response .get_receipt (client , validate_status = True )
147+
148+ return TopicMessageSubmitResponse (ResponseCode (receipt .status ).name )
0 commit comments