Skip to content

Commit 0b1e7ac

Browse files
committed
feat: hbar support
Signed-off-by: prajeeta pal <prajeetapal@gmail.com>
1 parent 5fe2fde commit 0b1e7ac

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
77
## [Unreleased]
88

99
### Added
10+
1011
- Add examples/tokens/token_create_transaction_pause_key.py example demonstrating token pause/unpause behavior and pause key usage (#833)
1112
- Added `docs/sdk_developers/training/transaction_lifecycle.md` to explain the typical lifecycle of executing a transaction using the Hedera Python SDK.
1213
- Add inactivity bot workflow to unassign stale issue assignees (#952)
14+
- feat: Allow `add_hbar_transfer`, `add_approved_hbar_transfer`, and internal `_add_hbar_transfer` to accept `Hbar` objects in addition to raw tinybar integers, with internal normalization to tinybars. Added tests validating the new behavior.
15+
1316
### Changed
17+
1418
-
1519

1620
### Fixed
21+
1722
-
1823

1924
### Breaking Change
25+
2026
-
2127

2228
## [0.1.10] - 2025-12-03
2329

2430
### Added
31+
2532
- Added docs/sdk_developers/training/workflow: a training for developers to learn the workflow to contribute to the python SDK.
2633
- Added Improved NFT allowance deletion flow with receipt-based status checks and strict `SPENDER_DOES_NOT_HAVE_ALLOWANCE` verification.
2734
- Add `max_automatic_token_associations`, `staked_account_id`, `staked_node_id` and `decline_staking_reward` fields to `AccountUpdateTransaction` (#801)
@@ -30,8 +37,8 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
3037
- Added `.github/workflows/merge-conflict-bot.yml` to automatically detect and notify users of merge conflicts in Pull Requests.
3138
- Added `.github/workflows/bot-office-hours.yml` to automate the Weekly Office Hour Reminder.
3239
- feat: Implement account creation with EVM-style alias transaction example.
33-
- Added validation logic in `.github/workflows/pr-checks.yml` to detect when no new changelog entries are added under [Unreleased]
34-
- feat: Allow `add_hbar_transfer`, `add_approved_hbar_transfer`, and internal `_add_hbar_transfer` to accept `Hbar` objects in addition to raw tinybar integers, with internal normalization to tinybars. Added tests validating the new behavior.
40+
- Added validation logic in `.github/workflows/pr-checks.yml` to detect when no new changelog entries are added under [Unreleased].
41+
- Support for message chunking in `TopicSubmitMessageTransaction`.
3542

3643
### Changed
3744

@@ -41,7 +48,6 @@ This changelog is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.
4148
- feat: Add string representation method for `CustomFractionalFee` class and update `custom_fractional_fee.py` example.
4249
- Moved query examples to their respective domain folders to improve structure matching.
4350

44-
4551
### Fixed
4652

4753
- fixed workflow: changelog check with improved sensitivity to deletions, additions, new releases

src/hiero_sdk_python/transaction/transfer_transaction.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
Defines TransferTransaction for transferring HBAR or tokens between accounts.
33
"""
44

5-
from typing import Dict, List, Optional, Tuple
5+
from typing import Dict, List, Optional, Tuple, Union
66

77
from hiero_sdk_python.account.account_id import AccountId
88
from hiero_sdk_python.channels import _Channel
99
from hiero_sdk_python.executable import _Method
10+
from hiero_sdk_python.hbar import Hbar
1011
from hiero_sdk_python.hapi.services import basic_types_pb2, crypto_transfer_pb2, transaction_pb2
1112
from hiero_sdk_python.hapi.services.schedulable_transaction_body_pb2 import (
1213
SchedulableTransactionBody,
@@ -60,14 +61,14 @@ def _init_hbar_transfers(self, hbar_transfers: Dict[AccountId, int]) -> None:
6061
self.add_hbar_transfer(account_id, amount)
6162

6263
def _add_hbar_transfer(
63-
self, account_id: AccountId, amount: int, is_approved: bool = False
64+
self, account_id: AccountId, amount: Union[int, Hbar], is_approved: bool = False
6465
) -> "TransferTransaction":
6566
"""
6667
Internal method to add a HBAR transfer to the transaction.
6768
6869
Args:
6970
account_id (AccountId): The account ID of the sender or receiver.
70-
amount (int): The amount of the HBAR to transfer.
71+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
7172
is_approved (bool, optional): Whether the transfer is approved. Defaults to False.
7273
7374
Returns:
@@ -81,11 +82,13 @@ def _add_hbar_transfer(
8182
if amount is None:
8283
raise TypeError("amount cannot be None.")
8384

84-
if not isinstance(amount, int):
85-
raise TypeError("amount must be an integer.")
85+
if isinstance(amount, Hbar):
86+
amount = amount.to_tinybars()
87+
elif not isinstance(amount, int):
88+
raise TypeError("amount must be an integer or Hbar object.")
8689

8790
if amount == 0:
88-
raise ValueError("amount must be a non-zero integer.")
91+
raise ValueError("Amount must be a non-zero value.")
8992

9093
if not isinstance(is_approved, bool):
9194
raise TypeError("is_approved must be a boolean.")
@@ -95,17 +98,17 @@ def _add_hbar_transfer(
9598
transfer.amount += amount
9699
return self
97100

98-
self.hbar_transfers.append(
99-
HbarTransfer(account_id, amount, is_approved))
100-
return self
101+
self.hbar_transfers.append(
102+
HbarTransfer(account_id, amount, is_approved))
103+
return self
101104

102-
def add_hbar_transfer(self, account_id: AccountId, amount: int) -> "TransferTransaction":
105+
def add_hbar_transfer(self, account_id: AccountId, amount: Union[int, Hbar]) -> "TransferTransaction":
103106
"""
104107
Adds a HBAR transfer to the transaction.
105108
106109
Args:
107110
account_id (AccountId): The account ID of the sender or receiver.
108-
amount (int): The amount of the HBAR to transfer.
111+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
109112
110113
Returns:
111114
TransferTransaction: The current instance of the transaction for chaining.
@@ -114,14 +117,14 @@ def add_hbar_transfer(self, account_id: AccountId, amount: int) -> "TransferTran
114117
return self
115118

116119
def add_approved_hbar_transfer(
117-
self, account_id: AccountId, amount: int
120+
self, account_id: AccountId, amount: Union[int, Hbar]
118121
) -> "TransferTransaction":
119122
"""
120123
Adds a HBAR transfer with approval to the transaction.
121124
122125
Args:
123126
account_id (AccountId): The account ID of the sender or receiver.
124-
amount (int): The amount of the HBAR to transfer.
127+
amount (Union[int, Hbar]): The amount of the HBAR to transfer (in tinybars if int, or Hbar object).
125128
126129
Returns:
127130
TransferTransaction: The current instance of the transaction for chaining.

0 commit comments

Comments
 (0)