Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
serderovsh committed Mar 31, 2019
1 parent 11a7ea2 commit 1cea609
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 22 deletions.
48 changes: 32 additions & 16 deletions src/Ripple.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php
namespace IEXBase\RippleAPI;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use IEXBase\RippleAPI\Objects\AccountObject;
use IEXBase\RippleAPI\Objects\PaymentObject;
use IEXBase\RippleAPI\Objects\SignObject;
use IEXBase\RippleAPI\Objects\TransactionObject;
use IEXBase\RippleAPI\Support\Collection;
use IEXBase\RippleAPI\Transaction\TransactionBuilder;

class Ripple
Expand All @@ -16,49 +13,50 @@ class Ripple
* Адрес кошелька
*
* @var string
*/
*/
protected $address;

/**
* Приватный ключ кошелька
*
* @var string
*/
*/
protected $secret;

/**
* Ripple client service
*
* @var RippleClient
*/
*/
protected $client;

/**
* Получаем Хэш подписанной транзакции
*
* @var string
*/
*/
protected $tx_blob;

/**
* Создаем объект суперкласса Ripple.
*
* @param $address
* @param null $secret
* @param array $nodes
*/
public function __construct($address, $secret = null)
public function __construct($address, $secret = null, $nodes = [])
{
$this->address = $address;
$this->secret = $secret;

$this->client = new RippleClient();
$this->client = new RippleClient($nodes);
}

/**
* Получение пинга
*
* @return array
*/
*/
public function getPing() : array
{
return $this->call('ping', '/');
Expand All @@ -68,7 +66,7 @@ public function getPing() : array
* Получаем детальную информацию о сервере
*
* @return array
*/
*/
public function getServerInfo() : array
{
return $this->call('server_info', '/');
Expand All @@ -78,7 +76,7 @@ public function getServerInfo() : array
* Генерация случайних чисел
*
* @return array
*/
*/
public function getRandom() : array
{
return $this->call('random', '/');
Expand Down Expand Up @@ -232,7 +230,7 @@ public function getTransaction($hash = null, $params = [])
* Получение последних версий
*
* @return array
*/
*/
public function getRippledVersion()
{
return $this->call('GET', '/network/rippled_versions');
Expand All @@ -242,7 +240,7 @@ public function getRippledVersion()
* Получаем список всех шлюзов
*
* @return array
*/
*/
public function getGateways()
{
return $this->call('GET', '/gateways');
Expand Down Expand Up @@ -307,7 +305,7 @@ public function getHealthValidationsEtl($params = [])
* Получаем комиссию
*
* @return array
*/
*/
public function getFee()
{
return $this->call('fee', '/');
Expand Down Expand Up @@ -389,6 +387,24 @@ public function submit()
}
}

/**
* Отправляем средства используя стронний сервер
*
* @param $options
* @return array
* @throws \Exception
*/
public function sendAndSubmitForServer($options)
{
$result = $this->client->sendRequestWss('POST','/send-xrp', $options);

if(empty($result)) {
throw new \Exception('Транзакция не отправлена');
} else {
return $result;
}
}

/**
* Базовая функция для формировании запросов
*
Expand All @@ -399,7 +415,7 @@ public function submit()
*/
protected function call($method, $path, $params = [])
{
if(in_array($method, ['GET','POST','PUT','DELETE'])) {
if(in_array($method, ['GET', 'POST', 'PUT', 'DELETE'])) {
return $this->client->sendRequest(
$method,
trim($path),
Expand Down
45 changes: 39 additions & 6 deletions src/RippleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ class RippleClient

/**
* @const string Ripple RPC URL
*/
const BASE_RPC_URL = 'https://s2.ripple.com:51234';
*/
const BASE_RPC_URL = 'https://s1.ripple.com:51234';

/**
* Base WSS Node
*
* @var string
*/
protected $WSSNode;

/**
* Guzzle Http клиент
Expand All @@ -27,17 +34,21 @@ class RippleClient
* Количество запросов
*
* @var integer
*/
*/
protected $requestCount = 0;

/**
* Создаем новый объект RippleClient
*
* @return void.
*/
public function __construct()
* @param array $nodes
*/
public function __construct($nodes = [])
{
$this->client = new Client();

if(array_key_exists('wss_node', $nodes)) {
$this->WSSNode = $nodes['wss_node'];
}
}

/**
Expand Down Expand Up @@ -80,6 +91,28 @@ public function sendRequest($method, $path, $options = [], $api = true)
}
}

/**
* Отправляем запросы на сервер Ripple WSS
*
* @param $method
* @param $path
* @param array $options
* @return array
*/
public function sendRequestWss($method, $path, $options = [])
{
$this->requestCount++;
try {
$url = sprintf('%s%s', $this->WSSNode, $path);

$response = $this->client->request($method, $url, ['query' => $options]);
return $this->toArray($response->getBody()->getContents());

} catch (GuzzleException $e) {
die($e->getMessage());
}
}

/**
* Преобразовываем любой ответ в массив
*
Expand Down

0 comments on commit 1cea609

Please sign in to comment.