Skip to content

Commit

Permalink
add toUtf8 and change listNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Nov 1, 2018
1 parent 10edb9b commit d33810b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 59 deletions.
57 changes: 19 additions & 38 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand All @@ -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)
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*
Expand Down
21 changes: 0 additions & 21 deletions src/TronInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down

0 comments on commit d33810b

Please sign in to comment.