Skip to content

Commit

Permalink
protocol 21 support
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed May 13, 2024
1 parent 887cf54 commit 0198c21
Show file tree
Hide file tree
Showing 21 changed files with 1,320 additions and 311 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# [Stellar SDK for PHP](https://github.com/Soneso/stellar-php-sdk)

![v1.4.2](https://img.shields.io/badge/v1.4.2-green.svg)
![v1.5.0](https://img.shields.io/badge/v1.5.0-green.svg)

The Soneso open source Stellar SDK for PHP provides APIs to build and sign transactions, connect and query [Horizon](https://github.com/stellar/horizon).

Expand Down
8 changes: 7 additions & 1 deletion Soneso/StellarSDK/Soroban/Responses/GetHealthResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ class GetHealthResponse extends SorobanRpcResponse
const HEALTHY = "healthy";

public ?string $status = null;
public ?int $ledgerRetentionWindow = null;

public static function fromJson(array $json) : GetHealthResponse {
$result = new GetHealthResponse($json);
if (isset($json['result'])) {
$result->status = $json['result']['status'];
if (isset($json['result']['status'])) {
$result->status = $json['result']['status'];
}
if (isset($json['result']['ledgerRetentionWindow'])) {
$result->ledgerRetentionWindow = $json['result']['ledgerRetentionWindow'];
}
} else if (isset($json['error'])) {
$result->error = SorobanRpcErrorResponse::fromJson($json);
}
Expand Down
153 changes: 153 additions & 0 deletions Soneso/StellarSDK/Soroban/Responses/LedgerEntryChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php declare(strict_types=1);

// Copyright 2024 The Stellar PHP SDK Authors. All rights reserved.
// Use of this source code is governed by a license that can be
// found in the LICENSE file.


namespace Soneso\StellarSDK\Soroban\Responses;

use Soneso\StellarSDK\Xdr\XdrLedgerEntry;
use Soneso\StellarSDK\Xdr\XdrLedgerKey;

class LedgerEntryChange
{
/**
* @var string $type 'created', 'updated' or 'deleted'
*/
public string $type;
/**
* @var string $key XdrLedgerKey in base64
*/
public string $key;

/**
* @var string|null $before XdrLedgerEntry in base64
*/
public ?string $before;

/**
* @var string|null $after XdrLedgerEntry in base64
*/
public ?string $after;

/**
* @param string $type
* @param string $key
* @param string|null $before
* @param string|null $after
*/
public function __construct(
string $type,
string $key,
?string $before = null,
?string $after = null,
)
{
$this->type = $type;
$this->key = $key;
$this->before = $before;
$this->after = $after;
}

public static function fromJson(array $json) : LedgerEntryChange {
$before = null;
if(isset($json['before'])) {
$before = $json['before'];
}

$after = null;
if(isset($json['after'])) {
$after = $json['after'];
}
return new LedgerEntryChange(
type: $json['type'],
key: $json['key'],
before: $before,
after: $after,
);
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}

/**
* @return string
*/
public function getKey(): string
{
return $this->key;
}

/**
* @param string $key
*/
public function setKey(string $key): void
{
$this->key = $key;
}

/**
* @return string|null
*/
public function getBefore(): ?string
{
return $this->before;
}

/**
* @param string|null $before
*/
public function setBefore(?string $before): void
{
$this->before = $before;
}

/**
* @return string|null
*/
public function getAfter(): ?string
{
return $this->after;
}

/**
* @param string|null $after
*/
public function setAfter(?string $after): void
{
$this->after = $after;
}

public function getKeyXdr() : XdrLedgerKey {
return XdrLedgerKey::fromBase64Xdr($this->key);
}

public function getAfterXdr() : ?XdrLedgerEntry {
if($this->after !== null) {
return XdrLedgerEntry::fromBase64Xdr($this->after);
}
return null;
}

public function getBeforeXdr() : ?XdrLedgerEntry {
if($this->before !== null) {
return XdrLedgerEntry::fromBase64Xdr($this->before);
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class SimulateTransactionResponse extends SorobanRpcResponse
/// the simulation detected expired ledger entries which requires restoring with the submission of a RestoreFootprint
/// operation before submitting the InvokeHostFunction operation. The restorePreamble.minResourceFee and restorePreamble.transactionData fields should
/// be used to construct the transaction containing the RestoreFootprint
public ?RestorePreamble $restorePreamble;
public ?RestorePreamble $restorePreamble = null;

/**
* @var array<LedgerEntryChange>|null $stateChanges If present, it indicates how the state (ledger entries) will change as a result of the transaction execution.
*/
public ?array $stateChanges = null;

public static function fromJson(array $json) : SimulateTransactionResponse {
$result = new SimulateTransactionResponse($json);
Expand Down Expand Up @@ -78,6 +83,14 @@ public static function fromJson(array $json) : SimulateTransactionResponse {
if (isset($json['result']['restorePreamble'])) {
$result->restorePreamble = RestorePreamble::fromJson($json['result']['restorePreamble']);
}

if (isset($json['result']['stateChanges'])) {
$result->stateChanges = array();
foreach ($json['result']['stateChanges'] as $jsonValue) {
$result->stateChanges[] = LedgerEntryChange::fromJson($jsonValue);
}
}

} else if (isset($json['error'])) {
$result->error = SorobanRpcErrorResponse::fromJson($json);
}
Expand Down
2 changes: 1 addition & 1 deletion Soneso/StellarSDK/StellarSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
class StellarSDK
{

public const VERSION_NR = "1.4.2";
public const VERSION_NR = "1.5.0";
public static string $PUBLIC_NET_HORIZON_URL = "https://horizon.stellar.org";
public static string $TEST_NET_HORIZON_URL = "https://horizon-testnet.stellar.org";
public static string $FUTURE_NET_HORIZON_URL = "https://horizon-futurenet.stellar.org";
Expand Down
Loading

0 comments on commit 0198c21

Please sign in to comment.