Skip to content

Commit

Permalink
- Fixed fundWallet() "Account not found" issue
Browse files Browse the repository at this point in the history
- Added to documentation
- Removed obsolete examples
  • Loading branch information
AlexanderBuzz committed Nov 8, 2023
1 parent cdffe71 commit 2823c9a
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 53 deletions.
61 changes: 60 additions & 1 deletion docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,63 @@
layout: documentation
title: JSON RPC Client
current_menu: client
---
---

# JSON RPC Client

### Creating a Client

To instantiate a client, you have to create a new JsonRpcClient object and provide the URL of the [Network](networks.md)
you want to use as a constructor parameter:

```php
use use XRPL_PHP\Client\JsonRpcClient;

$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");
```

### Method requests and raw requests

XRPL_PHP offers most of the standardized [Public API Methods](https://xrpl.org/public-api-methods.html)
and [Admin API Methods](https://xrpl.org/admin-api-methods.html). In most use cases you create a request method and
pass it to the clients `syncReuqest()` or `asyncRequest()` methods.

```php
use XRPL_PHP\Client\JsonRpcClient;
use XRPL_PHP\Models\Utility\PingRequest;

$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");

$pingRequest = new PingRequest();

$pingResponse = $client->syncRequest($pingRequest);

$result = $pingResponse->getResult();

print_r($result);
```

You can also use the `rawRequest()` method if you need more control over the request, e.g. using a currently not implemented method:

```php
use XRPL_PHP\Client\JsonRpcClient;

$client = new JsonRpcClient("https://s.altnet.rippletest.net:51234");

$body = json_encode([
"method" => "server_info",
"params" => [
["api_version" => 1]
]
]);

$response = $client->rawSyncRequest('POST', '', $body);

$content = $response->getBody()->getContents();

print_r($content);
```

### Synchronous and Asynchronous requests

XRPL_PHP supports both synchronous and asynchronous request flows.
38 changes: 0 additions & 38 deletions examples/internal/request.php

This file was deleted.

File renamed without changes.
1 change: 0 additions & 1 deletion examples/quickstart/1.get-accounts-send-xrp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

print_r(Color::YELLOW . "Funding standby wallet, please wait..." . PHP_EOL);
$standbyWallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created standby wallet - address: " . Color::WHITE . "{$standbyWallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$standbyWallet->getSeed()}" . PHP_EOL);

print_r(Color::YELLOW . "Funding operational wallet, please wait..." . PHP_EOL);
Expand Down
1 change: 0 additions & 1 deletion examples/quickstart/2.create-trustline-send-currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

print_r(Color::YELLOW . "Funding cold wallet, please wait..." . PHP_EOL);
$coldWallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created cold wallet - address: " . Color::WHITE . "{$coldWallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$coldWallet->getSeed()}" . PHP_EOL);

/*
Expand Down
1 change: 0 additions & 1 deletion examples/quickstart/3.mint-nfts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

print_r(Color::YELLOW . "Funding wallet, please wait..." . PHP_EOL);
$wallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created wallet - address: " . Color::WHITE . "{$wallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$wallet->getSeed()}" . PHP_EOL);

print_r(Color::YELLOW . "Minting NFT, please wait..." . PHP_EOL);
Expand Down
1 change: 0 additions & 1 deletion examples/quickstart/5.broker-nfts.php

This file was deleted.

1 change: 0 additions & 1 deletion examples/quickstart/6.authorized-minter.php

This file was deleted.

1 change: 0 additions & 1 deletion examples/quickstart/7.batch-minting.php

This file was deleted.

3 changes: 0 additions & 3 deletions examples/token-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@

print_r(Color::YELLOW . "Funding bank wallet, please wait..." . PHP_EOL);
$bankWallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created bank wallet - address: " . Color::WHITE . "{$bankWallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$bankWallet->getSeed()}" . PHP_EOL);

//print_r("Configuring bank wallet, please wait..." . PHP_EOL);
Expand All @@ -69,7 +68,6 @@

print_r(Color::YELLOW . "Funding merchant wallet, please wait..." . PHP_EOL);
$merchantWallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created merchant wallet - address: " . Color::WHITE . "{$merchantWallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$merchantWallet->getSeed()}" . PHP_EOL);

// Configure Wallet ...
Expand All @@ -92,7 +90,6 @@

print_r(Color::YELLOW . "Funding customer wallet, please wait..." . PHP_EOL);
$customerWallet = $client->fundWallet();
sleep(2);
print_r(Color::GREEN . "Created customer wallet - address: " . Color::WHITE . "{$customerWallet->getAddress()} " . Color::GREEN . "seed: " . Color::WHITE . "{$customerWallet->getSeed()}" . PHP_EOL);

// Configure Wallet ...
Expand Down
11 changes: 7 additions & 4 deletions src/Sugar/balances.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ function getXrpBalance(
JsonRpcClient $client,
string $address,
?string $ledgerHash = null,
?string $ledgerIndex = null,
?string $ledgerIndex = 'validated',
): string
{
//$xrpRequest = new AccountInfoRequest($address, $ledgerIndex, $ledgerIndex || 'validated');
$xrpRequest = new AccountInfoRequest($address);
$accountInfoRequest = new AccountInfoRequest(
account: $address,
ledgerHash: $ledgerHash,
ledgerIndex: $ledgerIndex
);

$xrpResponse = $client->request($xrpRequest)->wait();
$xrpResponse = $client->request($accountInfoRequest)->wait();

if(get_class($xrpResponse) === ErrorResponse::class) {
throw new Exception($xrpResponse->getError());
Expand Down
2 changes: 1 addition & 1 deletion src/Sugar/fundWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function fundWallet(
$attempts = 20;
while ($attempts > 0) {
try {
$updatedBalance = (float)getXrpBalance($client, $classicAddress);
$updatedBalance = (float) getXrpBalance($client, $classicAddress);
if ($updatedBalance > $startingBalance) {
break;
}
Expand Down

0 comments on commit 2823c9a

Please sign in to comment.