Skip to content

Commit cd30c5d

Browse files
committed
feat: update node account selection and docstring
Signed-off-by: Angelina <[email protected]>
1 parent b1d4ed0 commit cd30c5d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
5454
- Approved transfer support to TransferTransaction
5555
- set_transaction_id() API to Transaction class
5656
- Allowance examples (hbar_allowance.py, token_allowance.py, nft_allowance.py)
57+
- `set_node_account_ids` method for setting node account IDs in transactions.
58+
- Updated `_select_node_account_id` to clarify behavior in docstring.
5759

5860
### Changed
5961

src/hiero_sdk_python/transaction/transaction.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,3 +485,50 @@ def set_transaction_id(self, transaction_id: TransactionId):
485485
self._require_not_frozen()
486486
self.transaction_id = transaction_id
487487
return self
488+
489+
def set_node_account_ids(self, node_account_ids, List[AccountId]):
490+
"""
491+
Sets the list of node account IDs the query can be sent to.
492+
493+
Args:
494+
node_account_ids (List[AccountId]): The list of node account IDs.
495+
496+
Returns:
497+
Self: Returns self for method chaining.
498+
"""
499+
500+
self.node_account_ids = node_account_ids
501+
return self
502+
503+
def set_node_account_id(self, node_account_id: AccountId):
504+
"""
505+
Selects a node account ID to use for sending a query.
506+
507+
Args:
508+
node_account_id (AccountId): The node account ID.
509+
510+
Returns:
511+
Self: Returns self for method chaining.
512+
"""
513+
514+
return self.set_node_account_ids([node_account_id])
515+
516+
def _select_node_account_id(self) -> Optional[AccountId]:
517+
"""
518+
Selects a node account ID to use for sending a query.
519+
520+
Picks the first unused node from `self.node_account_ids`.
521+
Once used, stores it in `_used_node_account_id`.
522+
523+
Returns:
524+
Optional[AccountId]: The selected node account ID, or None if no IDs are available.
525+
"""
526+
if not self.node_account_ids:
527+
return None
528+
529+
if hasattr(self, '_last_used_index'):
530+
self._last_used_index = (self._last_used_index + 1) % len(self.node_account_ids)
531+
else:
532+
self._last_used_index = 0
533+
self._used_node_account_id = self.node_account_ids[self._last_used_index]
534+
return self._used_node_account_id

0 commit comments

Comments
 (0)