Skip to content

Commit 5fe2fde

Browse files
committed
fix: hbar support errors
Signed-off-by: prajeeta pal <prajeetapal@gmail.com>
1 parent 70c5b1f commit 5fe2fde

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/hiero_sdk_python/tokens/abstract_token_transfer_transaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def _add_token_transfer(
149149
if not isinstance(account_id, AccountId):
150150
raise TypeError("account_id must be an AccountId instance.")
151151
if not isinstance(amount, int) or amount == 0:
152-
raise ValueError("Amount must be a non-zero value.")
152+
raise ValueError("Amount must be a integer.")
153+
if amount == 0:
154+
raise ValueError("amount must be a non-zero value.")
153155
if expected_decimals is not None and not isinstance(expected_decimals, int):
154156
raise TypeError("expected_decimals must be an integer.")
155157
if not isinstance(is_approved, bool):

src/hiero_sdk_python/transaction/transfer_transaction.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(
2929
self,
3030
hbar_transfers: Optional[Dict[AccountId, int]] = None,
3131
token_transfers: Optional[Dict[TokenId, Dict[AccountId, int]]] = None,
32-
nft_transfers: Optional[Dict[TokenId, List[Tuple[AccountId, AccountId, int, bool]]]] = None,
32+
nft_transfers: Optional[Dict[TokenId,
33+
List[Tuple[AccountId, AccountId, int, bool]]]] = None,
3334
) -> None:
3435
"""
3536
Initializes a new TransferTransaction instance.
@@ -73,10 +74,19 @@ def _add_hbar_transfer(
7374
TransferTransaction: The current instance of the transaction for chaining.
7475
"""
7576
self._require_not_frozen()
77+
7678
if not isinstance(account_id, AccountId):
7779
raise TypeError("account_id must be an AccountId instance.")
78-
if not isinstance(amount, int) or amount == 0:
79-
raise ValueError("Amount must be a non-zero integer.")
80+
81+
if amount is None:
82+
raise TypeError("amount cannot be None.")
83+
84+
if not isinstance(amount, int):
85+
raise TypeError("amount must be an integer.")
86+
87+
if amount == 0:
88+
raise ValueError("amount must be a non-zero integer.")
89+
8090
if not isinstance(is_approved, bool):
8191
raise TypeError("is_approved must be a boolean.")
8292

@@ -85,8 +95,9 @@ def _add_hbar_transfer(
8595
transfer.amount += amount
8696
return self
8797

88-
self.hbar_transfers.append(HbarTransfer(account_id, amount, is_approved))
89-
return self
98+
self.hbar_transfers.append(
99+
HbarTransfer(account_id, amount, is_approved))
100+
return self
90101

91102
def add_hbar_transfer(self, account_id: AccountId, amount: int) -> "TransferTransaction":
92103
"""
@@ -190,7 +201,8 @@ def _from_protobuf(cls, transaction_body, body_bytes: bytes, sig_map):
190201

191202
if crypto_transfer.HasField("transfers"):
192203
for account_amount in crypto_transfer.transfers.accountAmounts:
193-
account_id = AccountId._from_proto(account_amount.accountID)
204+
account_id = AccountId._from_proto(
205+
account_amount.accountID)
194206
amount = account_amount.amount
195207
is_approved = account_amount.is_approval
196208
transaction.hbar_transfers.append(
@@ -210,17 +222,21 @@ def _from_protobuf(cls, transaction_body, body_bytes: bytes, sig_map):
210222
expected_decimals = token_transfer_list.expected_decimals.value
211223

212224
transaction.token_transfers[token_id].append(
213-
TokenTransfer(token_id, account_id, amount, expected_decimals, is_approved)
225+
TokenTransfer(token_id, account_id, amount,
226+
expected_decimals, is_approved)
214227
)
215228

216229
for nft_transfer in token_transfer_list.nftTransfers:
217-
sender_id = AccountId._from_proto(nft_transfer.senderAccountID)
218-
receiver_id = AccountId._from_proto(nft_transfer.receiverAccountID)
230+
sender_id = AccountId._from_proto(
231+
nft_transfer.senderAccountID)
232+
receiver_id = AccountId._from_proto(
233+
nft_transfer.receiverAccountID)
219234
serial_number = nft_transfer.serialNumber
220235
is_approved = nft_transfer.is_approval
221236

222237
transaction.nft_transfers[token_id].append(
223-
TokenNftTransfer(token_id, sender_id, receiver_id, serial_number, is_approved)
238+
TokenNftTransfer(
239+
token_id, sender_id, receiver_id, serial_number, is_approved)
224240
)
225241

226242
return transaction

0 commit comments

Comments
 (0)