Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tron.php and TransactoinBuilder.php #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LuisLACT10
Copy link

@LuisLACT10 LuisLACT10 commented Aug 19, 2021

$receiver_address was added to the parameters of freezeBalance and unfreezeBalance. The Tron developers documentation has a section where it explains how to freeze and unfreeze TRX.

The section of FreezeBalance describes that you can freeze an amount of TRX. Will give bandwidth OR Energy and TRON Power (voting rights) to the owner of the frozen tokens. Optionally, can freeze TRX to grant Energy or Bandwidth to other users. Balance amount in the denomination of Sun. The parameter for receiver_address is the address that will receive the resource.

The section of UnfreezeBalance describes TRX that has passed the minimum freeze duration. Unfreezing will remove bandwidth and TRON Power. Returns unfrozen TRX transaction. The parameter for receiver_address is the address that will lose the resource.

Tron.php:
/**
* Freezes an amount of TRX.
* Will give bandwidth OR Energy and TRON Power(voting rights) to the owner of the frozen tokens.
*
* @param float $amount
* @param int $duration
* @param string $resource
* @param string $owner_address
* @param string $receiver_address
* @return array
* @throws TronException
*/
public function freezeBalance(float $amount = 0, int $duration = 3, string $resource = 'BANDWIDTH', string $owner_address = null, string $receiver_address = null)
{
if($owner_address == null) {
$owner_address = $this->address['hex'];
}

    if($receiver_address == null){
        $receiver_address = "";
    }

    $freeze = $this->transactionBuilder->freezeBalance($amount, $duration, $resource, $owner_address, $receiver_address);
    $signedTransaction = $this->signTransaction($freeze);
    $response = $this->sendRawTransaction($signedTransaction);

    return array_merge($response, $signedTransaction);
}

/**
 * Unfreeze TRX that has passed the minimum freeze duration.
 * Unfreezing will remove bandwidth and TRON Power.
 *
 * @param string $resource
 * @param string $owner_address
 * @param string $receiver_address
 * @return array
 * @throws TronException
 */
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address = null, string $receiver_address = null)
{
    if($owner_address == null) {
        $owner_address = $this->address['hex'];
    }

    if($receiver_address == null){
        $receiver_address = "";
    }

    $unfreeze = $this->transactionBuilder->unfreezeBalance($resource, $owner_address,  $receiver_address);
    $signedTransaction = $this->signTransaction($unfreeze);
    $response = $this->sendRawTransaction($signedTransaction);

    return array_merge($response, $signedTransaction);
}

TransactionBuilder.php:
/**
* Freezes an amount of TRX.
* Will give bandwidth OR Energy and TRON Power(voting rights) to the owner of the frozen tokens.
*
* @param float $amount
* @param int $duration
* @param string $resource
* @param string|null $address
* @param string|null $receiver_address
* @return array
* @throws TronException
*/
public function freezeBalance(float $amount = 0, int $duration = 3, string $resource = 'BANDWIDTH', string $address, string $receiver_address)
{
if (!in_array($resource, ['BANDWIDTH', 'ENERGY'])) {
throw new TronException('Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"');
}

    if (!is_float($amount)) {
        throw new TronException('Invalid amount provided');
    }

    if(!is_integer($duration) and $duration < 3) {
        throw new TronException('Invalid duration provided, minimum of 3 days');
    }

    

    return $this->tron->getManager()->request('wallet/freezebalance', [
        'owner_address' => $this->tron->address2HexString($address),
        'receiver_address' => ($receiver_address === "")?$receiver_address:$this->tron->address2HexString($receiver_address),
        'frozen_balance' => $this->tron->toTron($amount),
        'frozen_duration' => $duration,
        'resource' => $resource
    ]);
}

/**
 * Unfreeze TRX that has passed the minimum freeze duration.
 * Unfreezing will remove bandwidth and TRON Power.
 *
 * @param string $resource
 * @param string $owner_address
 * @param string $receiver_address
 * @return array
 * @throws TronException
 */
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address, string $receiver_address)
{
    if (!in_array($resource, ['BANDWIDTH', 'ENERGY'])) {
        throw new TronException('Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"');
    }

    return $this->tron->getManager()->request('wallet/unfreezebalance', [
        'owner_address' =>  $this->tron->address2HexString($owner_address),
        'receiver_address' => ($receiver_address === "")?$receiver_address:$this->tron->address2HexString($receiver_address),
        'resource' => $resource
    ]);
}

$receiver_address was added to the parameters of freezeBalance and unfreezeBalance.  The Tron developers documentation has a section where it explains how to freeze and unfreeze TRX. 

The section of FreezeBalance describes that you can freeze an amount of TRX. Will give bandwidth OR Energy and TRON Power (voting rights) to the owner of the frozen tokens. Optionally, can freeze TRX to grant Energy or Bandwidth to other users. Balance amount in the denomination of Sun.  The parameter for receiver_address is the address that will receive the resource.

The section of UnfreezeBalance describes TRX that has passed the minimum freeze duration. Unfreezing will remove bandwidth and TRON Power. Returns unfrozen TRX transaction. The parameter for receiver_address is the address that will lose the resource.
$receiver_address was added to the parameters of freezeBalance and unfreezeBalance.  The Tron developers documentation has a section where it explains how to freeze and unfreeze TRX. 

The section of FreezeBalance describes that you can freeze an amount of TRX. Will give bandwidth OR Energy and TRON Power (voting rights) to the owner of the frozen tokens. Optionally, can freeze TRX to grant Energy or Bandwidth to other users. Balance amount in the denomination of Sun.  The parameter for receiver_address is the address that will receive the resource.

The section of UnfreezeBalance describes TRX that has passed the minimum freeze duration. Unfreezing will remove bandwidth and TRON Power. Returns unfrozen TRX transaction. The parameter for receiver_address is the address that will lose the resource.
@leexin
Copy link

leexin commented Oct 22, 2021

We need this too! Please merge to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants