Skip to content

Commit 1cea609

Browse files
committed
update
1 parent 11a7ea2 commit 1cea609

File tree

2 files changed

+71
-22
lines changed

2 files changed

+71
-22
lines changed

src/Ripple.php

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?php
22
namespace IEXBase\RippleAPI;
33

4-
use GuzzleHttp\Client;
5-
use GuzzleHttp\Exception\GuzzleException;
64
use IEXBase\RippleAPI\Objects\AccountObject;
75
use IEXBase\RippleAPI\Objects\PaymentObject;
86
use IEXBase\RippleAPI\Objects\SignObject;
97
use IEXBase\RippleAPI\Objects\TransactionObject;
10-
use IEXBase\RippleAPI\Support\Collection;
118
use IEXBase\RippleAPI\Transaction\TransactionBuilder;
129

1310
class Ripple
@@ -16,49 +13,50 @@ class Ripple
1613
* Адрес кошелька
1714
*
1815
* @var string
19-
*/
16+
*/
2017
protected $address;
2118

2219
/**
2320
* Приватный ключ кошелька
2421
*
2522
* @var string
26-
*/
23+
*/
2724
protected $secret;
2825

2926
/**
3027
* Ripple client service
3128
*
3229
* @var RippleClient
33-
*/
30+
*/
3431
protected $client;
3532

3633
/**
3734
* Получаем Хэш подписанной транзакции
3835
*
3936
* @var string
40-
*/
37+
*/
4138
protected $tx_blob;
4239

4340
/**
4441
* Создаем объект суперкласса Ripple.
4542
*
4643
* @param $address
4744
* @param null $secret
45+
* @param array $nodes
4846
*/
49-
public function __construct($address, $secret = null)
47+
public function __construct($address, $secret = null, $nodes = [])
5048
{
5149
$this->address = $address;
5250
$this->secret = $secret;
5351

54-
$this->client = new RippleClient();
52+
$this->client = new RippleClient($nodes);
5553
}
5654

5755
/**
5856
* Получение пинга
5957
*
6058
* @return array
61-
*/
59+
*/
6260
public function getPing() : array
6361
{
6462
return $this->call('ping', '/');
@@ -68,7 +66,7 @@ public function getPing() : array
6866
* Получаем детальную информацию о сервере
6967
*
7068
* @return array
71-
*/
69+
*/
7270
public function getServerInfo() : array
7371
{
7472
return $this->call('server_info', '/');
@@ -78,7 +76,7 @@ public function getServerInfo() : array
7876
* Генерация случайних чисел
7977
*
8078
* @return array
81-
*/
79+
*/
8280
public function getRandom() : array
8381
{
8482
return $this->call('random', '/');
@@ -232,7 +230,7 @@ public function getTransaction($hash = null, $params = [])
232230
* Получение последних версий
233231
*
234232
* @return array
235-
*/
233+
*/
236234
public function getRippledVersion()
237235
{
238236
return $this->call('GET', '/network/rippled_versions');
@@ -242,7 +240,7 @@ public function getRippledVersion()
242240
* Получаем список всех шлюзов
243241
*
244242
* @return array
245-
*/
243+
*/
246244
public function getGateways()
247245
{
248246
return $this->call('GET', '/gateways');
@@ -307,7 +305,7 @@ public function getHealthValidationsEtl($params = [])
307305
* Получаем комиссию
308306
*
309307
* @return array
310-
*/
308+
*/
311309
public function getFee()
312310
{
313311
return $this->call('fee', '/');
@@ -389,6 +387,24 @@ public function submit()
389387
}
390388
}
391389

390+
/**
391+
* Отправляем средства используя стронний сервер
392+
*
393+
* @param $options
394+
* @return array
395+
* @throws \Exception
396+
*/
397+
public function sendAndSubmitForServer($options)
398+
{
399+
$result = $this->client->sendRequestWss('POST','/send-xrp', $options);
400+
401+
if(empty($result)) {
402+
throw new \Exception('Транзакция не отправлена');
403+
} else {
404+
return $result;
405+
}
406+
}
407+
392408
/**
393409
* Базовая функция для формировании запросов
394410
*
@@ -399,7 +415,7 @@ public function submit()
399415
*/
400416
protected function call($method, $path, $params = [])
401417
{
402-
if(in_array($method, ['GET','POST','PUT','DELETE'])) {
418+
if(in_array($method, ['GET', 'POST', 'PUT', 'DELETE'])) {
403419
return $this->client->sendRequest(
404420
$method,
405421
trim($path),

src/RippleClient.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ class RippleClient
1313

1414
/**
1515
* @const string Ripple RPC URL
16-
*/
17-
const BASE_RPC_URL = 'https://s2.ripple.com:51234';
16+
*/
17+
const BASE_RPC_URL = 'https://s1.ripple.com:51234';
18+
19+
/**
20+
* Base WSS Node
21+
*
22+
* @var string
23+
*/
24+
protected $WSSNode;
1825

1926
/**
2027
* Guzzle Http клиент
@@ -27,17 +34,21 @@ class RippleClient
2734
* Количество запросов
2835
*
2936
* @var integer
30-
*/
37+
*/
3138
protected $requestCount = 0;
3239

3340
/**
3441
* Создаем новый объект RippleClient
3542
*
36-
* @return void.
37-
*/
38-
public function __construct()
43+
* @param array $nodes
44+
*/
45+
public function __construct($nodes = [])
3946
{
4047
$this->client = new Client();
48+
49+
if(array_key_exists('wss_node', $nodes)) {
50+
$this->WSSNode = $nodes['wss_node'];
51+
}
4152
}
4253

4354
/**
@@ -80,6 +91,28 @@ public function sendRequest($method, $path, $options = [], $api = true)
8091
}
8192
}
8293

94+
/**
95+
* Отправляем запросы на сервер Ripple WSS
96+
*
97+
* @param $method
98+
* @param $path
99+
* @param array $options
100+
* @return array
101+
*/
102+
public function sendRequestWss($method, $path, $options = [])
103+
{
104+
$this->requestCount++;
105+
try {
106+
$url = sprintf('%s%s', $this->WSSNode, $path);
107+
108+
$response = $this->client->request($method, $url, ['query' => $options]);
109+
return $this->toArray($response->getBody()->getContents());
110+
111+
} catch (GuzzleException $e) {
112+
die($e->getMessage());
113+
}
114+
}
115+
83116
/**
84117
* Преобразовываем любой ответ в массив
85118
*

0 commit comments

Comments
 (0)