Skip to content
Open
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: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
## [Unreleased]

### Src
-
- Fix child transaction receipts in `TransactionGetReceiptQuery` to properly expose protobuf fields like `accountID` by passing `None` instead of parent transaction_id (#1849)

### Tests

Expand Down
15 changes: 11 additions & 4 deletions src/hiero_sdk_python/query/transaction_get_receipt_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,21 @@ def _map_status_error(self, response: response_pb2.Response) -> Union[PrecheckEr
TransactionReceipt._from_proto(response.transactionGetReceipt.receipt, self.transaction_id),
)

def _map_receipt_list(self, receipts: List[transaction_receipt_pb2.TransactionReceipt]) -> List["TransactionReceipt"]:
def _map_receipt_list(self, receipts: List[transaction_receipt_pb2.TransactionReceipt], include_parent_tx_id: bool = False) -> List["TransactionReceipt"]:
"""
Maps a list of protobuf transaction receipts to TransactionReceipt objects.

Args:
receipts: A list of protobuf TransactionReceipt objects
include_parent_tx_id: If True, pass parent transaction_id to mapped receipts (for duplicates).
If False, pass None (for child receipts).

Returns:
A list of TransactionReceipt objects
"""
transaction_id = self.transaction_id if include_parent_tx_id else None
return [
TransactionReceipt._from_proto(receipt_proto, self.transaction_id)
TransactionReceipt._from_proto(receipt_proto, transaction_id)
for receipt_proto in receipts
]

Expand Down Expand Up @@ -317,15 +320,19 @@ def execute(self, client: Client, timeout: Optional[Union[int, float]] = None) -
parent = TransactionReceipt._from_proto(response.transactionGetReceipt.receipt, self.transaction_id)

if self.include_children:
# Child receipts are sub-transactions; they don't need parent transaction_id
children = self._map_receipt_list(
response.transactionGetReceipt.child_transaction_receipts
response.transactionGetReceipt.child_transaction_receipts,
include_parent_tx_id=False
)

parent._set_children(children)

if self.include_duplicates:
# Duplicate receipts are related to parent; keep parent transaction_id for context
duplicates = self._map_receipt_list(
response.transactionGetReceipt.duplicateTransactionReceipts
response.transactionGetReceipt.duplicateTransactionReceipts,
include_parent_tx_id=True
)

parent._set_duplicates(duplicates)
Expand Down
16 changes: 9 additions & 7 deletions src/hiero_sdk_python/transaction/transaction_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ def account_id(self) -> Optional[AccountId]:
"""
Retrieves the AccountId associated with the transaction receipt, if available.

Unlike other ID properties (token_id, file_id, etc.), this returns the AccountId
even when accountNum is 0. This is intentional to support EVM auto-account creation
scenarios where the protobuf may contain an AccountID with num=0 to identify the
newly created account before it's fully initialized on-chain.

Returns:
AccountId or None: The AccountId if present; otherwise, None.
AccountId or None: The AccountId if present (including num=0); otherwise, None.
"""
if (
self._receipt_proto.HasField("accountID")
and self._receipt_proto.accountID.accountNum != 0
):
if self._receipt_proto.HasField("accountID"):
return AccountId._from_proto(self._receipt_proto.accountID)
return None

Expand Down Expand Up @@ -257,12 +259,12 @@ def _to_proto(self):
return self._receipt_proto

@classmethod
def _from_proto(cls, proto: transaction_receipt_pb2.TransactionReceipt, transaction_id: TransactionId) -> "TransactionReceipt":
def _from_proto(cls, proto: transaction_receipt_pb2.TransactionReceipt, transaction_id: TransactionId | None) -> "TransactionReceipt":
Copy link
Copy Markdown
Contributor

@Adityarya11 Adityarya11 Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**non-blocking Issue:** a minor note, the PR description mentions using Optional[TransactionId] but the code uses TransactionId | None. Since we run on Python 3.10+ this is perfectly valid and safe, just pointing it out as a small stylistic difference compared to older files.

"""
Creates a TransactionReceipt instance from a protobuf TransactionReceipt object.
Args:
proto (transaction_receipt_pb2.TransactionReceipt): The protobuf TransactionReceipt object.
transaction_id (TransactionId): The transaction ID associated with this receipt.
transaction_id (TransactionId | None): The transaction ID associated with this receipt. Can be None for child receipts.
Returns:
TransactionReceipt: A new instance of TransactionReceipt populated with data from the protobuf object.
"""
Expand Down
Loading
Loading