Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/unit_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
tools: composer, phpunit
extensions: ds, gmp, sockets
coverage: none
#
- name: Install composer dependencies
uses: php-actions/composer@v6
with:
php_version: "8.1"
php_version: "8.2"
php_extensions: gmp sockets bcmath
version: latest

Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"config": {
"optimize-autoloader": true,
"platform": {
"php": "8.1"
"php": "8.2.27"
}
},
"autoload": {
Expand All @@ -39,6 +39,8 @@
"src/Sugar/balances.php",
"src/Sugar/fundWallet.php",
"src/Sugar/getFeeXrp.php",
"src/Sugar/getOrderbook.php",
"src/Sugar/getTransactions.php",
"src/Sugar/submit.php",
"src/Sugar/xrpConversion.php"
]
Expand All @@ -60,9 +62,10 @@
"vlucas/phpdotenv": "^5.6"
},
"require-dev": {
"phpunit/phpunit": "^10.3.1",
"vimeo/psalm": "^5.14",
"donatj/mock-webserver": "^2.6.2"
"phpunit/phpunit": "^11.5",
"vimeo/psalm": "^6.8",
"donatj/mock-webserver": "^2.10.0",
"rector/rector": "^2.3"
},
"scripts": {
"psalm": "vendor/bin/psalm --config=psalm.xml"
Expand Down
6 changes: 3 additions & 3 deletions containers/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM php:8.1.4-fpm-alpine
FROM php:8.2.27-fpm-alpine

RUN apk update \
&& apk upgrade \
&& apk add gmp-dev \
&& apk add --no-cache bash $PHPIZE_DEPS \
&& apk add --no-cache bash $PHPIZE_DEPS linux-headers \
&& docker-php-ext-install gmp \
&& docker-php-ext-install sockets \
&& pecl install xdebug-3.1.3 \
&& pecl install xdebug \
&& pecl install ds

COPY --from=composer /usr/bin/composer /usr/bin/composer
Expand Down
103 changes: 92 additions & 11 deletions src/Client/JsonRpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
use function Hardcastle\XRPL_PHP\Sugar\autofill;
use function Hardcastle\XRPL_PHP\Sugar\fundWallet;
use function Hardcastle\XRPL_PHP\Sugar\getXrpBalance;
use function Hardcastle\XRPL_PHP\Sugar\getBalances;
use function Hardcastle\XRPL_PHP\Sugar\getFeeXrp;
use function Hardcastle\XRPL_PHP\Sugar\getOrderbook;
use function Hardcastle\XRPL_PHP\Sugar\getTransactions;
use function Hardcastle\XRPL_PHP\Sugar\submit;
use function Hardcastle\XRPL_PHP\Sugar\submitAndWait;

Expand All @@ -44,30 +48,26 @@ class JsonRpcClient

private const NORMAL_DISCONNECT_CODE = 1000;

private Client $restClient;
private readonly Client $restClient;

private string $connectionUrl;
private readonly string $connectionUrl;

private float $feeCushion;
private readonly float $feeCushion;

private string $maxFeeXrp;

private float $timeout;
private readonly string $maxFeeXrp;

public function __construct(
string $connectionUrl,
?float $feeCushion = null,
?string $maxFeeXrp = null,
?float $timeout = 3.0
private readonly float $timeout = 3.0
) {
$this->connectionUrl = $this->getNetworkUrl($connectionUrl);

$this->feeCushion = $feeCushion ?? self::DEFAULT_FEE_CUSHION;

$this->maxFeeXrp = $maxFeeXrp ?? self::DEFAULT_MAX_FEE_XRP;

$this->timeout = $timeout;

$stack = HandlerStack::create(new CurlHandler());

$this->restClient = new Client(
Expand Down Expand Up @@ -208,7 +208,7 @@ private function handleResponse(BaseRequest $request, ?ResponseInterface $respon
);
}

$requestClassName = get_class($request);
$requestClassName = $request::class;
/** @psalm-var class-string $responseClassName */
$responseClassName = str_replace('Request', 'Response', $requestClassName);
/** @var BaseResponse $responseClass */
Expand Down Expand Up @@ -303,6 +303,87 @@ public function getXrpBalance(string $address): string
return getXrpBalance($this, $address);
}

/**
* @param string $address
* @param string|null $ledgerHash
* @param string|null $ledgerIndex
* @param string|null $peer
* @param int|null $limit
* @return array
* @throws Exception
*/
public function getBalances(
string $address,
?string $ledgerHash = null,
?string $ledgerIndex = 'validated',
?string $peer = null,
?int $limit = null
): array
{
return getBalances($this, $address, $ledgerHash, $ledgerIndex, $peer, $limit);
}

/**
* @param string $address
* @param int|null $ledgerIndexMin
* @param int|null $ledgerIndexMax
* @param string|null $ledgerHash
* @param string|null $ledgerIndex
* @param bool|null $binary
* @param bool|null $forward
* @param int|null $limit
* @param mixed|null $marker
* @return array
* @throws Exception
*/
public function getTransactions(
string $address,
?int $ledgerIndexMin = null,
?int $ledgerIndexMax = null,
?string $ledgerHash = null,
?string $ledgerIndex = 'validated',
?bool $binary = null,
?bool $forward = null,
?int $limit = null,
mixed $marker = null
): array
{
return getTransactions($this, $address, $ledgerIndexMin, $ledgerIndexMax, $ledgerHash, $ledgerIndex, $binary, $forward, $limit, $marker);
}

/**
* @param array $takerGets
* @param array $takerPays
* @param string|null $ledgerHash
* @param string|null $ledgerIndex
* @param int|null $limit
* @param string|null $taker
* @return array
* @throws Exception
*/
public function getOrderbook(
array $takerGets,
array $takerPays,
?string $ledgerHash = null,
?string $ledgerIndex = 'validated',
?int $limit = null,
?string $taker = null
): array
{
return getOrderbook($this, $takerGets, $takerPays, $ledgerHash, $ledgerIndex, $limit, $taker);
}

/**
* @param int|null $cushion
* @return string
* @throws \Brick\Math\Exception\MathException
* @throws \Brick\Math\Exception\RoundingNecessaryException
*/
public function getFeeXrp(?int $cushion = null): string
{
return getFeeXrp($this, $cushion);
}

/**
*
*
Expand Down Expand Up @@ -380,7 +461,7 @@ private function getNetworkUrl(string $connection): string
try {
$network = Networks::getNetwork($connection);
return $network['jsonRpcUrl'];
} catch (Exception $e) {
} catch (Exception) {
return $connection;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/CoreUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CoreUtilities
{
private static ?CoreUtilities $instance = null;

private AddressCodec $addressCodec;
private readonly AddressCodec $addressCodec;

public static function getInstance(): CoreUtilities
{
Expand All @@ -33,7 +33,7 @@ public static function ensureClassicAddress(string $account): string
{
$_this = self::getInstance();
if ($_this->addressCodec->isValidXAddress($account)) {
list($classicAddress, $tag) = $_this->addressCodec->xAddressToClassicAddress($account);
[$classicAddress, $tag] = $_this->addressCodec->xAddressToClassicAddress($account);

/*
* Except for special cases, X-addresses used for requests
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Ctid.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Ctid
{
private const FILLER = 0xc0000000;

private Buffer $internal;
private readonly Buffer $internal;

/**
* // https://github.com/XRPLF/XRPL-Standards/discussions/91
Expand Down
10 changes: 4 additions & 6 deletions src/Core/RippleAddressCodec/AddressCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ public function encodeXAddress(Buffer $accountId, $tag, bool $test = false): str
0, 0, 0, 0
]);

$hex = array_map(function ($item) {
return sprintf('%02X', $item);
}, $bytes);
$hex = array_map(fn($item) => sprintf('%02X', $item), $bytes);

return $this->encodeChecked(Buffer::from(join($hex)));
return $this->encodeChecked(Buffer::from(join('', $hex)));
}

public function xAddressToClassicAddress(string $xAddress): array
{
list($accountId, $tag, $test) = array_values($this->decodeXAddress($xAddress));
[$accountId, $tag, $test] = array_values($this->decodeXAddress($xAddress));
$classicAddress = $this->encodeAccountID($accountId);
return [
'classicAddress' => $classicAddress,
Expand All @@ -91,7 +89,7 @@ public function isValidXAddress(string $xAddress): bool
{
try {
$this->decodeXAddress($xAddress);
} catch (\Throwable $e) {
} catch (\Throwable) {
return false;
}
return true;
Expand Down
12 changes: 5 additions & 7 deletions src/Core/RippleAddressCodec/BaseX.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class BaseX

private SplFixedArray $baseMap;

private int $base;
private readonly int $base;

private string $leader;
private readonly string $leader;

private float $factor;
private readonly float $factor;

private float $inverseFactor;
private readonly float $inverseFactor;

public function __construct(string $alphabet)
{
Expand Down Expand Up @@ -170,9 +170,7 @@ public function decodeUnsafe(string $source): ?Buffer
$vch[$j++] = $b256[$it4++];
}

$hexStr = join(array_map(function ($item) {
return sprintf('%02X', $item);
}, $vch));
$hexStr = join('', array_map(fn($item) => sprintf('%02X', $item), $vch));

//decimalArrayToHexStr
return Buffer::from($hexStr);
Expand Down
9 changes: 3 additions & 6 deletions src/Core/RippleAddressCodec/Codec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@

class Codec
{
private string $alphabet;
private readonly BaseX $baseCodec;

private BaseX $baseCodec;

public function __construct(string $alphabet)
public function __construct(private readonly string $alphabet)
{
$this->alphabet = $alphabet;
$this->baseCodec = new BaseX($alphabet);
$this->baseCodec = new BaseX($this->alphabet);
}

public function encode(Buffer $bytes, array $options): string
Expand Down
2 changes: 1 addition & 1 deletion src/Core/RippleAddressCodec/CodecWithXrpAlphabet.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function isValidClassicAddress(string $address): bool
{
try {
$this->decodeAccountId($address);
} catch (\Throwable $e) {
} catch (\Throwable) {
return false;
}
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/Core/RippleBinaryCodec/BinaryCodec.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,14 @@ public function encode(string|array $jsonObject): string
*
* @param string $binaryString
* @return array
* @throws Exception
*/
public function decode(string $binaryString): array
{
if (str_starts_with(trim(bin2hex(hex2bin($binaryString))), "7b")) {
throw new Exception("The provided binary string appears to be a hex-encoded JSON object, not a binary-encoded transaction.");
}

return $this->binaryToJson($binaryString);
}

Expand Down
Loading