Skip to content

Commit ea4255f

Browse files
Merge branch 'main' into dependabot/pip/cryptography-gte-44.0.1-and-lt-48
2 parents 5df9b6e + fd13539 commit ea4255f

5 files changed

Lines changed: 428 additions & 15 deletions

File tree

src/hiero_sdk_python/query/transaction_get_receipt_query.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,22 @@ def _map_status_error(self, response: response_pb2.Response) -> PrecheckError |
277277
TransactionReceipt._from_proto(response.transactionGetReceipt.receipt, self.transaction_id),
278278
)
279279

280-
def _map_receipt_list(self, receipts: list[transaction_receipt_pb2.TransactionReceipt]) -> list[TransactionReceipt]:
280+
def _map_receipt_list(
281+
self, receipts: list[transaction_receipt_pb2.TransactionReceipt], include_parent_tx_id: bool = False
282+
) -> list[TransactionReceipt]:
281283
"""
282284
Maps a list of protobuf transaction receipts to TransactionReceipt objects.
283285
284286
Args:
285287
receipts: A list of protobuf TransactionReceipt objects
288+
include_parent_tx_id: If True, pass parent transaction_id to mapped receipts (for duplicates).
289+
If False, pass None (for child receipts).
286290
287291
Returns:
288292
A list of TransactionReceipt objects
289293
"""
290-
return [TransactionReceipt._from_proto(receipt_proto, self.transaction_id) for receipt_proto in receipts]
294+
transaction_id = self.transaction_id if include_parent_tx_id else None
295+
return [TransactionReceipt._from_proto(receipt_proto, transaction_id) for receipt_proto in receipts]
291296

292297
def execute(self, client: Client, timeout: int | float | None = None) -> TransactionReceipt:
293298
"""
@@ -315,12 +320,18 @@ def execute(self, client: Client, timeout: int | float | None = None) -> Transac
315320
parent = TransactionReceipt._from_proto(response.transactionGetReceipt.receipt, self.transaction_id)
316321

317322
if self.include_children:
318-
children = self._map_receipt_list(response.transactionGetReceipt.child_transaction_receipts)
323+
# Child receipts are sub-transactions; they don't need parent transaction_id
324+
children = self._map_receipt_list(
325+
response.transactionGetReceipt.child_transaction_receipts, include_parent_tx_id=False
326+
)
319327

320328
parent._set_children(children)
321329

322330
if self.include_duplicates:
323-
duplicates = self._map_receipt_list(response.transactionGetReceipt.duplicateTransactionReceipts)
331+
# Duplicate receipts are related to parent; keep parent transaction_id for context
332+
duplicates = self._map_receipt_list(
333+
response.transactionGetReceipt.duplicateTransactionReceipts, include_parent_tx_id=True
334+
)
324335

325336
parent._set_duplicates(duplicates)
326337

src/hiero_sdk_python/transaction/transaction_receipt.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ def account_id(self) -> AccountId | None:
8888
"""
8989
Retrieves the AccountId associated with the transaction receipt, if available.
9090
91+
Unlike other ID properties (token_id, file_id, etc.), this returns the AccountId
92+
even when accountNum is 0. This is intentional to support EVM auto-account creation
93+
scenarios where the protobuf may contain an AccountID with num=0 to identify the
94+
newly created account before it's fully initialized on-chain.
95+
9196
Returns:
92-
AccountId or None: The AccountId if present; otherwise, None.
97+
AccountId or None: The AccountId if present (including num=0); otherwise, None.
9398
"""
94-
if self._receipt_proto.HasField("accountID") and self._receipt_proto.accountID.accountNum != 0:
99+
if self._receipt_proto.HasField("accountID"):
95100
return AccountId._from_proto(self._receipt_proto.accountID)
96101
return None
97102

@@ -107,7 +112,9 @@ def serial_numbers(self) -> list[int]:
107112

108113
@property
109114
def file_id(self) -> FileId | None:
110-
"""Returns the file ID associated with this receipt."""
115+
"""
116+
Returns the file ID associated with this receipt.
117+
"""
111118
if self._receipt_proto.HasField("fileID") and self._receipt_proto.fileID.fileNum != 0:
112119
return FileId._from_proto(self._receipt_proto.fileID)
113120
return None
@@ -243,14 +250,14 @@ def _to_proto(self):
243250

244251
@classmethod
245252
def _from_proto(
246-
cls, proto: transaction_receipt_pb2.TransactionReceipt, transaction_id: TransactionId
253+
cls, proto: transaction_receipt_pb2.TransactionReceipt, transaction_id: TransactionId | None
247254
) -> TransactionReceipt:
248255
"""
249256
Creates a TransactionReceipt instance from a protobuf TransactionReceipt object.
250257
251258
Args:
252259
proto (transaction_receipt_pb2.TransactionReceipt): The protobuf TransactionReceipt object.
253-
transaction_id (TransactionId): The transaction ID associated with this receipt.
260+
transaction_id (TransactionId | None): The transaction ID associated with this receipt. Can be None for child receipts.
254261
255262
Returns:
256263
TransactionReceipt: A new instance of TransactionReceipt populated with data from the protobuf object.

tests/integration/account_records_query_e2e_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ def test_integration_account_record_query_can_execute(env):
2020
account = env.create_account()
2121

2222
# Perform transfer transaction
23+
transfer_tx = TransferTransaction()
24+
transfer_tx.transaction_fee = Hbar(2).to_tinybars()
2325
transfer_receipt = (
24-
TransferTransaction()
25-
.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
26+
transfer_tx.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
2627
.add_hbar_transfer(env.operator_id, -Hbar(1).to_tinybars())
2728
.execute(env.client)
2829
)
@@ -50,9 +51,10 @@ def test_integration_account_record_query_get_cost(env):
5051
"""Test that AccountRecordsQuery can calculate query costs."""
5152
account = env.create_account()
5253

54+
transfer_tx = TransferTransaction()
55+
transfer_tx.transaction_fee = Hbar(2).to_tinybars()
5356
transfer_receipt = (
54-
TransferTransaction()
55-
.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
57+
transfer_tx.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
5658
.add_hbar_transfer(env.operator_id, -Hbar(1).to_tinybars())
5759
.execute(env.client)
5860
)
@@ -75,9 +77,10 @@ def test_integration_account_record_query_insufficient_payment(env):
7577
"""Test that AccountRecordsQuery fails with insufficient payment."""
7678
account = env.create_account()
7779

80+
transfer_tx = TransferTransaction()
81+
transfer_tx.transaction_fee = Hbar(2).to_tinybars()
7882
transfer_receipt = (
79-
TransferTransaction()
80-
.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
83+
transfer_tx.add_hbar_transfer(account.id, Hbar(1).to_tinybars())
8184
.add_hbar_transfer(env.operator_id, -Hbar(1).to_tinybars())
8285
.execute(env.client)
8386
)

0 commit comments

Comments
 (0)