Skip to content

Commit 7ffc7e4

Browse files
committed
feat: move node account ID selection to _Executable and update execution flow (#362)
Signed-off-by: Angelina <aceppaluni@gmail.com>
1 parent 13a542a commit 7ffc7e4

File tree

4 files changed

+30
-52
lines changed

4 files changed

+30
-52
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
6464
- Added expiration_time, auto_renew_period, auto_renew_account, fee_schedule_key, kyc_key in `TokenCreateTransaction`, `TokenUpdateTransaction` classes
6565
- Added comprehensive Google-style docstrings to the `CustomFee` class and its methods in `custom_fee.py`.
6666
- docs: Add `docs/sdk_developers/project_structure.md` to explain repository layout and import paths.
67-
- Support selecting specific node account ID(s) for queries and transactions (#362)
68-
- Added `Network._get_node()` method and updated execution flow to use node selection (#362)
67+
- Support selecting specific node account ID(s) for queries and transactions and added `Network._get_node()` with updated execution flow (#362)
6968

7069
### Changed
7170
- chore: bumped solo action from 14.0 to 15.0 (#764)

src/hiero_sdk_python/executable.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ def __init__(self):
7575
self._grpc_deadline = DEFAULT_GRPC_DEADLINE
7676
self.node_account_id = None
7777

78+
self.node_account_ids: Optional[List[AccountId]] = None
79+
self._used_node_account_id: Optional[AccountId] = None
80+
81+
def set_node_account_ids(self, node_account_ids: List[AccountId]):
82+
"""Select node account IDs for sending the request."""
83+
self.node_account_ids = node_account_ids
84+
return self
85+
86+
def set_node_account_id(self, node_account_id: AccountId):
87+
"""Convenience wrapper to set a single node account ID."""
88+
return self.set_node_account_ids([node_account_id])
89+
90+
def _select_node_account_id(self) -> Optional[AccountId]:
91+
"""Pick the first preferred node if available, otherwise None."""
92+
if self.node_account_ids:
93+
selected = self.node_account_ids[0]
94+
self._used_node_account_id = selected
95+
return selected
96+
return None
97+
7898
@abstractmethod
7999
def _should_retry(self, response) -> _ExecutionState:
80100
"""
@@ -177,13 +197,15 @@ def _execute(self, client: "Client"):
177197
current_backoff *= 2
178198

179199
# Select preferred node if provided, fallback to client's default
180-
selected_node_account_id = (
181-
self._select_node_account_id()
182-
or client.network.current_node._account_id
183-
)
184-
185-
self.node_account_id = selected_node_account_id
186-
node = client.network._get_node(self.node_account_id)
200+
selected = self._select_node_account_id()
201+
202+
if selected is not None:
203+
node = client.network._get_node(selected)
204+
else:
205+
node = client.network.current_node
206+
207+
#Store for logging and receipts
208+
self.node_account_id = node._account_id
187209

188210
# Create a channel wrapper from the client's channel
189211
channel = node._get_channel()

src/hiero_sdk_python/query/query.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -382,44 +382,4 @@ def _is_payment_required(self) -> bool:
382382
bool: True if payment is required, False otherwise
383383
"""
384384
return True
385-
386-
def set_node_account_ids(self, node_account_ids: List[AccountId]):
387-
"""
388-
Sets the list of node account IDs the query can be sent to.
389-
390-
Args:
391-
node_account_ids (List[AccountId]): The list of node account IDs.
392-
393-
Returns:
394-
Self: Returns self for method chaining.
395-
"""
396-
self.node_account_ids = node_account_ids
397-
return self
398-
399-
def set_node_account_id(self, node_account_id: AccountId):
400-
"""
401-
Sets a single node account ID the query will be sent to.
402-
403-
Args:
404-
node_account_id (AccountId): The node account ID.
405-
406-
Returns:
407-
Self: Returns self for method chaining.
408-
"""
409-
410-
return self.set_node_account_ids([node_account_id])
411-
412-
def _select_node_account_id(self) -> Optional[AccountId]:
413-
"""
414-
Internal method to select a node account ID to send the query to.
415-
Defaults to the first in the list.
416-
417-
Returns:
418-
Optional[AccountId]: The selected node account ID.
419-
"""
420-
if self.node_account_ids:
421-
selected = self.node_account_ids[0]
422-
self._used_node_account_id = selected
423-
return selected
424-
return None
425385

src/hiero_sdk_python/transaction/transaction.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ def __init__(self) -> None:
6161
self._default_transaction_fee = 2_000_000
6262
self.operator_account_id = None
6363

64-
self.node_account_ids: Optional[List[AccountId]] = None
65-
self._used_node_account_id: Optional[AccountId] = None
66-
6764
def _make_request(self):
6865
"""
6966
Implements the Executable._make_request method to build the transaction request.

0 commit comments

Comments
 (0)