hiero-ledger / hiero-ledger/hiero-sdk-python

Add `regenerate_transaction_id` to the Transaction class

Open
#2,643 7 comments 0 reactions 1 assignee Claimed by @iron-prog View on GitHub
approved python skill: advanced
Dominant language
Python
Stars
63
Forks
298
Avg merge
3d 18h
Merged PRs (30d)
38

Description

**Description**

Add `regenerate_transaction_id` support to the `Transaction` class, bringing the Python SDK closer with the transaction ID regeneration behavior supported by the other SDKs.

Specifically, add:

- `set_regenerate_transaction_id()`
- `regenerate_transaction_id`
-
This support is also required by the TCK `CommonTransactionParams`, which receive `regenerateTransactionId` parameter through JSON-RPC request parameters.

**Proposed Solution**

- [ ] Add the `regenerate_transaction_id` property to Transaction
```python
def __init__(self) -> None:
...
self._regenerate_transaction_id: bool | None = None
...

@proprty
def regenerate_transaction_id(self) -> bool | None:
return self._regenerate_transaction_id
```
- [ ] Add the setter for the regenerate transaction id
```python
def set_regenerate_transaction_id(self, value: bool):
self._regenerate_transaction_id = value
return self
```
- [ ] Update the transaction retry/expiration handling so that `TRANSACTION_EXPIRED` triggers a retry when transaction ID regeneration is enabled.
```python
def _should_retry(self, response):
...
if status == ResponseCode.TRANSACTION_EXPIRED:
# Regenerate the transaction ID and retry if enabled.
if self.regenerate_transaction_id:
self._handle_transaction_id_regeneration()
return _ExecutionState.RETRY

# Transaction ID regeneration is disabled.
return _ExecutionState.EXPIRED
...
```
- [ ] Create `_handle_transaction_id_regeneration` method to generate new transactionId.
```python
def _handle_transaction_id_regeneration(self):
# unlock the transaction_ids list
new_trasnaction_id = TransactionId.generate(client.operator_account_id)
# transaction_ids.set(transaction_ids.index, new_transaction_id);
# lock the transaction_ids list
return self
```

- [ ] Add the `default_regenerate_transaction_id: bool = True` to Client, default value `True`.
- [ ] Add setter in the Client to `set_default_regenerate_transaction_id()`.
- [ ] Update the `freeze_with()` method to to resolve the regenerate_transaction_id
```python
self._regenerate_transaction_id = ( self._regenerate_transaction_id if self._regenerate_transaction_id is not None else client.default_regenerate_transaction_id )
```
- [ ] Add unit/integration test to validate the changes

**Acceptance Criteria**

- [ ] `Transaction` exposes a `regenerate_transaction_id` property.
- [ ] `Transaction` provides a fluent `set_regenerate_transaction_id(bool)` method.
- [ ] The transaction-level setting takes precedence over the client-level default.
- [ ] `Client` provides `default_regenerate_transaction_id`, with a default value of `True`.
- [ ] When no transaction-level value is configured, `freeze_with()` uses `Client.default_regenerate_transaction_id`.
- [ ] When `TRANSACTION_EXPIRED` is received and transaction ID regeneration is enabled, a new transaction ID is generated and the transaction is retried.
- [ ] The newly generated transaction ID uses the client's operator account ID.
- [ ] Existing transaction IDs are correctly replaced with the newly generated transaction ID(s).
- [ ] Transaction ID locking is preserved correctly during regeneration.
- [ ] When transaction ID regeneration is disabled, `TRANSACTION_EXPIRED` results in `_ExecutionState.EXPIRED` and the transaction is not retried.

**Note**
Once this issue is resolved, create a separate follow-up issue to update `apply_common_params()` to handle the `regenerateTransactionId` parameter from `CommonTransactionParams` and apply it to the transaction using `set_regenerate_transaction_id()`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.