Skip to content

Instantly share code, notes, and snippets.

@steepzero-old
Created January 17, 2018 08:18
Show Gist options
  • Save steepzero-old/24d005df55a0fb692ea8ebcb2483558a to your computer and use it in GitHub Desktop.
Save steepzero-old/24d005df55a0fb692ea8ebcb2483558a to your computer and use it in GitHub Desktop.
<?php
namespace App\Library\Api;
use App\Library\Contracts\AssetsApi;
use App\Library\Entity\Wallet;
use GuzzleHttp\Exception\ClientException;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Cache;
class DashApi implements AssetsApi
{
/**
* Api-ключ для cryptoID
* зареган на имя [email protected]
* TODO: заменить на ключ заказчика
* @var string
*/
private $apiKey = '2ff9ef437467';
public function __construct(Application $app)
{
$this->client = $app->make('HttpClient');
}
public function getHost()
{
return 'http://chainz.cryptoid.info';
}
public function getAccount($hash)
{
$wallet = new Wallet();
$wallet->name = $hash;
$wallet->currency = 'DASH';
$wallet->link = $this->getLink($hash);
try {
$balance = Cache::remember('DashAccount',60,$this->getAccountCacheCallback($hash),true);
$wallet->balance = $balance;
}catch (\InvalidArgumentException $e){
$wallet->balance = 0;
}
return $wallet;
}
public function getAccountCacheCallback($hash){
return function () use ($hash){
$url = $this->getHost().'/dash/api.dws?a='.$hash.'&q=getbalance';
try {
$response = $this->client->get($url);
$result = (string) $response->getBody();
}catch (ClientException $e){
throw new \RuntimeException('Dash Error');
}
return $result;
};
}
public function getLink($hash)
{
return 'https://explorer.dash.org/address/'.$hash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment