diff --git a/src/TransactionBuilder.php b/src/TransactionBuilder.php index a2415c5..e381825 100644 --- a/src/TransactionBuilder.php +++ b/src/TransactionBuilder.php @@ -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); diff --git a/src/Tron.php b/src/Tron.php index 2e5a88a..eecdc49 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -16,6 +16,7 @@ namespace IEXBase\TronAPI; +use BN\BN; use Elliptic\EC; use IEXBase\TronAPI\Support\Base58; use IEXBase\TronAPI\Support\Base58Check; @@ -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) @@ -81,13 +83,6 @@ class Tron implements TronInterface */ protected $manager; - /** - * Online sign - * - * @var boolean - */ - protected $isOnlineSign = false; - /** * Object Result * @@ -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 * @@ -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 * @@ -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); } @@ -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; @@ -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(); } diff --git a/src/TronAwareTrait.php b/src/TronAwareTrait.php index 8223ebf..66711fa 100644 --- a/src/TronAwareTrait.php +++ b/src/TronAwareTrait.php @@ -3,7 +3,6 @@ namespace IEXBase\TronAPI; use IEXBase\TronAPI\Support\{Base58Check, BigInteger, Keccak}; - trait TronAwareTrait { /**