-
Notifications
You must be signed in to change notification settings - Fork 87
feat: add FreezeTransaction
#716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
exploreriii
merged 7 commits into
hiero-ledger:main
from
Dosik13:feature/add-FreezeTransaction
Nov 6, 2025
+635
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
101e24e
feat: implement FreezeTransaction
Dosik13 ea94da2
feat: add FreezeType
Dosik13 228ed9e
test: freeze type
Dosik13 9f1359d
test: add freeze transaction unit tests
Dosik13 190fd1e
chore: update changelog
Dosik13 fd318a4
chore: add new classes to __init__.py
Dosik13 140dbb0
chore: address PR feedback
Dosik13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| """ | ||
| FreezeTransaction class for freezing the network. | ||
| """ | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from hiero_sdk_python.channels import _Channel | ||
| from hiero_sdk_python.executable import _Method | ||
| from hiero_sdk_python.file.file_id import FileId | ||
| from hiero_sdk_python.hapi.services.freeze_pb2 import FreezeTransactionBody | ||
| from hiero_sdk_python.hapi.services.schedulable_transaction_body_pb2 import ( | ||
| SchedulableTransactionBody, | ||
| ) | ||
| from hiero_sdk_python.hapi.services.transaction_pb2 import TransactionBody | ||
| from hiero_sdk_python.system.freeze_type import FreezeType | ||
| from hiero_sdk_python.timestamp import Timestamp | ||
| from hiero_sdk_python.transaction.transaction import Transaction | ||
|
|
||
|
|
||
| class FreezeTransaction(Transaction): | ||
| """ | ||
| Represents a freeze transaction on the network. | ||
|
|
||
| This transaction freezes the network with the specified parameters including | ||
| start_time, file_id, file_hash, and freeze_type. | ||
|
|
||
| Inherits from the base Transaction class and implements the required methods | ||
| to build and execute a freeze transaction. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| start_time: Optional[Timestamp] = None, | ||
| file_id: Optional[FileId] = None, | ||
| file_hash: Optional[bytes] = None, | ||
| freeze_type: Optional[FreezeType] = None, | ||
| ): | ||
| """ | ||
| Initializes a new FreezeTransaction instance with the specified parameters. | ||
|
|
||
| Args: | ||
| start_time (Optional[Timestamp]): The start time for the freeze. | ||
| file_id (Optional[FileId]): The file ID containing the upgrade data. | ||
| file_hash (Optional[bytes]): Hash of the file for verification. | ||
| freeze_type (Optional[FreezeType]): The type of freeze to perform. | ||
| """ | ||
| super().__init__() | ||
| self.start_time: Optional[Timestamp] = start_time | ||
| self.file_id: Optional[FileId] = file_id | ||
| self.file_hash: Optional[bytes] = file_hash | ||
| self.freeze_type: Optional[FreezeType] = freeze_type | ||
|
|
||
| def set_start_time(self, start_time: Optional[Timestamp]) -> "FreezeTransaction": | ||
| """ | ||
| Sets the start time for this freeze transaction. | ||
|
|
||
| Args: | ||
| start_time (Optional[Timestamp]): The start time for the freeze. | ||
|
|
||
| Returns: | ||
| FreezeTransaction: This transaction instance. | ||
| """ | ||
| self._require_not_frozen() | ||
| self.start_time = start_time | ||
| return self | ||
|
|
||
| def set_file_id(self, file_id: Optional[FileId]) -> "FreezeTransaction": | ||
| """ | ||
| Sets the file ID for this freeze transaction. | ||
|
|
||
| Args: | ||
| file_id (Optional[FileId]): The file ID containing the upgrade data. | ||
|
|
||
| Returns: | ||
| FreezeTransaction: This transaction instance. | ||
| """ | ||
| self._require_not_frozen() | ||
| self.file_id = file_id | ||
| return self | ||
|
|
||
| def set_file_hash(self, file_hash: Optional[bytes]) -> "FreezeTransaction": | ||
| """ | ||
| Sets the file hash for this freeze transaction. | ||
|
|
||
| Args: | ||
| file_hash (Optional[bytes]): Hash of the file for verification. | ||
|
|
||
| Returns: | ||
| FreezeTransaction: This transaction instance. | ||
| """ | ||
| self._require_not_frozen() | ||
| self.file_hash = file_hash | ||
| return self | ||
|
|
||
| def set_freeze_type(self, freeze_type: Optional[FreezeType]) -> "FreezeTransaction": | ||
| """ | ||
| Sets the freeze type for this freeze transaction. | ||
|
|
||
| Args: | ||
| freeze_type (Optional[FreezeType]): The type of freeze to perform. | ||
|
|
||
| Returns: | ||
| FreezeTransaction: This transaction instance. | ||
| """ | ||
| self._require_not_frozen() | ||
| self.freeze_type = freeze_type | ||
| return self | ||
|
|
||
| def _build_proto_body(self) -> FreezeTransactionBody: | ||
| """ | ||
| Returns the protobuf body for the freeze transaction. | ||
|
|
||
| Returns: | ||
| FreezeTransactionBody: The protobuf body for this transaction. | ||
| """ | ||
| return FreezeTransactionBody( | ||
| start_time=self.start_time._to_protobuf() if self.start_time else None, | ||
| update_file=self.file_id._to_proto() if self.file_id else None, | ||
| file_hash=self.file_hash, | ||
| freeze_type=self.freeze_type._to_proto() if self.freeze_type else None, | ||
| ) | ||
|
|
||
| def build_transaction_body(self) -> TransactionBody: | ||
| """ | ||
| Builds the transaction body for this freeze transaction. | ||
|
|
||
| Returns: | ||
| TransactionBody: The built transaction body. | ||
| """ | ||
| freeze_body = self._build_proto_body() | ||
| transaction_body = self.build_base_transaction_body() | ||
| transaction_body.freeze.CopyFrom(freeze_body) | ||
| return transaction_body | ||
|
|
||
| def build_scheduled_body(self) -> SchedulableTransactionBody: | ||
| """ | ||
| Builds the scheduled transaction body for this freeze transaction. | ||
|
|
||
| Returns: | ||
| SchedulableTransactionBody: The schedulable transaction body. | ||
| """ | ||
| freeze_body = self._build_proto_body() | ||
| schedulable_body = self.build_base_scheduled_body() | ||
| schedulable_body.freeze.CopyFrom(freeze_body) | ||
| return schedulable_body | ||
|
|
||
| def _get_method(self, channel: _Channel) -> _Method: | ||
| """ | ||
| Gets the method to execute the freeze transaction. | ||
|
|
||
| This internal method returns a _Method object containing the appropriate gRPC | ||
| function to call when executing this transaction on the Hedera network. | ||
|
|
||
| Args: | ||
| channel (_Channel): The channel containing service stubs | ||
|
|
||
| Returns: | ||
| _Method: An object containing the transaction function to freeze the network. | ||
| """ | ||
| return _Method(transaction_func=channel.freeze.freeze, query_func=None) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| """ | ||
| Defines FreezeType enum for representing freeze types | ||
| """ | ||
| from enum import Enum | ||
|
|
||
| from hiero_sdk_python.hapi.services.freeze_type_pb2 import ( | ||
| FreezeType as proto_FreezeType, | ||
| ) | ||
|
|
||
|
|
||
| class FreezeType(Enum): | ||
| """ | ||
| Freeze type: | ||
|
|
||
| • UNKNOWN_FREEZE_TYPE - not applicable | ||
| • FREEZE_ONLY - Freeze only | ||
| • PREPARE_UPGRADE - Prepare upgrade | ||
| • FREEZE_UPGRADE - Freeze upgrade | ||
| • FREEZE_ABORT - Freeze abort | ||
| • TELEMETRY_UPGRADE - Telemetry upgrade | ||
| """ | ||
|
|
||
| UNKNOWN_FREEZE_TYPE = 0 | ||
| FREEZE_ONLY = 1 | ||
| PREPARE_UPGRADE = 2 | ||
| FREEZE_UPGRADE = 3 | ||
| FREEZE_ABORT = 4 | ||
| TELEMETRY_UPGRADE = 5 | ||
|
|
||
| @staticmethod | ||
| def _from_proto(proto_obj: proto_FreezeType) -> "FreezeType": | ||
| """ | ||
| Converts a protobuf FreezeType to a FreezeType enum. | ||
|
|
||
| Args: | ||
| proto_obj (proto_FreezeType): The protobuf FreezeType object. | ||
|
|
||
| Returns: | ||
| FreezeType: The corresponding FreezeType enum value. | ||
| """ | ||
| if proto_obj == proto_FreezeType.FREEZE_ONLY: | ||
| return FreezeType.FREEZE_ONLY | ||
| elif proto_obj == proto_FreezeType.PREPARE_UPGRADE: | ||
| return FreezeType.PREPARE_UPGRADE | ||
| elif proto_obj == proto_FreezeType.FREEZE_UPGRADE: | ||
| return FreezeType.FREEZE_UPGRADE | ||
| elif proto_obj == proto_FreezeType.FREEZE_ABORT: | ||
| return FreezeType.FREEZE_ABORT | ||
| elif proto_obj == proto_FreezeType.TELEMETRY_UPGRADE: | ||
| return FreezeType.TELEMETRY_UPGRADE | ||
| return FreezeType.UNKNOWN_FREEZE_TYPE | ||
|
|
||
| def _to_proto(self) -> proto_FreezeType: | ||
| """ | ||
| Converts a FreezeType enum to a protobuf FreezeType object. | ||
|
|
||
| Args: | ||
| self (FreezeType): The FreezeType enum value. | ||
|
|
||
| Returns: | ||
| proto_FreezeType: The corresponding protobuf FreezeType object. | ||
| """ | ||
| if self == FreezeType.FREEZE_ONLY: | ||
| return proto_FreezeType.FREEZE_ONLY | ||
| elif self == FreezeType.PREPARE_UPGRADE: | ||
| return proto_FreezeType.PREPARE_UPGRADE | ||
| elif self == FreezeType.FREEZE_UPGRADE: | ||
| return proto_FreezeType.FREEZE_UPGRADE | ||
| elif self == FreezeType.FREEZE_ABORT: | ||
| return proto_FreezeType.FREEZE_ABORT | ||
| elif self == FreezeType.TELEMETRY_UPGRADE: | ||
| return proto_FreezeType.TELEMETRY_UPGRADE | ||
| return proto_FreezeType.UNKNOWN_FREEZE_TYPE | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if isinstance(other, FreezeType): | ||
| return self.value == other.value | ||
| elif isinstance(other, int): | ||
| return self.value == other | ||
| return False | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.