Skip to content

Commit 832a5e9

Browse files
authored
feat: implement endpoint for deleteTopic method (#2451)
Signed-off-by: MonaaEid <monaa_eid@hotmail.com>
1 parent 69eec2a commit 832a5e9

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

tck/handlers/topic.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hiero_sdk_python.account.account_id import AccountId
44
from hiero_sdk_python.consensus.topic_create_transaction import TopicCreateTransaction
5+
from hiero_sdk_python.consensus.topic_delete_transaction import TopicDeleteTransaction
56
from hiero_sdk_python.consensus.topic_id import TopicId
67
from hiero_sdk_python.consensus.topic_info import TopicInfo
78
from hiero_sdk_python.consensus.topic_message_submit_transaction import TopicMessageSubmitTransaction
@@ -14,10 +15,11 @@
1415
from hiero_sdk_python.transaction.transaction_receipt import TransactionReceipt
1516
from tck.handlers.registry import rpc_method
1617
from tck.param.custom_fee import CustomFeeLimitParams, CustomFeeParams
17-
from tck.param.topic import CreateTopicParams, TopicMessageInfoParams, TopicMessageSubmitParams
18+
from tck.param.topic import CreateTopicParams, DeleteTopicParams, TopicMessageInfoParams, TopicMessageSubmitParams
1819
from tck.response.topic import (
1920
CreateTopicResponse,
2021
CustomFeeResponse,
22+
DeleteTopicResponse,
2123
FixedFeeResponse,
2224
TopicInfoResponse,
2325
TopicMessageSubmitResponse,
@@ -95,6 +97,25 @@ def create_topic(params: CreateTopicParams) -> CreateTopicResponse:
9597
return CreateTopicResponse(topic_id, ResponseCode(receipt.status).name)
9698

9799

100+
@rpc_method("deleteTopic")
101+
def delete_topic(params: DeleteTopicParams) -> DeleteTopicResponse:
102+
"""Delete topic."""
103+
client = get_client(params.sessionId)
104+
105+
transaction = TopicDeleteTransaction().set_grpc_deadline(DEFAULT_GRPC_TIMEOUT)
106+
107+
if params.topicId is not None:
108+
transaction.set_topic_id(TopicId.from_string(params.topicId))
109+
110+
if params.commonTransactionParams is not None:
111+
params.commonTransactionParams.apply_common_params(transaction, client)
112+
113+
response = transaction.execute(client, wait_for_receipt=False)
114+
receipt: TransactionReceipt = response.get_receipt(client, validate_status=True)
115+
116+
return DeleteTopicResponse(ResponseCode(receipt.status).name)
117+
118+
98119
def _build_custom_fee_limit(params: CustomFeeLimitParams) -> CustomFeeLimit:
99120
"""Build custom fee limit from params."""
100121
custom_fee_limit = CustomFeeLimit()

tck/param/topic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ def parse_json_params(cls, params: dict) -> CreateTopicParams:
5656
)
5757

5858

59+
@dataclass
60+
class DeleteTopicParams(BaseTransactionParams):
61+
"""Parameters for deleting a topic. Extends BaseTransactionParams to include common transaction parameters."""
62+
63+
topicId: str | None = None
64+
65+
@classmethod
66+
def parse_json_params(cls, params: dict) -> DeleteTopicParams:
67+
"""Parse JSON-RPC params into a DeleteTopicParams instance."""
68+
return cls(
69+
topicId=params.get("topicId"),
70+
sessionId=parse_session_id(params),
71+
commonTransactionParams=parse_common_transaction_params(params),
72+
)
73+
74+
5975
@dataclass
6076
class TopicMessageSubmitParams(BaseTransactionParams):
6177
"""Request parameters for submitTopicMessage endpoint."""

tck/response/topic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from dataclasses import dataclass
44

5+
from tck.response.base import StatusOnlyResponse
6+
57

68
@dataclass
79
class CreateTopicResponse:
@@ -11,6 +13,11 @@ class CreateTopicResponse:
1113
status: str | None = None
1214

1315

16+
@dataclass
17+
class DeleteTopicResponse(StatusOnlyResponse):
18+
"""Response payload for deleteTopic."""
19+
20+
1421
@dataclass
1522
class TopicMessageSubmitResponse:
1623
"""Response payload for submitTopicMessage."""

0 commit comments

Comments
 (0)