|
|
@@ -676,11 +676,11 @@ class UsdtWalletService extends BaseService
|
|
|
* @param $address
|
|
|
* @return false|float|string
|
|
|
*/
|
|
|
- public function getTrxBalance($address)
|
|
|
+ public function getTrxBalance($address, $cache=false)
|
|
|
{
|
|
|
- $cacheKey = "caches:wallet:balance:{$address}";
|
|
|
- if (RedisService::get($cacheKey)) {
|
|
|
- return false;
|
|
|
+ $cacheKey = "caches:wallet:balance:trx_{$address}";
|
|
|
+ if ($data = RedisService::get($cacheKey) && $cache) {
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
if (empty($address)) {
|
|
|
@@ -704,7 +704,9 @@ class UsdtWalletService extends BaseService
|
|
|
$address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
|
$result = $trxWallet->balance($address);
|
|
|
|
|
|
- return $result ? floatval($result) : '0.00';
|
|
|
+ $result = $result ? floatval($result) : '0.00';
|
|
|
+ RedisService::set($cacheKey, $result, rand(3, 5));
|
|
|
+ return $result;
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
@@ -717,7 +719,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @param $address
|
|
|
* @return false|float|string
|
|
|
*/
|
|
|
- public function getTrc20Usdt($address)
|
|
|
+ public function getTrc20Usdt($address, $cache=false)
|
|
|
{
|
|
|
if (empty($address)) {
|
|
|
$this->error = '1018';
|
|
|
@@ -729,6 +731,11 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ $cacheKey = "caches:wallet:balance:usdt_{$address}";
|
|
|
+ if ($data = RedisService::get($cacheKey) && $cache) {
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
$headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
|
|
|
$api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
|
|
|
@@ -739,7 +746,10 @@ class UsdtWalletService extends BaseService
|
|
|
$address = $tron->getAddress();
|
|
|
$address = new \Tron\Address($address['base58'], '', $address['hex']);
|
|
|
$result = $trxWallet->balance($address);
|
|
|
- return $result ? floatval($result) : '0.00';
|
|
|
+
|
|
|
+ $result = $result ? floatval($result) : '0.00';
|
|
|
+ RedisService::set($cacheKey, $result, rand(3, 5));
|
|
|
+ return $result;
|
|
|
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
@@ -812,7 +822,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @throws \Tron\Exceptions\TransactionException
|
|
|
* @throws \Tron\Exceptions\TronErrorException
|
|
|
*/
|
|
|
- public function ercTransfer($force = false)
|
|
|
+ public function ercTransfer($to, $amount, $from, $fromPrivate)
|
|
|
{
|
|
|
if ($amount <= 0) {
|
|
|
$this->error = '2205';
|
|
|
@@ -966,7 +976,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @param $address
|
|
|
* @return false|float|string
|
|
|
*/
|
|
|
- public function getErcBalance($address)
|
|
|
+ public function getErcBalance($address, $cache=false)
|
|
|
{
|
|
|
if (empty($address)) {
|
|
|
$this->error = '1018';
|
|
|
@@ -983,6 +993,11 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ $cacheKey = "caches:wallet:balance:erc_{$address}";
|
|
|
+ if ($data = RedisService::get($cacheKey) && $cache) {
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
$url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
|
|
|
$headers = ["Content-Type" => 'application/json'];
|
|
|
@@ -995,8 +1010,9 @@ class UsdtWalletService extends BaseService
|
|
|
$result = curl_api($url, json_encode($data), $headers);
|
|
|
$result = $result ? json_decode($result, true) : [];
|
|
|
$balance = isset($result['result']) ? hexdec($result['result']) : 0.00;
|
|
|
- return $balance ? floatval($balance/pow(10,18)) : '0.00';
|
|
|
-
|
|
|
+ $balance = $balance ? floatval($balance/pow(10,18)) : '0.00';
|
|
|
+ RedisService::set($cacheKey, $balance, rand(3, 5));
|
|
|
+ return $balance;
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|
|
|
@@ -1008,7 +1024,7 @@ class UsdtWalletService extends BaseService
|
|
|
* @param $address
|
|
|
* @return false|float|string
|
|
|
*/
|
|
|
- public function getErc20Usdt($address)
|
|
|
+ public function getErc20Usdt($address, $cache=false)
|
|
|
{
|
|
|
|
|
|
if (empty($address)) {
|
|
|
@@ -1031,6 +1047,11 @@ class UsdtWalletService extends BaseService
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ $cacheKey = "caches:wallet:balance:erc_usdt_{$address}";
|
|
|
+ if ($data = RedisService::get($cacheKey) && $cache) {
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
$url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
|
|
|
$headers = ["Content-Type" => 'application/json'];
|
|
|
@@ -1047,8 +1068,9 @@ class UsdtWalletService extends BaseService
|
|
|
$balance = isset($result['result']) ? hexdec($result['result']) : 0.00;
|
|
|
$balance = $balance? floatval($balance/1000000) : '0.00';
|
|
|
|
|
|
- return $balance? $balance : '0.00';
|
|
|
-
|
|
|
+ $balance = $balance? $balance : '0.00';
|
|
|
+ RedisService::set($cacheKey, $balance, rand(3, 5));
|
|
|
+ return $balance;
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|