Skip to content

Commit

Permalink
Revert "Support PHP 8"
Browse files Browse the repository at this point in the history
This reverts commit 74b8b38.
  • Loading branch information
leexin committed Dec 20, 2022
1 parent 11445ea commit dc62c67
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],

"require": {
"php": ">=7.4",
"php": "^7.4",
"comely-io/data-types": "^1.0",
"guzzlehttp/guzzle": "^7.0",
"iexbase/web3.php": "^2.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/ManagesUniversal.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function balances(array $accounts, $isValid = false): array
* @return array
* @throws ErrorException
*/
public function sendOneToMany(array $to, $private_key = null, bool $isValid = false, string $from = null): array
public function sendOneToMany(array $to, $private_key = null, $isValid = false, string $from): array
{
if(!is_null($private_key)) {
$this->privateKey = $private_key;
Expand Down
32 changes: 8 additions & 24 deletions src/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ public function __construct(Tron $tron)
*
* @param string $to
* @param float $amount
* @param string|null $from
* @param string|null $message
* @param string $from
* @return array
* @throws TronException
*/
public function sendTrx(string $to, float $amount, string $from = null, string $message = null)
public function sendTrx($to, $amount, string $from = null)
{
if ($amount < 0) {
throw new TronException('Invalid amount provided');
Expand All @@ -54,17 +53,13 @@ public function sendTrx(string $to, float $amount, string $from = null, string $
throw new TronException('Cannot transfer TRX to the same account');
}

$options = [
$response = $this->tron->getManager()->request('wallet/createtransaction', [
'to_address' => $to,
'owner_address' => $from,
'amount' => $this->tron->toTron($amount),
];

if(!is_null($message)) {
$params['extra_data'] = $this->tron->stringUtf8toHex($message);
}
]);

return $this->tron->getManager()->request('wallet/createtransaction', $options);
return $response;
}

/**
Expand Down Expand Up @@ -258,11 +253,8 @@ public function createToken($options = [], $issuerAddress = null)
* @return array
* @throws TronException
*/
public function freezeBalance(float $amount = 0, int $duration = 3, string $resource = 'BANDWIDTH', string $address = null)
public function freezeBalance(float $amount = 0, int $duration = 3, string $resource = 'BANDWIDTH', string $address)
{
if(empty($address))
throw new TronException('Address not specified');

if (!in_array($resource, ['BANDWIDTH', 'ENERGY'])) {
throw new TronException('Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"');
}
Expand Down Expand Up @@ -292,12 +284,8 @@ public function freezeBalance(float $amount = 0, int $duration = 3, string $reso
* @return array
* @throws TronException
*/
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address = null)
public function unfreezeBalance(string $resource = 'BANDWIDTH', string $owner_address)
{
if(is_null($owner_address)) {
throw new TronException('Owner Address not specified');
}

if (!in_array($resource, ['BANDWIDTH', 'ENERGY'])) {
throw new TronException('Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"');
}
Expand Down Expand Up @@ -338,12 +326,8 @@ public function withdrawBlockRewards($owner_address = null)
* @return array
* @throws TronException
*/
public function updateToken(string $description, string $url, int $freeBandwidth = 0, int $freeBandwidthLimit = 0, $address = null)
public function updateToken(string $description, string $url, int $freeBandwidth = 0, int $freeBandwidthLimit = 0, $address)
{
if(is_null($address)) {
throw new TronException('Owner Address not specified');
}

if (!is_integer($freeBandwidth) || $freeBandwidth < 0) {
throw new TronException('Invalid free bandwidth amount provided');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,19 +677,19 @@ public function getTransactionCount(): int
* @param string $to
* @param float $amount
* @param string|null $message
* @param string|null $from
* @param string $from
*
* @return array
* @throws TronException
*/
public function sendTransaction(string $to, float $amount, string $from = null, string $message = null): array
public function sendTransaction(string $to, float $amount, string $message= null, string $from = null): array
{
if (is_null($from)) {
$from = $this->address['hex'];
}

$transaction = $this->transactionBuilder->sendTrx($to, $amount, $from, $message);
$signedTransaction = $this->signTransaction($transaction);
$transaction = $this->transactionBuilder->sendTrx($to, $amount, $from);
$signedTransaction = $this->signTransaction($transaction, $message);


$response = $this->sendRawTransaction($signedTransaction);
Expand Down

0 comments on commit dc62c67

Please sign in to comment.