Skip to content

Commit

Permalink
added message
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Nov 4, 2018
1 parent d33810b commit dfed4c7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,19 +515,20 @@ public function getTransactionCount(): int
*
* @param string $to
* @param float $amount
* @param string|null $message
* @param string $from
*
* @return array
* @throws TronException
*/
public function sendTransaction(string $to, float $amount, string $from = null): array
public function sendTransaction(string $to, float $amount, string $message= null, string $from = null): array
{
if (is_null($from)) {
$from = $this->address;
}

$transaction = $this->createTransaction($from, $to, $amount);
$signedTransaction = $this->signTransaction($transaction);
$signedTransaction = $this->signTransaction($transaction, $message);
$response = $this->sendRawTransaction($signedTransaction);

return array_merge($response, $signedTransaction);
Expand Down Expand Up @@ -570,10 +571,11 @@ protected function createTransaction(string $from, string $to, float $amount): a
* please make sure to call the api in a secure environment
*
* @param $transaction
* @param string|null $message
* @return array
* @throws TronException
*/
protected function signTransaction($transaction): array
protected function signTransaction($transaction, string $message = null): array
{
if(!$this->privateKey) {
throw new TronException('Missing private key');
Expand All @@ -587,6 +589,10 @@ protected function signTransaction($transaction): array
throw new TronException('Transaction is already signed');
}

if(!is_null($message)) {
$transaction['raw_data']['data'] = $this->stringUtf8toHex($message);
}

return $this->fullNode->request('wallet/gettransactionsign', [
'transaction' => $transaction,
'privateKey' => $this->privateKey
Expand Down

0 comments on commit dfed4c7

Please sign in to comment.