1+ from hiero_sdk_python .tokens .token_id import TokenId
2+ from hiero_sdk_python .transaction .transaction import Transaction
3+ from hiero_sdk_python .hapi .services .token_pause_pb2 import TokenPauseTransactionBody
4+ from hiero_sdk_python .channels import _Channel
5+ from hiero_sdk_python .executable import _Method
6+
7+ class TokenPauseTransaction (Transaction ):
8+ """
9+ Represents a token pause transaction.
10+
11+ A token pause transaction prevents a token from being involved in any operation.
12+
13+ The token is required to have a pause key and the pause key must sign.
14+ Once a token is paused, token status will update from unpaused to paused.
15+ The token status for tokens that do not have an assigned pause key will state PauseNotApplicable.
16+
17+ Inherits from the base Transaction class and implements the required methods
18+ to build and execute a token pause transaction.
19+ """
20+ def __init__ (self , token_id = None ):
21+ """
22+ Initializes a new TokenPauseTransaction instance with optional token_id.
23+
24+ Args:
25+ token_id (TokenId, optional): The ID of the token to be paused.
26+ """
27+ super ().__init__ ()
28+ self .token_id : TokenId = token_id
29+
30+ def set_token_id (self , token_id ):
31+ """
32+ Sets the ID of the token to be paused.
33+
34+ Args:
35+ token_id (TokenId): The ID of the token to be paused.
36+
37+ Returns:
38+ TokenPauseTransaction: Returns self for method chaining.
39+ """
40+ self ._require_not_frozen ()
41+ self .token_id = token_id
42+ return self
43+
44+ def build_transaction_body (self ):
45+ """
46+ Builds and returns the protobuf transaction body for token pause.
47+
48+ Returns:
49+ TransactionBody: The protobuf transaction body containing the token pause details.
50+
51+ Raises:
52+ ValueError: If no token_id has been set.
53+ """
54+ if self .token_id is None :
55+ raise ValueError ("token_id must be set before building the transaction body" )
56+
57+ token_pause_body = TokenPauseTransactionBody (
58+ token = self .token_id .to_proto ()
59+ )
60+ transaction_body = self .build_base_transaction_body ()
61+ transaction_body .tokenPause .CopyFrom (token_pause_body )
62+ return transaction_body
63+
64+ def _get_method (self , channel : _Channel ) -> _Method :
65+ return _Method (
66+ transaction_func = channel .token .pauseToken ,
67+ query_func = None
68+ )
69+
70+ def _from_proto (self , proto : TokenPauseTransactionBody ):
71+ """
72+ Deserializes a TokenPauseTransactionBody from a protobuf object.
73+
74+ Args:
75+ proto (TokenPauseTransactionBody): The protobuf object to deserialize.
76+
77+ Returns:
78+ TokenPauseTransaction: Returns self for method chaining.
79+ """
80+ self .token_id = TokenId .from_proto (proto .token )
81+ return self
0 commit comments