-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Copy link
Labels
Good First Issue CandidateIssues that can become a “good first issue” but need more description/context.Issues that can become a “good first issue” but need more description/context.
Description
Problem
The current Python SDK only accepts raw integer amounts (in tinybars) when during add_hbar_transfer transfers. It does not support passing an Hbar object directly. Users must manually convert HBAR values to tinybars.
Solution
- Allow
_add_hbar_transfer,add_hbar_transferandadd_approved_hbar_transferto acceptHbaras an input type.
def _add_hbar_transfer(self, account_id: AccountId, amount: Union[int, Hbar], is_approved: bool = False) -> "TransferTransaction":
...
def add_hbar_transfer(self, account_id: AccountId, amount: Union[int, Hbar]) -> "TransferTransaction":
...
def add_approved_hbar_transfer(self, account_id: AccountId, amount: Union[int, Hbar]) -> "TransferTransaction":
...- Internally normalize all amounts to tinybars.
def _add_hbar_transfer(
self, account_id: AccountId, amount: Union[int, Hbar], is_approved: bool = False
) -> "TransferTransaction":
...
if not isinstance(amount, (int, Hbar)):
raise ValueError("Amount must be of type int or Hbar.")
tinybar = amount if isinstance(amount, int) else amount.to_tinybars()
if tinybar == 0:
raise ValueError("Ammount must be a non zero value.")
for transfer in self.hbar_transfers:
if transfer.account_id == account_id:
transfer.amount += tinybar
return self
self.hbar_transfers.append(HbarTransfer(account_id, amount, is_approved))
return self- Create unit/integration test to validate the changes.
Alternatives
No response
exploreriii
Metadata
Metadata
Assignees
Labels
Good First Issue CandidateIssues that can become a “good first issue” but need more description/context.Issues that can become a “good first issue” but need more description/context.