Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
## [Unreleased]

### Added
- added FreezeTransaction class
- added FreezeType class
- Added `docs/sdk_developers/pylance.md`, a new guide explaining how to set up and use **Pylance** in VS Code for validating imports, file references, and methods before review. (#713)
- docs: Add Google-style docstrings to `TokenId` class and its methods in `token_id.py`.
- added Google-style docstrings to the `TransactionRecord` class including all dataclass fields, `__repr__`, `_from_proto()` & `_to_proto()` methods.
Expand Down
8 changes: 8 additions & 0 deletions src/hiero_sdk_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@
from .tokens.custom_royalty_fee import CustomRoyaltyFee
from .transaction.custom_fee_limit import CustomFeeLimit

# System
from .system.freeze_transaction import FreezeTransaction
from .system.freeze_type import FreezeType

__all__ = [
# Client
"Client",
Expand Down Expand Up @@ -278,4 +282,8 @@
"CustomFractionalFee",
"CustomRoyaltyFee",
"CustomFeeLimit",

# System
"FreezeTransaction",
"FreezeType",
]
160 changes: 160 additions & 0 deletions src/hiero_sdk_python/system/freeze_transaction.py
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)
80 changes: 80 additions & 0 deletions src/hiero_sdk_python/system/freeze_type.py
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
Loading