andelf / tronpy

TRON Python Client Library.
MIT License
204 stars 96 forks source link

LOCK_PERIOD is not included for delegate_resource #112

Closed clipcow closed 6 months ago

clipcow commented 10 months ago

I was not able to find a possibility to set lock_period for delegate_resource https://github.com/andelf/tronpy/blob/c8ebc870ac64afc80dcf764f59668b065555f63f/tronpy/tron.py#L454C5-L454C5

def delegate_resource( self, owner: TAddress, receiver: TAddress, balance: int, resource: str = "BANDWIDTH", lock: bool = False )

Only possible to set boolean for lock which defeaults to 3 days, but in the tron network additionally lock period can in practice be set, if im not incorrect from 30 Minutes to 30 Days

Here with delegation it is possible: https://developers.tron.network/reference/delegateresource-1

It would be good to add

newstar121 commented 10 months ago

Hi, clipcow. You can add parameter lock_period to set lock period as you want.

clipcow commented 10 months ago

Hi, clipcow. You can add parameter lock_period to set lock period as you want.

How so? The current implementation of resource delegation delegate_resource only takes these arguments: :param owner: :param receiver: :param balance: :param resource: Resource type, can be "ENERGY" or "BANDWIDTH" :param lock: Optionally lock delegated resources for 3 days.

There is NO parameter there to set the period, as its not the current implementation like on the core tron.network, where since mid 2023 its possible to set specific period from 30 min to 30 days. See on developer.tron.network where there is the current implementation

clipcow commented 10 months ago

Ouh wait I think I get it now... I can just change the payload and thats the whole fix for the issue right?

Like:

def delegate_resource(
        self, owner: TAddress, receiver: TAddress, balance: int, lock_period: int, resource: str = "BANDWIDTH", lock: bool = False
    ) -> "TransactionBuilder":
        """Delegate bandwidth or energy resources to other accounts in Stake2.0.

        :param owner:
        :param receiver:
        :param balance:
        :param resource: Resource type, can be ``"ENERGY"`` or ``"BANDWIDTH"``
        :param lock: Optionally lock delegated resources for 3 days.
        :param lock_period: Time for lock period
        """

        payload = {
            "owner_address": keys.to_hex_address(owner),
            "receiver_address": keys.to_hex_address(receiver),
            "balance": balance,
            "resource": resource,
            "lock": lock,
            "lock_period": lock_period
        }

        return self._build_transaction("DelegateResourceContract", payload)

Is this a working fix?

But I dont know how to try this out or how to submit an fix/pull request to github

newstar121 commented 10 months ago

Yes. Right.

def delegate_resource(
        self, owner: TAddress, receiver: TAddress, balance: int, lock_period: int, resource: str = "BANDWIDTH", lock: bool = False, lock_period: int
    ) -> "TransactionBuilder":

You can change tronpy library as above.

MaGua-Bishop commented 10 months ago

Whether you can provide a method to transfer energy, I call the function after the prompt delegateBalance must be greater than or equal to 1 TRX

But my address has energy and trx

MrNaif2018 commented 6 months ago

Added the lock_period param in latest commit, update coming soon