Skip to content

Commit

Permalink
update for stable p20
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-rogobete committed Oct 25, 2023
1 parent 81aab71 commit 4541a40
Show file tree
Hide file tree
Showing 50 changed files with 791 additions and 649 deletions.
4 changes: 3 additions & 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.3.0](https://img.shields.io/badge/v1.3.0-green.svg)
![v1.3.1](https://img.shields.io/badge/v1.3.1-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 Expand Up @@ -209,6 +209,7 @@ if ($response->isSuccessful()) {
| [SEP-0010: Stellar Web Authentication](examples/sep-0010-webauth.md) | This example shows how to authenticate with any web service which requires a Stellar account ownership verification. | [SEP-0010](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md)|
| [SEP-0011: Txrep](examples/sep-0011-txrep.md) | This example shows how to to generate Txrep (human-readable low-level representation of Stellar transactions) from a transaction and how to create a transaction object from a Txrep string. | [SEP-0011](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)|
| [SEP-0012: KYC API](examples/sep-0012-kyc.md) | In this examples you can see how to use the sdk to send KYC data to anchors and other services. | [SEP-0012](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md)|
| [SEP-0024: Hosted Deposit and Withdrawal](examples/sep-0024.md) | In this examples you can see how to interact with anchors in a standard way defined by SEP-0024. | [SEP-0024](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md)|

More examples can be found in the [tests](https://github.com/Soneso/stellar-php-sdk/tree/main/Soneso/StellarSDKTests).

Expand All @@ -224,6 +225,7 @@ More examples can be found in the [tests](https://github.com/Soneso/stellar-php-
- [SEP-0011: Txrep](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0011.md)
- [SEP-0012: KYC API](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md)
- [SEP-0023: Strkeys](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0023.md)
- [SEP-0024: Hosted Deposit and Withdrawal](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md)
- [SEP-0029: Account Memo Requirements](https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0029.md)

### Soroban support
Expand Down
8 changes: 4 additions & 4 deletions Soneso/StellarSDK/AbstractOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function fromXdr(XdrOperation $xdrOp) : AbstractOperation {
XdrOperationType::LIQUIDITY_POOL_DEPOSIT => self::liquidityPoolDeposit($body),
XdrOperationType::LIQUIDITY_POOL_WITHDRAW => self::liquidityPoolWithdraw($body),
XdrOperationType::INVOKE_HOST_FUNCTION => self::invokeHostFunction($body),
XdrOperationType::BUMP_FOOTPRINT_EXPIRATION => self::bumpFootprintExpiration($body),
XdrOperationType::EXTEND_FOOTPRINT_TTL => self::extendFootprintTTL($body),
XdrOperationType::RESTORE_FOOTPRINT => self::restoreFootprint($body),
default => throw new InvalidArgumentException(sprintf("Unknown operation type: %s", $type))
};
Expand All @@ -101,10 +101,10 @@ private static function restoreFootprint(XdrOperationBody $body) : RestoreFootpr
}
}

private static function bumpFootprintExpiration(XdrOperationBody $body) : BumpFootprintExpirationOperation {
$op = $body->getBumpFootprintExpirationOp();
private static function extendFootprintTTL(XdrOperationBody $body) : ExtendFootprintTTLOperation {
$op = $body->getExtendFootprintTTLOp();
if ($op != null) {
return BumpFootprintExpirationOperation::fromXdrOperation($op);
return ExtendFootprintTTLOperation::fromXdrOperation($op);
} else {
throw new InvalidArgumentException("missing invoke host function operation in xdr operation body");
}
Expand Down
57 changes: 0 additions & 57 deletions Soneso/StellarSDK/BumpFootprintExpirationOperation.php

This file was deleted.

2 changes: 1 addition & 1 deletion Soneso/StellarSDK/DeploySACWithAssetHostFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function fromXdr(XdrHostFunction $xdr) : DeploySACWithAssetHostFun
$type = $xdr->type;
if ($type->value != XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT || $xdr->createContract == null
|| $xdr->createContract->contractIDPreimage->type->value != XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ASSET
|| $xdr->createContract->executable->type->value != XdrContractExecutableType::CONTRACT_EXECUTABLE_TOKEN) {
|| $xdr->createContract->executable->type->value != XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET) {
throw new Exception("Invalid argument");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static function fromXdr(XdrHostFunction $xdr) : DeploySACWithSourceAccoun
$type = $xdr->type;
if ($type->value != XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT || $xdr->createContract == null
|| $xdr->createContract->contractIDPreimage->type->value != XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS
|| $xdr->createContract->executable->type->value != XdrContractExecutableType::CONTRACT_EXECUTABLE_TOKEN) {
|| $xdr->createContract->executable->type->value != XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET) {
throw new Exception("Invalid argument");
}

Expand Down
57 changes: 57 additions & 0 deletions Soneso/StellarSDK/ExtendFootprintTTLOperation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php declare(strict_types=1);

// Copyright 2023 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;

use Soneso\StellarSDK\Xdr\XdrExtendFootprintTTLOp;
use Soneso\StellarSDK\Xdr\XdrExtensionPoint;
use Soneso\StellarSDK\Xdr\XdrOperationBody;
use Soneso\StellarSDK\Xdr\XdrOperationType;


class ExtendFootprintTTLOperation extends AbstractOperation
{
private int $extendTo;

/**
* @param int $extendTo
*/
public function __construct(int $extendTo)
{
$this->extendTo = $extendTo;
}

public static function fromXdrOperation(XdrExtendFootprintTTLOp $xdrOp): ExtendFootprintTTLOperation {
return new ExtendFootprintTTLOperation($xdrOp->extendTo);
}

public function toOperationBody(): XdrOperationBody
{
$op = new XdrExtendFootprintTTLOp(new XdrExtensionPoint(0), $this->extendTo);
$type = new XdrOperationType(XdrOperationType::EXTEND_FOOTPRINT_TTL);
$result = new XdrOperationBody($type);
$result->setExtendFootprintTTLOp($op);
return $result;
}

/**
* @return int
*/
public function getExtendTo(): int
{
return $this->extendTo;
}

/**
* @param int $extendTo
*/
public function setExtendTo(int $extendTo): void
{
$this->extendTo = $extendTo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@

namespace Soneso\StellarSDK;

class BumpFootprintExpirationOperationBuilder
class ExtendFootprintTTLOperationBuilder
{
private int $ledgersToExpire;
private int $extendTo;
private ?MuxedAccount $sourceAccount = null;

/**
* @param int $ledgersToExpire
* @param int $extendTo
*/
public function __construct(int $ledgersToExpire)
public function __construct(int $extendTo)
{
$this->ledgersToExpire = $ledgersToExpire;
$this->extendTo = $extendTo;
}


public function setSourceAccount(string $accountId) : BumpFootprintExpirationOperationBuilder {
public function setSourceAccount(string $accountId) : ExtendFootprintTTLOperationBuilder {
$this->sourceAccount = MuxedAccount::fromAccountId($accountId);
return $this;
}

public function setMuxedSourceAccount(MuxedAccount $sourceAccount) : BumpFootprintExpirationOperationBuilder {
public function setMuxedSourceAccount(MuxedAccount $sourceAccount) : ExtendFootprintTTLOperationBuilder {
$this->sourceAccount = $sourceAccount;
return $this;
}

public function build(): BumpFootprintExpirationOperation {
$result = new BumpFootprintExpirationOperation($this->ledgersToExpire);
public function build(): ExtendFootprintTTLOperation {
$result = new ExtendFootprintTTLOperation($this->extendTo);
if ($this->sourceAccount != null) {
$result->setSourceAccount($this->sourceAccount);
}
Expand Down
2 changes: 1 addition & 1 deletion Soneso/StellarSDK/InvokeHostFunctionOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function fromXdrOperation(XdrInvokeHostFunctionOp $xdrOp): InvokeH
if ($contractIdPreimageTypeVal == XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS) {
if ($executableTypeValue == XdrContractExecutableType::CONTRACT_EXECUTABLE_WASM) {
return new InvokeHostFunctionOperation(CreateContractHostFunction::fromXdr($xdrFunction), $auth);
} else if ($executableTypeValue == XdrContractExecutableType::CONTRACT_EXECUTABLE_TOKEN){
} else if ($executableTypeValue == XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET){
return new InvokeHostFunctionOperation(DeploySACWithSourceAccountHostFunction::fromXdr($xdrFunction), $auth);
}
} else if ($executableTypeValue == XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ASSET) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ class LiquidityPoolTradeEffectResponse extends EffectResponse
private LiquidityPoolEffectResponse $liquidityPool;
private ReserveResponse $sold;
private ReserveResponse $bought;
private ReservesResponse $reserves;

protected function loadFromJson(array $json) : void {
if (isset($json['liquidity_pool'])) $this->liquidityPool = LiquidityPoolEffectResponse::fromJson($json['liquidity_pool']);
if (isset($json['sold'])) $this->sold = ReserveResponse::fromJson($json['sold']);
if (isset($json['bought'])) $this->sold = ReserveResponse::fromJson($json['bought']);
if (isset($json['reserves'])) {
$this->reserves = new ReservesResponse();
foreach ($json['reserves'] as $jsonValue) {
$value = ReserveResponse::fromJson($jsonValue);
$this->reserves->add($value);
}
}
parent::loadFromJson($json);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php declare(strict_types=1);

// Copyright 2023 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\Responses\Operations;


class ExtendFootprintTTLOperationResponse extends OperationResponse
{
public string $extendTo;

protected function loadFromJson(array $json) : void {
if (isset($json['extend_to'])) {
$this->extendTo = $json['extend_to'];
} else if (isset($json['ledgers_to_expire'])) {
$this->extendTo = $json['ledgers_to_expire'];
}
parent::loadFromJson($json);
}

public static function fromJson(array $jsonData) : ExtendFootprintTTLOperationResponse {
$result = new ExtendFootprintTTLOperationResponse();
$result->loadFromJson($jsonData);
return $result;
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function fromJson(array $jsonData) : OperationResponse {
OperationType::LIQUIDITY_POOL_DEPOSIT => LiquidityPoolDepositOperationResponse::fromJson($jsonData),
OperationType::LIQUIDITY_POOL_WITHDRAW => LiquidityPoolWithdrawOperationResponse::fromJson($jsonData),
OperationType::INVOKE_HOST_FUNCTION => InvokeHostFunctionOperationResponse::fromJson($jsonData),
OperationType::BUMP_FOOTPRINT_EXPIRATION => BumpFootprintExpirationOperationResponse::fromJson($jsonData),
OperationType::EXTEND_FOOTPRINT_TTL => ExtendFootprintTTLOperationResponse::fromJson($jsonData),
OperationType::RESTORE_FOOTPRINT => RestoreFootprintOperationResponse::fromJson($jsonData),
default => throw new \InvalidArgumentException(sprintf("Unknown operation type: %s", $operationType)),
};
Expand Down
2 changes: 1 addition & 1 deletion Soneso/StellarSDK/Responses/Operations/OperationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ class OperationType
public const LIQUIDITY_POOL_DEPOSIT = 22;
public const LIQUIDITY_POOL_WITHDRAW = 23;
public const INVOKE_HOST_FUNCTION = 24;
public const BUMP_FOOTPRINT_EXPIRATION = 25;
public const EXTEND_FOOTPRINT_TTL = 25;
public const RESTORE_FOOTPRINT = 26;
}
8 changes: 4 additions & 4 deletions Soneso/StellarSDK/SEP/Interactive/SEP24Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ class SEP24Transaction extends Response
/// (optional) True if the anchor has verified the user's KYC information for this transaction.
public ?bool $kycVerified = null;

/// (optional) A URL that is opened by wallets after the interactive flow is complete. It can include banking information for users to start deposits, the status of the transaction, or any other information the user might need to know about the transaction.
/// A URL that is opened by wallets after the interactive flow is complete. It can include banking information for users to start deposits, the status of the transaction, or any other information the user might need to know about the transaction.
public string $moreInfoUrl;

/// (optional) Amount received by anchor at start of transaction as a string with up to 7 decimals. Excludes any fees charged before the anchor received the funds.
/// Amount received by anchor at start of transaction as a string with up to 7 decimals. Excludes any fees charged before the anchor received the funds.
public string $amountIn;

/// (optional) The asset received or to be received by the Anchor. Must be present if the deposit/withdraw was made using non-equivalent assets.
Expand All @@ -38,7 +38,7 @@ class SEP24Transaction extends Response
/// https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md#asset-exchanges
public ?string $amountInAsset = null;

/// (optional) Amount sent by anchor to user at end of transaction as a string with up to 7 decimals.
/// Amount sent by anchor to user at end of transaction as a string with up to 7 decimals.
/// Excludes amount converted to XLM to fund account and any external fees.
public string $amountOut;

Expand All @@ -49,7 +49,7 @@ class SEP24Transaction extends Response
/// https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md#asset-exchanges
public ?string $amountOutAsset = null;

/// (optional) Amount of fee charged by anchor.
/// Amount of fee charged by anchor.
public string $amountFee;

/// (optional) The asset in which fees are calculated in. Must be present if the deposit/withdraw was made using non-equivalent assets.
Expand Down
Loading

0 comments on commit 4541a40

Please sign in to comment.