Skip to content

Commit

Permalink
added support explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Jul 23, 2019
1 parent b5d0503 commit 2272b60
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
24 changes: 24 additions & 0 deletions src/Concerns/ManagesTronscan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
namespace IEXBase\TronAPI\Concerns;


use IEXBase\TronAPI\Exception\TronException;

trait ManagesTronscan
{
/**
* Transactions from explorer
*
* @param array $options
* @return array
* @throws TronException
*/
public function getTransactionByAddress($options = [])
{
if(empty($options)) {
throw new TronException('Parameters must not be empty.');
}

return $this->manager->request('api/transaction', $options);
}
}
8 changes: 6 additions & 2 deletions src/Tron.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
class Tron implements TronInterface
{
use TronAwareTrait,
Concerns\ManagesUniversal;
Concerns\ManagesUniversal,
Concerns\ManagesTronscan;

/**
* Default Address
Expand Down Expand Up @@ -84,13 +85,15 @@ class Tron implements TronInterface
* @param HttpProviderInterface $solidityNode
* @param HttpProviderInterface|null $eventServer
* @param HttpProviderInterface|null $signServer
* @param HttpProviderInterface|null $explorer
* @param string $privateKey
* @throws TronException
*/
public function __construct(?HttpProviderInterface $fullNode = null,
?HttpProviderInterface $solidityNode = null,
?HttpProviderInterface $eventServer = null,
?HttpProviderInterface $signServer = null,
?HttpProviderInterface $explorer = null,
string $privateKey = null)
{
if(!is_null($privateKey)) {
Expand All @@ -102,7 +105,8 @@ public function __construct(?HttpProviderInterface $fullNode = null,
'fullNode' => $fullNode,
'solidityNode' => $solidityNode,
'eventServer' => $eventServer,
'signServer' => $signServer
'signServer' => $signServer,
'explorer' => $explorer
]));

$this->transactionBuilder = new TransactionBuilder($this);
Expand Down
30 changes: 25 additions & 5 deletions src/TronManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class TronManager
* @var array
*/
protected $defaultNodes = [
'fullNode' => 'https://api.trongrid.io',
'fullNode' => 'https://api.trongrid.io',
'solidityNode' => 'https://api.trongrid.io',
'eventServer' => 'https://api.trongrid.io',
'explorer' => 'https://apilist.tronscan.org',
'signServer' => ''
];

Expand All @@ -25,9 +26,10 @@ class TronManager
* @var array
*/
protected $providers = [
'fullNode' => [],
'solidityNode' => [],
'fullNode' => [],
'solidityNode' => [],
'eventServer' => [],
'explorer' => [],
'signServer' => []
];

Expand All @@ -39,7 +41,8 @@ class TronManager
protected $statusPage = [
'fullNode' => 'wallet/getnowblock',
'solidityNode' => 'walletsolidity/getnowblock',
'eventServer' => 'healthcheck'
'eventServer' => 'healthcheck',
'explorer' => 'api/system/status'
];

/**
Expand All @@ -63,7 +66,7 @@ public function __construct($tron, $providers)
if(is_string($providers[$key]))
$this->providers[$key] = new HttpProvider($value);

if($key == 'signServer')
if(in_array($key, ['signServer']))
continue;

$this->providers[$key]->setStatusPage($this->statusPage[$key]);
Expand Down Expand Up @@ -124,6 +127,21 @@ public function signServer(): HttpProviderInterface
return $this->providers['signServer'];
}

/**
* TronScan server
*
* @throws TronException
* @return HttpProviderInterface
*/
public function explorer(): HttpProviderInterface
{
if (!array_key_exists('explorer', $this->providers)) {
throw new TronException('explorer is not activated.');
}

return $this->providers['explorer'];
}

/**
* Event server
*
Expand Down Expand Up @@ -157,6 +175,8 @@ public function request($url, $params = [], $method = 'post')
$response = $this->eventServer()->request($url, $params, 'get');
} elseif (in_array($split[0], ['trx-sign'])) {
$response = $this->signServer()->request($url, $params, 'post');
} elseif(in_array($split[0], ['api'])) {
$response = $this->explorer()->request($url, $params, 'get');
}else {
$response = $this->fullNode()->request($url, $params, $method);
}
Expand Down

0 comments on commit 2272b60

Please sign in to comment.