Skip to content

Commit

Permalink
Add lock_period to delegate_resource. Fixes andelf#112
Browse files Browse the repository at this point in the history
  • Loading branch information
MrNaif2018 committed Mar 15, 2024
1 parent 4893fa3 commit f8b38df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tronpy/async_tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,13 @@ def unfreeze_balance_legacy(
return self._build_transaction("UnfreezeBalanceContract", payload)

def delegate_resource(
self, owner: TAddress, receiver: TAddress, balance: int, resource: str = "BANDWIDTH", lock: bool = False
self,
owner: TAddress,
receiver: TAddress,
balance: int,
resource: str = "BANDWIDTH",
lock: bool = False,
lock_period: int = None,
) -> "AsyncTransactionBuilder":
"""Delegate bandwidth or energy resources to other accounts in Stake2.0.
Expand All @@ -470,6 +476,7 @@ def delegate_resource(
:param balance:
:param resource: Resource type, can be ``"ENERGY"`` or ``"BANDWIDTH"``
:param lock: Optionally lock delegated resources for 3 days.
:param lock_period: Optionally lock delegated resources for a specific period. Default: 3 days.
"""

payload = {
Expand All @@ -479,6 +486,8 @@ def delegate_resource(
"resource": resource,
"lock": lock,
}
if lock_period is not None:
payload["lock_period"] = lock_period

return self._build_transaction("DelegateResourceContract", payload)

Expand Down
11 changes: 10 additions & 1 deletion tronpy/tron.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ def unfreeze_balance_legacy(
return self._build_transaction("UnfreezeBalanceContract", payload)

def delegate_resource(
self, owner: TAddress, receiver: TAddress, balance: int, resource: str = "BANDWIDTH", lock: bool = False
self,
owner: TAddress,
receiver: TAddress,
balance: int,
resource: str = "BANDWIDTH",
lock: bool = False,
lock_period: int = None,
) -> "TransactionBuilder":
"""Delegate bandwidth or energy resources to other accounts in Stake2.0.
Expand All @@ -461,6 +467,7 @@ def delegate_resource(
:param balance:
:param resource: Resource type, can be ``"ENERGY"`` or ``"BANDWIDTH"``
:param lock: Optionally lock delegated resources for 3 days.
:param lock_period: Optionally lock delegated resources for a specific period. Default: 3 days.
"""

payload = {
Expand All @@ -470,6 +477,8 @@ def delegate_resource(
"resource": resource,
"lock": lock,
}
if lock_period is not None:
payload["lock_period"] = lock_period

return self._build_transaction("DelegateResourceContract", payload)

Expand Down

0 comments on commit f8b38df

Please sign in to comment.