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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ public function createToken($options = [], $issuerAddress = null)
* @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)
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"');
Expand All @@ -269,6 +270,7 @@ public function freezeBalance(float $amount = 0, int $duration = 3, string $reso

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
Expand All @@ -281,17 +283,19 @@ public function freezeBalance(float $amount = 0, int $duration = 3, string $reso
*
* @param string $resource
* @param string $owner_address
* @param string $receiver_address
* @return array
* @throws TronException
*/
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address)
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
]);
}
Expand Down
18 changes: 14 additions & 4 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -952,16 +952,21 @@ public function purchaseToken($issuerAddress, $tokenID, $amount, $buyer = null)
* @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)
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);
$freeze = $this->transactionBuilder->freezeBalance($amount, $duration, $resource, $owner_address, $receiver_address);
$signedTransaction = $this->signTransaction($freeze);
$response = $this->sendRawTransaction($signedTransaction);

Expand All @@ -974,16 +979,21 @@ public function freezeBalance(float $amount = 0, int $duration = 3, string $reso
*
* @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)
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);
$unfreeze = $this->transactionBuilder->unfreezeBalance($resource, $owner_address, $receiver_address);
$signedTransaction = $this->signTransaction($unfreeze);
$response = $this->sendRawTransaction($signedTransaction);

Expand Down