From 9470081a6ae932496f71a964f222da150f8c07b8 Mon Sep 17 00:00:00 2001 From: ygcool <764990304@qq.com> Date: Wed, 13 Jul 2022 09:36:18 +0800 Subject: [PATCH 1/2] Fix add transaction message --- src/TransactionBuilder.php | 12 +++++++++--- src/Tron.php | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/TransactionBuilder.php b/src/TransactionBuilder.php index f940de5..2f70006 100644 --- a/src/TransactionBuilder.php +++ b/src/TransactionBuilder.php @@ -36,7 +36,7 @@ public function __construct(Tron $tron) * @return array * @throws TronException */ - public function sendTrx($to, $amount, string $from = null) + public function sendTrx($to, $amount, string $from = null, string $message = null) { if ($amount < 0) { throw new TronException('Invalid amount provided'); @@ -53,11 +53,17 @@ public function sendTrx($to, $amount, string $from = null) throw new TronException('Cannot transfer TRX to the same account'); } - $response = $this->tron->getManager()->request('wallet/createtransaction', [ + $params = [ 'to_address' => $to, 'owner_address' => $from, 'amount' => $this->tron->toTron($amount), - ]); + ]; + + if(!is_null($message)) { + $params['extra_data'] = $this->tron->stringUtf8toHex($message); + } + + $response = $this->tron->getManager()->request('wallet/createtransaction', $params); return $response; } diff --git a/src/Tron.php b/src/Tron.php index 9d51343..50149af 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -688,7 +688,7 @@ public function sendTransaction(string $to, float $amount, string $message= null $from = $this->address['hex']; } - $transaction = $this->transactionBuilder->sendTrx($to, $amount, $from); + $transaction = $this->transactionBuilder->sendTrx($to, $amount, $from, $message); $signedTransaction = $this->signTransaction($transaction, $message); From 5b2840e97af331ef5a4b484132f0fcedaed57687 Mon Sep 17 00:00:00 2001 From: ygcool <764990304@qq.com> Date: Fri, 15 Jul 2022 09:26:41 +0800 Subject: [PATCH 2/2] 1.Fix add transaction message 2.Fix bcmul err : is not well-formed --- src/Tron.php | 4 ++-- src/TronInterface.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Tron.php b/src/Tron.php index 50149af..7a2ac9d 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -675,14 +675,14 @@ public function getTransactionCount(): int * Send transaction to Blockchain * * @param string $to - * @param float $amount + * @param string $amount * @param string|null $message * @param string $from * * @return array * @throws TronException */ - public function sendTransaction(string $to, float $amount, string $message= null, string $from = null): array + public function sendTransaction(string $to, string $amount, string $message= null, string $from = null): array { if (is_null($from)) { $from = $this->address['hex']; diff --git a/src/TronInterface.php b/src/TronInterface.php index 32220e1..a1f0325 100644 --- a/src/TronInterface.php +++ b/src/TronInterface.php @@ -60,7 +60,7 @@ public function getTransactionCount(); * @return array * @throws TronException */ - public function sendTransaction(string $to, float $amount, string $from = null); + public function sendTransaction(string $to, string $amount, string $from = null); /** * Modify account name