From d33810b095cd009318e9b2f5a2d8c5c94e5b7efb Mon Sep 17 00:00:00 2001 From: serderovsh Date: Thu, 1 Nov 2018 05:56:26 +0300 Subject: [PATCH] add toUtf8 and change listNodes --- src/Tron.php | 57 +++++++++++++++---------------------------- src/TronInterface.php | 21 ---------------- 2 files changed, 19 insertions(+), 59 deletions(-) diff --git a/src/Tron.php b/src/Tron.php index 31a7902..e937984 100644 --- a/src/Tron.php +++ b/src/Tron.php @@ -643,6 +643,7 @@ public function changeAccountName(string $address = null, string $account_name) * * @param array $args * @return array + * @throws TronException */ public function sendToken(...$args): array { return $this->createSendAssetTransaction(...$args); @@ -764,8 +765,6 @@ public function createSendAssetTransaction($to, $amount, $tokenID, $from = null) throw new TronException('Invalid token ID provided'); } - - $transfer = $this->fullNode->request('wallet/transferasset', [ 'owner_address' => $this->toHex($from), 'to_address' => $this->toHex($to), @@ -779,41 +778,6 @@ public function createSendAssetTransaction($to, $amount, $tokenID, $from = null) return array_merge($response, $signedTransaction); } - /** - * Easily transfer from an address using the password string. - * Only works with accounts created from createAddress - * - * @param string $to - * @param float $amount - * @param string $password - * @return array - */ - public function sendTransactionByPassword(string $to, float $amount, string $password): array - { - return $this->fullNode->request('wallet/easytransfer', [ - 'passPhrase' => $this->stringUtf8toHex($password), - 'toAddress' => $this->toHex($to), - 'amount' => $this->toTron($amount) - ],'post'); - } - - /** - * Easily transfer from an address using the private key. - * - * @param string $to - * @param float $amount - * @param string $privateKey - * @return array - */ - public function sendTransactionByPrivateKey(string $to, float $amount, string $privateKey): array - { - return $this->fullNode->request('wallet/easytransferbyprivate', [ - 'privateKey' => $this->stringUtf8toHex($privateKey), - 'toAddress' => $this->toHex($to), - 'amount' => $this->toTron($amount) - ],'post'); - } - /** * Create address from a specified password string (NOT PRIVATE KEY) * @@ -932,9 +896,16 @@ public function createUpdateAssetTransaction($address, $description, $url, $band */ public function listNodes(): array { - return $this->fullNode->request('wallet/listnodes'); + $nodes = $this->fullNode->request('wallet/listnodes'); + + return array_map(function($item) { + $address = $item['address']; + + return sprintf('%s:%s', $this->toUtf8($address['host']), $address['port']); + }, $nodes['nodes']); } + /** * List the tokens issued by an account. * @@ -1207,6 +1178,16 @@ public function getNodeMap(): array return $this->tronNode->request('api/v2/node/nodemap'); } + /** + * Helper function that will convert HEX to UTF8 + * + * @param $str + * @return string + */ + public function toUtf8($str): string { + return pack('H*', $str); + } + /** * Check all connected nodes * diff --git a/src/TronInterface.php b/src/TronInterface.php index 8f6eafb..59bd6bd 100644 --- a/src/TronInterface.php +++ b/src/TronInterface.php @@ -102,27 +102,6 @@ public function applyForSuperRepresentative(string $address, string $url); */ public function createSendAssetTransaction($from, $to, $assetID, $amount); - /** - * Easily transfer from an address using the password string. - * Only works with accounts created from createAddress - * - * @param string $to - * @param float $amount - * @param string $password - * @return array - */ - public function sendTransactionByPassword(string $to, float $amount, string $password); - - /** - * Easily transfer from an address using the private key. - * - * @param string $to - * @param float $amount - * @param string $privateKey - * @return array - */ - public function sendTransactionByPrivateKey(string $to, float $amount, string $privateKey); - /** * Create address from a specified password string (NOT PRIVATE KEY) *