hiero-ledger / hiero-ledger/hiero-sdk-python
`_add_token_transfer` silently ignores `is_approved` when merging transfers for the same account
- Dominant language
- Python
- Stars
- 63
- Forks
- 298
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 38
Description
### Description
When `_add_token_transfer()` is called multiple times for the same `(token_id, account_id)` pair, the transfer amount is accumulated correctly, but the `is_approved` flag is never updated in the accumulation branch.
This causes approved transfers to silently lose their approval state depending on call order.
Example:
```python
tx.add_token_transfer(token_a, sender, 500)
# is_approved=False (default)
tx.add_approved_token_transfer(token_a, sender, 200)
# expected accumulated transfer to become approved
### Steps to reproduce
1. Create a transaction.
2. Add a normal token transfer for a `(token_id, account_id)` pair.
3. Add an approved token transfer for the same `(token_id, account_id)` pair.
4. Inspect the accumulated transfer object.
Example:
```python
tx.add_token_transfer(token_a, sender, 500)
tx.add_approved_token_transfer(token_a, sender, 200)
```
Observed result:
```python
is_approved == False
```
Expected result:
```python
is_approved == True
```
### Additional context
Root cause appears to be inside `_add_token_transfer()` where the accumulation branch updates `amount` and `expected_decimals`, but never updates `is_approved`.
Current logic:
```python
for transfer in self.token_transfers[token_id]:
if transfer.account_id == account_id:
transfer.amount += amount
transfer.expected_decimals = expected_decimals
return
```
Suggested fix:
```python
transfer.is_approved = is_approved
```
before returning from the accumulation branch.
This can affect allowance-based transfer flows where regular and approved transfers are combined in the same transaction.
### Hedera network
_No response_
### Version
v0.2.5
### Operating system
None
Contributor guide
Assessment
This issue has not been assessed yet.