1- import warnings
2- from hiero_sdk_python .contract .contract_id import ContractId
1+ """
2+ transaction_receipt.py
3+ ~~~~~~~~~~~~~~~~~~~~~~
4+
5+ Defines the TransactionReceipt class, which represents the outcome of a Hedera transaction.
6+
7+ This module provides structured access to fields in a transaction receipt,
8+ including associated IDs like TokenId, TopicId, AccountId, and FileId.
9+ It wraps the underlying protobuf object and exposes key properties with
10+ optional deprecated alias support via `_DeprecatedAliasesMixin`.
11+
12+ Classes:
13+ - TransactionReceipt: Parses and exposes fields from a transaction receipt protobuf.
14+ """
15+ from typing import Optional , cast
316from hiero_sdk_python .file .file_id import FileId
17+ from hiero_sdk_python .contract .contract_id import ContractId
418from hiero_sdk_python .tokens .token_id import TokenId
519from hiero_sdk_python .consensus .topic_id import TopicId
620from hiero_sdk_python .account .account_id import AccountId
721from hiero_sdk_python ._deprecated import _DeprecatedAliasesMixin
22+ from hiero_sdk_python .transaction .transaction_id import TransactionId
23+ from hiero_sdk_python .hapi .services import transaction_receipt_pb2 , response_code_pb2
824
9- class TransactionReceipt (_DeprecatedAliasesMixin ):
25+ class TransactionReceipt (_DeprecatedAliasesMixin ): # type: ignore[misc]
1026 """
1127 Represents the receipt of a transaction.
1228 Imports deprecated aliases for tokenId, topicId and accountId.
@@ -17,21 +33,27 @@ class TransactionReceipt(_DeprecatedAliasesMixin):
1733 Attributes:
1834 status (ResponseCode): The status code of the transaction.
1935 _receipt_proto (TransactionReceiptProto): The underlying protobuf receipt.
36+ _transaction_id (TransactionId): The transaction ID associated with this receipt.
2037 """
2138
22- def __init__ (self , receipt_proto , transaction_id = None ):
39+ def __init__ (
40+ self ,
41+ receipt_proto : transaction_receipt_pb2 .TransactionReceipt ,
42+ transaction_id : Optional [TransactionId ] = None
43+ ) -> None :
2344 """
2445 Initializes the TransactionReceipt with the provided protobuf receipt.
2546
2647 Args:
27- receipt_proto (TransactionReceiptProto): The protobuf transaction receipt.
48+ receipt_proto (transaction_receipt_pb2.TransactionReceiptProto, optional): The protobuf transaction receipt.
49+ transaction_id (TransactionId, optional): The transaction ID associated with this receipt.
2850 """
29- self ._transaction_id = transaction_id
30- self .status = receipt_proto .status
31- self ._receipt_proto = receipt_proto
51+ self ._transaction_id : Optional [ TransactionId ] = transaction_id
52+ self .status : Optional [ response_code_pb2 . ResponseCodeEnum ] = receipt_proto .status
53+ self ._receipt_proto : transaction_receipt_pb2 . TransactionReceipt = receipt_proto
3254
3355 @property
34- def token_id (self ):
56+ def token_id (self ) -> Optional [ TokenId ] :
3557 """
3658 Retrieves the TokenId associated with the transaction receipt, if available.
3759
@@ -40,11 +62,10 @@ def token_id(self):
4062 """
4163 if self ._receipt_proto .HasField ('tokenID' ) and self ._receipt_proto .tokenID .tokenNum != 0 :
4264 return TokenId ._from_proto (self ._receipt_proto .tokenID )
43- else :
44- return None
65+ return None
4566
4667 @property
47- def topic_id (self ):
68+ def topic_id (self ) -> Optional [ TopicId ] :
4869 """
4970 Retrieves the TopicId associated with the transaction receipt, if available.
5071
@@ -53,44 +74,44 @@ def topic_id(self):
5374 """
5475 if self ._receipt_proto .HasField ('topicID' ) and self ._receipt_proto .topicID .topicNum != 0 :
5576 return TopicId ._from_proto (self ._receipt_proto .topicID )
56- else :
57- return None
77+ return None
5878
5979 @property
60- def account_id (self ):
80+ def account_id (self ) -> Optional [ AccountId ] :
6181 """
6282 Retrieves the AccountId associated with the transaction receipt, if available.
6383
6484 Returns:
6585 AccountId or None: The AccountId if present; otherwise, None.
6686 """
67- if self ._receipt_proto .HasField ('accountID' ) and self ._receipt_proto .accountID .accountNum != 0 :
87+ if (
88+ self ._receipt_proto .HasField ('accountID' )
89+ and self ._receipt_proto .accountID .accountNum != 0
90+ ):
6891 return AccountId ._from_proto (self ._receipt_proto .accountID )
69- else :
70- return None
92+ return None
7193
7294 @property
73- def serial_numbers (self ):
95+ def serial_numbers (self ) -> list [ int ] :
7496 """
7597 Retrieves the serial numbers associated with the transaction receipt, if available.
7698
7799 Returns:
78100 list of int: The serial numbers if present; otherwise, an empty list.
79101 """
80- return self ._receipt_proto .serialNumbers
102+ return cast ( list [ int ], self ._receipt_proto .serialNumbers )
81103
82104 @property
83- def file_id (self ):
105+ def file_id (self ) -> Optional [ FileId ] :
84106 """
85107 Returns the file ID associated with this receipt.
86108 """
87109 if self ._receipt_proto .HasField ('fileID' ) and self ._receipt_proto .fileID .fileNum != 0 :
88110 return FileId ._from_proto (self ._receipt_proto .fileID )
89- else :
90- return None
91-
111+ return None
112+
92113 @property
93- def transaction_id (self ):
114+ def transaction_id (self ) -> Optional [ TransactionId ] :
94115 """
95116 Returns the transaction ID associated with this receipt.
96117
@@ -117,10 +138,18 @@ def _to_proto(self):
117138 Returns the underlying protobuf transaction receipt.
118139
119140 Returns:
120- TransactionReceiptProto : The protobuf transaction receipt.
141+ transaction_receipt_pb2.TransactionReceipt : The protobuf transaction receipt.
121142 """
122143 return self ._receipt_proto
123144
124145 @classmethod
125- def _from_proto (cls , proto , transaction_id = None ):
146+ def _from_proto (cls , proto : transaction_receipt_pb2 .TransactionReceipt , transaction_id : TransactionId ) -> "TransactionReceipt" :
147+ """
148+ Creates a TransactionReceipt instance from a protobuf TransactionReceipt object.
149+ Args:
150+ proto (transaction_receipt_pb2.TransactionReceipt): The protobuf TransactionReceipt object.
151+ transaction_id (TransactionId): The transaction ID associated with this receipt.
152+ Returns:
153+ TransactionReceipt: A new instance of TransactionReceipt populated with data from the protobuf object.
154+ """
126155 return cls (receipt_proto = proto , transaction_id = transaction_id )
0 commit comments