From dc62c67875b00708eff4c03626ce837af68bc4ae Mon Sep 17 00:00:00 2001 From: Lee Xin Date: Tue, 20 Dec 2022 22:13:54 +0800 Subject: [PATCH] Revert "Support PHP 8" This reverts commit 74b8b386028e1dd89b6e6c740e21ed18c4f6a599. --- composer.json | 2 +- src/Concerns/ManagesUniversal.php | 2 +- src/TransactionBuilder.php | 32 ++++++++----------------------- src/Tron.php | 8 ++++---- 4 files changed, 14 insertions(+), 30 deletions(-) diff --git a/composer.json b/composer.json index ba13b3c..d30bd43 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Concerns/ManagesUniversal.php b/src/Concerns/ManagesUniversal.php index 0e08555..1a032eb 100644 --- a/src/Concerns/ManagesUniversal.php +++ b/src/Concerns/ManagesUniversal.php @@ -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; diff --git a/src/TransactionBuilder.php b/src/TransactionBuilder.php index 1403a7c..f940de5 100644 --- a/src/TransactionBuilder.php +++ b/src/TransactionBuilder.php @@ -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'); @@ -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; } /** @@ -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"'); } @@ -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"'); } @@ -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'); } diff --git a/src/Tron.php b/src/Tron.php index 5ff3d21..9d51343 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -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);