Skip to content

Commit

Permalink
Remove online sign and fix address
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Sep 27, 2020
1 parent 0b286ea commit e120f5b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 32 deletions.
6 changes: 5 additions & 1 deletion src/TransactionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ public function __construct(Tron $tron)
* @return array
* @throws TronException
*/
public function sendTrx($to, $amount, $from)
public function sendTrx($to, $amount, string $from = null)
{
if (!is_float($amount) || $amount < 0) {
throw new TronException('Invalid amount provided');
}

if(!is_null($from)) {
$from = $this->tron->address['hex'];
}

$to = $this->tron->address2HexString($to);
$from = $this->tron->address2HexString($from);

Expand Down
44 changes: 14 additions & 30 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace IEXBase\TronAPI;

use BN\BN;
use Elliptic\EC;
use IEXBase\TronAPI\Support\Base58;
use IEXBase\TronAPI\Support\Base58Check;
Expand All @@ -25,6 +26,7 @@
use IEXBase\TronAPI\Support\Utils;
use IEXBase\TronAPI\Provider\HttpProviderInterface;
use IEXBase\TronAPI\Exception\TronException;
use kornrunner\Secp256k1;

/**
* A PHP API for interacting with the Tron (TRX)
Expand Down Expand Up @@ -81,13 +83,6 @@ class Tron implements TronInterface
*/
protected $manager;

/**
* Online sign
*
* @var boolean
*/
protected $isOnlineSign = false;

/**
* Object Result
*
Expand Down Expand Up @@ -147,6 +142,15 @@ public static function make(?HttpProviderInterface $fullNode = null,
return new static($fullNode, $solidityNode, $eventServer, $signServer, $privateKey);
}

/**
* Фасад для Laravel
*
* @return Tron
*/
public function getFacade(): Tron {
return $this;
}

/**
* Enter the link to the manager nodes
*
Expand Down Expand Up @@ -239,18 +243,6 @@ public function setPrivateKey(string $privateKey): void
$this->privateKey = $privateKey;
}

/**
* Set online sign
*
* @param bool $sign
* @return Tron
*/
public function setIsOnlineSign(bool $sign): Tron
{
$this->isOnlineSign = $sign;
return $this;
}

/**
* Enter your account address
*
Expand Down Expand Up @@ -677,6 +669,7 @@ public function sendTransaction(string $to, float $amount, string $message= null
$transaction = $this->transactionBuilder->sendTrx($to, $amount, $from);
$signedTransaction = $this->signTransaction($transaction, $message);


$response = $this->sendRawTransaction($signedTransaction);
return array_merge($response, $signedTransaction);
}
Expand Down Expand Up @@ -737,17 +730,8 @@ public function signTransaction($transaction, string $message = null): array
$transaction['raw_data']['data'] = $this->stringUtf8toHex($message);
}

// Online sign tx
if ($this->isOnlineSign == true)
{
return $this->manager->request('wallet/gettransactionsign', [
'transaction' => $transaction,
'privateKey' => $this->privateKey
]);
}

$signature = Support\Secp::sign($transaction['txID'], $this->privateKey);

$transaction['signature'] = [$signature];

return $transaction;
Expand Down Expand Up @@ -1297,10 +1281,10 @@ public function getAccountResources(string $address = null)
/**
* Create a new account
*
* @return array
* @return TronAddress
* @throws TronException
*/
public function createAccount(): array
public function createAccount(): TronAddress
{
return $this->generateAddress();
}
Expand Down
1 change: 0 additions & 1 deletion src/TronAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace IEXBase\TronAPI;

use IEXBase\TronAPI\Support\{Base58Check, BigInteger, Keccak};

trait TronAwareTrait
{
/**
Expand Down

0 comments on commit e120f5b

Please sign in to comment.