diff --git a/Soneso/StellarSDK/CreateContractWithConstructorHostFunction.php b/Soneso/StellarSDK/CreateContractWithConstructorHostFunction.php new file mode 100644 index 0000000..2c3ca72 --- /dev/null +++ b/Soneso/StellarSDK/CreateContractWithConstructorHostFunction.php @@ -0,0 +1,133 @@ + + */ + public array $constructorArgs; + + + /** + * @param Address $address + * @param string $wasmId + * @param string|null $salt + * @throws Exception + */ + public function __construct(Address $address, string $wasmId, array $constructorArgs, ?string $salt = null) + { + $this->address = $address; + $this->wasmId = $wasmId; + $this->constructorArgs = $constructorArgs; + $this->salt = $salt != null ? $salt : random_bytes(32); + parent::__construct(); + } + + public function toXdr() : XdrHostFunction { + return XdrHostFunction::forCreatingContractV2($this->address->toXdr(), + $this->wasmId, $this->salt, $this->constructorArgs); + } + + /** + * @throws Exception + */ + public static function fromXdr(XdrHostFunction $xdr) : CreateContractWithConstructorHostFunction { + $type = $xdr->type; + if ($type->value !== XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2 || $xdr->createContractV2 === null + || $xdr->createContractV2->contractIDPreimage->type->value !== XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS + || $xdr->createContractV2->executable->type->value !== XdrContractExecutableType::CONTRACT_EXECUTABLE_WASM) { + throw new Exception("Invalid argument"); + } + $wasmId = $xdr->createContractV2->executable->wasmIdHex; + $xdrAddress = $xdr->createContractV2->contractIDPreimage->address; + + if ($wasmId === null || $xdrAddress === null) { + throw new Exception("invalid argument"); + } + return new CreateContractWithConstructorHostFunction(Address::fromXdr($xdrAddress), $wasmId, + $xdr->createContractV2->constructorArgs, $xdr->createContract->contractIDPreimage->salt); + } + + /** + * @return Address + */ + public function getAddress(): Address + { + return $this->address; + } + + /** + * @param Address $address + */ + public function setAddress(Address $address): void + { + $this->address = $address; + } + + /** + * @return string + */ + public function getWasmId(): string + { + return $this->wasmId; + } + + /** + * @param string $wasmId + */ + public function setWasmId(string $wasmId): void + { + $this->wasmId = $wasmId; + } + + /** + * @return string + */ + public function getSalt(): string + { + return $this->salt; + } + + /** + * @param string $salt + */ + public function setSalt(string $salt): void + { + $this->salt = $salt; + } + + /** + * @return array + */ + public function getConstructorArgs(): array + { + return $this->constructorArgs; + } + + /** + * @param array $constructorArgs + */ + public function setConstructorArgs(array $constructorArgs): void + { + $this->constructorArgs = $constructorArgs; + } + +} \ No newline at end of file diff --git a/Soneso/StellarSDK/DeploySACWithAssetHostFunction.php b/Soneso/StellarSDK/DeploySACWithAssetHostFunction.php index c29d262..a72e3e7 100644 --- a/Soneso/StellarSDK/DeploySACWithAssetHostFunction.php +++ b/Soneso/StellarSDK/DeploySACWithAssetHostFunction.php @@ -34,15 +34,25 @@ public function toXdr() : XdrHostFunction { */ public static function fromXdr(XdrHostFunction $xdr) : DeploySACWithAssetHostFunction { $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_STELLAR_ASSET) { + if ($type->value !== XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT && + $type->value !== XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2) { throw new Exception("Invalid argument"); } - $xdrAsset = $xdr->createContract->contractIDPreimage->asset; - if ($xdrAsset == null) { - throw new Exception("invalid argument"); + $preimage = $xdr->createContract !== null ? $xdr->createContract->contractIDPreimage : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->contractIDPreimage : null); + $executableTypeValue = $xdr->createContract !== null ? $xdr->createContract->executable->type->value : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->executable->type->value : null); + $xdrAsset = $xdr->createContract !== null ? $xdr->createContract->contractIDPreimage->asset : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->contractIDPreimage->asset : null); + + if($preimage === null || $executableTypeValue === null || $xdrAsset === null) { + throw new Exception("Invalid argument"); + } + + if ($preimage->type->value !== XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ASSET || + $executableTypeValue !== XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET) { + throw new Exception("Invalid argument"); } return new DeploySACWithAssetHostFunction(Asset::fromXdr($xdrAsset)); diff --git a/Soneso/StellarSDK/DeploySACWithSourceAccountHostFunction.php b/Soneso/StellarSDK/DeploySACWithSourceAccountHostFunction.php index c74c41e..3fdd516 100644 --- a/Soneso/StellarSDK/DeploySACWithSourceAccountHostFunction.php +++ b/Soneso/StellarSDK/DeploySACWithSourceAccountHostFunction.php @@ -39,19 +39,28 @@ public function toXdr() : XdrHostFunction { */ public static function fromXdr(XdrHostFunction $xdr) : DeploySACWithSourceAccountHostFunction { $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_STELLAR_ASSET) { + if ($type->value !== XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT && + $type->value !== XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2) { throw new Exception("Invalid argument"); } - $xdrAddress = $xdr->createContract->contractIDPreimage->address; + $preimage = $xdr->createContract !== null ? $xdr->createContract->contractIDPreimage : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->contractIDPreimage : null); + $executableTypeValue = $xdr->createContract != null ? $xdr->createContract->executable->type->value : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->executable->type->value : null); + $xdrAddress = $xdr->createContract !== null ? $xdr->createContract->contractIDPreimage->address : + ($xdr->createContractV2 !== null ? $xdr->createContractV2->contractIDPreimage->address : null); - if ($xdrAddress == null) { - throw new Exception("invalid argument"); + if($preimage === null || $executableTypeValue === null || $xdrAddress === null) { + throw new Exception("Invalid argument"); + } + + if ($preimage->type->value !== XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS || + $executableTypeValue !== XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET) { + throw new Exception("Invalid argument"); } - return new DeploySACWithSourceAccountHostFunction(Address::fromXdr($xdrAddress), $xdr->createContract->contractIDPreimage->salt); + return new DeploySACWithSourceAccountHostFunction(Address::fromXdr($xdrAddress), $preimage->salt); } /** diff --git a/Soneso/StellarSDK/InvokeHostFunctionOperation.php b/Soneso/StellarSDK/InvokeHostFunctionOperation.php index 9c1eddb..a3a4a09 100644 --- a/Soneso/StellarSDK/InvokeHostFunctionOperation.php +++ b/Soneso/StellarSDK/InvokeHostFunctionOperation.php @@ -67,6 +67,23 @@ public static function fromXdrOperation(XdrInvokeHostFunctionOp $xdrOp): InvokeH return new InvokeHostFunctionOperation(DeploySACWithAssetHostFunction::fromXdr($xdrFunction), $auth); } break; + case XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2: + $createContractV2 = $xdrFunction->createContractV2; + if ($createContractV2 == null) { + throw new Exception("invalid argument"); + } + $contractIdPreimageTypeVal = $createContractV2->contractIDPreimage->type->value; + $executableTypeValue = $createContractV2->executable->type->value; + if ($contractIdPreimageTypeVal == XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS) { + if ($executableTypeValue == XdrContractExecutableType::CONTRACT_EXECUTABLE_WASM) { + return new InvokeHostFunctionOperation(CreateContractWithConstructorHostFunction::fromXdr($xdrFunction), $auth); + } else if ($executableTypeValue == XdrContractExecutableType::CONTRACT_EXECUTABLE_STELLAR_ASSET){ + return new InvokeHostFunctionOperation(DeploySACWithSourceAccountHostFunction::fromXdr($xdrFunction), $auth); + } + } else if ($executableTypeValue == XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ASSET) { + return new InvokeHostFunctionOperation(DeploySACWithAssetHostFunction::fromXdr($xdrFunction), $auth); + } + break; } throw new Exception("invalid argument"); } diff --git a/Soneso/StellarSDK/Responses/Asset/AssetResponse.php b/Soneso/StellarSDK/Responses/Asset/AssetResponse.php index dc88671..05ac788 100644 --- a/Soneso/StellarSDK/Responses/Asset/AssetResponse.php +++ b/Soneso/StellarSDK/Responses/Asset/AssetResponse.php @@ -16,10 +16,8 @@ class AssetResponse extends Response private string $pagingToken; private AssetAccountsResponse $accounts; private AssetBalancesResponse $balances; - private string $amount; private string $claimableBalancesAmount; private string $liquidityPoolsAmount; - private int $numAccounts; private int $numClaimableBalances; private int $numLiquidityPools; private ?int $numContracts = null; @@ -77,14 +75,6 @@ public function getBalances(): AssetBalancesResponse return $this->balances; } - /** - * @return string - */ - public function getAmount(): string - { - return $this->amount; - } - /** * @return string */ @@ -101,14 +91,6 @@ public function getLiquidityPoolsAmount(): string return $this->liquidityPoolsAmount; } - /** - * @return int - */ - public function getNumAccounts(): int - { - return $this->numAccounts; - } - /** * @return int */ @@ -201,12 +183,10 @@ protected function loadFromJson(array $json) : void { if (isset($json['paging_token'])) $this->pagingToken = $json['paging_token']; if (isset($json['accounts'])) $this->accounts = AssetAccountsResponse::fromJson($json['accounts']); if (isset($json['balances'])) $this->balances = AssetBalancesResponse::fromJson($json['balances']); - if (isset($json['amount'])) $this->amount = $json['amount']; if (isset($json['claimable_balances_amount'])) $this->claimableBalancesAmount = $json['claimable_balances_amount']; if (isset($json['liquidity_pools_amount'])) $this->liquidityPoolsAmount = $json['liquidity_pools_amount']; if (isset($json['contracts_amount'])) $this->contractsAmount = $json['contracts_amount']; if (isset($json['archived_contracts_amount'])) $this->archivedContractsAmount = $json['archived_contracts_amount']; - if (isset($json['num_accounts'])) $this->numAccounts = $json['num_accounts']; if (isset($json['num_claimable_balances'])) $this->numClaimableBalances = $json['num_claimable_balances']; if (isset($json['num_liquidity_pools'])) $this->numLiquidityPools = $json['num_liquidity_pools']; if (isset($json['num_contracts'])) $this->numContracts = $json['num_contracts']; diff --git a/Soneso/StellarSDK/Responses/Transaction/SubmitAsyncTransactionResponse.php b/Soneso/StellarSDK/Responses/Transaction/SubmitAsyncTransactionResponse.php index 74c5542..4fe8c7a 100644 --- a/Soneso/StellarSDK/Responses/Transaction/SubmitAsyncTransactionResponse.php +++ b/Soneso/StellarSDK/Responses/Transaction/SubmitAsyncTransactionResponse.php @@ -45,7 +45,12 @@ public static function fromJson(array $json, int $httpResponseStatusCode) : Subm { $txStatus = $json['tx_status']; $hash = $json['hash']; - $errorResultXdrBase64 = isset($json['error_result_xdr_base64']) ? $json['error_result_xdr_base64'] : null; + $errorResultXdrBase64 = null; + if (isset($json['errorResultXdr'])) { + $errorResultXdrBase64 = $json['errorResultXdr']; // protocol < 22 + } else if (isset($json['error_result_xdr'])) { + $errorResultXdrBase64 = $json['error_result_xdr']; // protocol 22 + } return new SubmitAsyncTransactionResponse( txStatus: $txStatus, hash: $hash, diff --git a/Soneso/StellarSDK/Responses/Transaction/TransactionResponse.php b/Soneso/StellarSDK/Responses/Transaction/TransactionResponse.php index a11d3b3..f78de0b 100644 --- a/Soneso/StellarSDK/Responses/Transaction/TransactionResponse.php +++ b/Soneso/StellarSDK/Responses/Transaction/TransactionResponse.php @@ -41,8 +41,7 @@ class TransactionResponse extends Response private string $resultMetaXdrBase64; private ?XdrTransactionMeta $resultMetaXdr = null; private ?string $feeMetaXdrBase64 = null; // todo resolve - private ?array $feeMetaXdr = null; // - private ?string $validAfter = null; // [XdrLedgerEntryChange] + private ?array $feeMetaXdr = null; private TransactionSignaturesResponse $signatures; private ?FeeBumpTransactionResponse $feeBumpTransactionResponse = null; private ?InnerTransactionResponse $innerTransactionResponse = null; @@ -225,14 +224,6 @@ public function getFeeMetaXdr(): ?array return $this->feeMetaXdr; } - /** - * @return string|null - */ - public function getValidAfter(): ?string - { - return $this->validAfter; - } - /** * @return TransactionSignaturesResponse */ @@ -338,7 +329,6 @@ protected function loadFromJson(array $json) : void { array_push($this->feeMetaXdr, XdrLedgerEntryChange::decode($xdrBuffer)); } } - if (isset($json['valid_after'])) $this->validAfter = $json['valid_after']; if (isset($json['memo_type'])) { $memoTypeStr = $json['memo_type']; diff --git a/Soneso/StellarSDK/SEP/TxRep/TxRep.php b/Soneso/StellarSDK/SEP/TxRep/TxRep.php index 7b852f7..50e9444 100644 --- a/Soneso/StellarSDK/SEP/TxRep/TxRep.php +++ b/Soneso/StellarSDK/SEP/TxRep/TxRep.php @@ -93,6 +93,7 @@ use Soneso\StellarSDK\Xdr\XdrContractIDPreimage; use Soneso\StellarSDK\Xdr\XdrContractIDPreimageType; use Soneso\StellarSDK\Xdr\XdrCreateContractArgs; +use Soneso\StellarSDK\Xdr\XdrCreateContractArgsV2; use Soneso\StellarSDK\Xdr\XdrDecoratedSignature; use Soneso\StellarSDK\Xdr\XdrEnvelopeType; use Soneso\StellarSDK\Xdr\XdrExtensionPoint; @@ -932,6 +933,24 @@ private static function getCreateContractArgs($prefix, array $map): XdrCreateCon return new XdrCreateContractArgs($preimage, $executable); } + private static function getCreateContractV2Args($prefix, array $map): XdrCreateContractArgsV2 + { + $preimage = self::getContractIDPreimage($prefix . 'contractIDPreimage.', $map); + $executable = self::getContractExecutable($prefix . 'executable.', $map); + $argsLen = self::getInt($prefix . 'constructorArgs.len', $map); + /** + * @var array $arguments + */ + $arguments = array(); + + for ($i = 0; $i < $argsLen; $i++) { + $next = self::getSCVal($prefix . 'constructorArgs[' . $i . '].', $map); + array_push($arguments, $next); + } + + return new XdrCreateContractArgsV2($preimage, $executable, $arguments); + } + private static function getInvokeContractArgs($prefix, array $map): XdrInvokeContractArgs { $address = self::getSCAddress($prefix . 'contractAddress.', $map); @@ -959,6 +978,9 @@ private static function getHostFunction($prefix, array $map): XdrHostFunction case 'HOST_FUNCTION_TYPE_CREATE_CONTRACT': $args = self::getCreateContractArgs($prefix . 'createContract.', $map); return XdrHostFunction::forCreatingContractWithArgs($args); + case 'HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2': + $args = self::getCreateContractV2Args($prefix . 'createContractV2.', $map); + return XdrHostFunction::forCreatingContractV2WithArgs($args); case 'HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM': $wasm = self::getString($prefix . 'wasm', $map); return XdrHostFunction::forUploadContractWasm(hex2bin($wasm)); @@ -1000,6 +1022,9 @@ private static function getSorobanAuthorizedFunction($prefix, array $map): XdrSo } else if ("SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN" === $type) { $args = self::getCreateContractArgs($prefix . 'createContractHostFn.', $map); return XdrSorobanAuthorizedFunction::forCreateContractArgs($args); + } else if ("SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN" === $type) { + $args = self::getCreateContractV2Args($prefix . 'createContractV2HostFn.', $map); + return XdrSorobanAuthorizedFunction::forCreateContractArgsV2($args); } else { throw new InvalidArgumentException('unknown ' . $prefix . 'type ' . $type); } @@ -2828,6 +2853,9 @@ private static function getOperationTx(AbstractOperation $operation, int $index, } else if ($hostFunctionXdr->type->value == XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT) { $lines += [$fnPrefix.'type' => 'HOST_FUNCTION_TYPE_CREATE_CONTRACT']; $lines = array_merge($lines, self::getCreateContractArgsTx($fnPrefix.'createContract.', $hostFunctionXdr->createContract)); + } else if ($hostFunctionXdr->type->value == XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2) { + $lines += [$fnPrefix.'type' => 'HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2']; + $lines = array_merge($lines, self::getCreateContractV2ArgsTx($fnPrefix.'createContractV2.', $hostFunctionXdr->createContractV2)); } else if ($hostFunctionXdr->type->value == XdrHostFunctionType::HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM) { $lines += [$fnPrefix.'type' => 'HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM']; $lines += [$fnPrefix.'wasm' => bin2hex($hostFunctionXdr->wasm->value)]; @@ -3108,6 +3136,20 @@ private static function getCreateContractArgsTx(string $prefix, XdrCreateContrac $lines = array_merge($lines, self::getContractIDPreimageTx($prefix.'contractIDPreimage.', $args->contractIDPreimage)); return array_merge($lines, self::getContractExecutableTx($prefix.'executable.', $args->executable)); } + + private static function getCreateContractV2ArgsTx(string $prefix, XdrCreateContractArgsV2 $args) : array { + $lines = array(); + $lines = array_merge($lines, self::getContractIDPreimageTx($prefix.'contractIDPreimage.', $args->contractIDPreimage)); + $lines = array_merge($lines, self::getContractExecutableTx($prefix.'executable.', $args->executable)); + $lines += [$prefix . 'constructorArgs.len' => strval(count($args->args))]; + $index = 0; + foreach ($args->constructorArgs as $val) { + $lines = array_merge($lines, self::getSCValTx($prefix.'constructorArgs['.$index.'].', $val)); + $index++; + } + return $lines; + } + private static function getInvokeContractArgsTx(string $prefix, XdrInvokeContractArgs $args) : array { $lines = array(); $lines = array_merge($lines, self::getSCAddressTx($prefix.'contractAddress.', $args->contractAddress)); @@ -3155,6 +3197,10 @@ private static function getSorobanAuthorizedFunctionTx(string $prefix, XdrSoroba $lines += [$prefix . 'type' => 'SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN']; $lines = array_merge($lines, self::getCreateContractArgsTx($prefix.'createContractHostFn.', $function->createContractHostFn)); break; + case XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN: + $lines += [$prefix . 'type' => 'SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN']; + $lines = array_merge($lines, self::getCreateContractV2ArgsTx($prefix.'createContractV2HostFn.', $function->createContractV2HostFn)); + break; } return $lines; } diff --git a/Soneso/StellarSDK/Soroban/Responses/EventInfo.php b/Soneso/StellarSDK/Soroban/Responses/EventInfo.php index a0b36bd..58860fc 100644 --- a/Soneso/StellarSDK/Soroban/Responses/EventInfo.php +++ b/Soneso/StellarSDK/Soroban/Responses/EventInfo.php @@ -35,14 +35,14 @@ class EventInfo public string $contractId; /** - * @var string $id Unique identifier for this event. + * @var ?string $pagingToken for paging if protocol version < 22 (Duplicate of id field, but in the standard place for pagination tokens) */ - public string $id; + public ?string $pagingToken = null; /** - * @var string $pagingToken Duplicate of id field, but in the standard place for pagination tokens. + * @var string $id Unique identifier for this event. */ - public string $pagingToken; + public string $id; /** * @var array $topic List containing the topic this event was emitted with. (>= 1 items, <= 4 items). @@ -70,7 +70,6 @@ class EventInfo * @param string $ledgerClosedAt ISO-8601 timestamp of the ledger closing time. * @param string $contractId StrKey representation of the contract address that emitted this event. ("C..."). * @param string $id Unique identifier for this event. - * @param string $pagingToken Duplicate of id field, but in the standard place for pagination tokens. * @param array $topic List containing the topic this event was emitted with. (>= 1 items, <= 4 items). * @param string $value The emitted body value of the event (serialized in a base64 xdr string). * @param bool $inSuccessfulContractCall If true the event was emitted during a successful contract call. @@ -82,11 +81,11 @@ public function __construct( string $ledgerClosedAt, string $contractId, string $id, - string $pagingToken, array $topic, string $value, bool $inSuccessfulContractCall, string $txHash, + ?string $pagingToken = null, ) { $this->type = $type; @@ -94,11 +93,11 @@ public function __construct( $this->ledgerClosedAt = $ledgerClosedAt; $this->contractId = $contractId; $this->id = $id; - $this->pagingToken = $pagingToken; $this->topic = $topic; $this->value = $value; $this->inSuccessfulContractCall = $inSuccessfulContractCall; $this->txHash = $txHash; + $this->pagingToken = $pagingToken; } public static function fromJson(array $json): EventInfo @@ -108,7 +107,6 @@ public static function fromJson(array $json): EventInfo $ledgerClosedAt = $json['ledgerClosedAt']; $contractId = $json['contractId']; $id = $json['id']; - $pagingToken = $json['pagingToken']; $value = $json['value']['xdr'] ?? $json['value']; $topic = array(); foreach ($json['topic'] as $val) { @@ -116,17 +114,21 @@ public static function fromJson(array $json): EventInfo } $inSuccessfulContractCall = $json['inSuccessfulContractCall']; $txHash = $json['txHash']; + $pagingToken = null; + if (isset($json['pagingToken'])) { + $pagingToken = $json['pagingToken']; // protocol < 22 + } return new EventInfo( $type, $ledger, $ledgerClosedAt, $contractId, $id, - $pagingToken, $topic, $value, $inSuccessfulContractCall, $txHash, + pagingToken: $pagingToken ); } @@ -210,22 +212,6 @@ public function setId(string $id): void $this->id = $id; } - /** - * @return string Duplicate of id field, but in the standard place for pagination tokens. - */ - public function getPagingToken(): string - { - return $this->pagingToken; - } - - /** - * @param string $pagingToken Duplicate of id field, but in the standard place for pagination tokens. - */ - public function setPagingToken(string $pagingToken): void - { - $this->pagingToken = $pagingToken; - } - /** * @return array List containing the topic this event was emitted with. (>= 1 items, <= 4 items). */ @@ -281,4 +267,36 @@ public function setInSuccessfulContractCall(bool $inSuccessfulContractCall): voi $this->inSuccessfulContractCall = $inSuccessfulContractCall; } + /** + * @return string|null for paging, only available for protocol version < 22 + */ + public function getPagingToken(): ?string + { + return $this->pagingToken; + } + + /** + * @param string|null $pagingToken for paging, only for protocol version < 22 + */ + public function setPagingToken(?string $pagingToken): void + { + $this->pagingToken = $pagingToken; + } + + /** + * @return string + */ + public function getTxHash(): string + { + return $this->txHash; + } + + /** + * @param string $txHash + */ + public function setTxHash(string $txHash): void + { + $this->txHash = $txHash; + } + } \ No newline at end of file diff --git a/Soneso/StellarSDK/Soroban/Responses/GetEventsResponse.php b/Soneso/StellarSDK/Soroban/Responses/GetEventsResponse.php index 8f6450f..0969e38 100644 --- a/Soneso/StellarSDK/Soroban/Responses/GetEventsResponse.php +++ b/Soneso/StellarSDK/Soroban/Responses/GetEventsResponse.php @@ -22,6 +22,11 @@ class GetEventsResponse extends SorobanRpcResponse */ public ?int $latestLedger = null; + /** + * @var String|null $cursor for pagination only available for protocol version >= 22 + */ + public ?String $cursor = null; + public static function fromJson(array $json): GetEventsResponse { $result = new GetEventsResponse($json); @@ -36,6 +41,9 @@ public static function fromJson(array $json): GetEventsResponse if (isset($json['result']['latestLedger'])) { $result->latestLedger = $json['result']['latestLedger']; } + if (isset($json['result']['cursor'])) { + $result->cursor = $json['result']['cursor']; // protocol >= 22 + } } else if (isset($json['error'])) { $result->error = SorobanRpcErrorResponse::fromJson($json); } @@ -74,4 +82,20 @@ public function setLatestLedger(?int $latestLedger): void $this->latestLedger = $latestLedger; } + /** + * @return String|null for pagination only available for protocol version >= 22 + */ + public function getCursor(): ?string + { + return $this->cursor; + } + + /** + * @param String|null $cursor for pagination only for protocol version >= 22 + */ + public function setCursor(?string $cursor): void + { + $this->cursor = $cursor; + } + } \ No newline at end of file diff --git a/Soneso/StellarSDK/Soroban/Responses/GetTransactionResponse.php b/Soneso/StellarSDK/Soroban/Responses/GetTransactionResponse.php index 9ff4a28..eb5977c 100644 --- a/Soneso/StellarSDK/Soroban/Responses/GetTransactionResponse.php +++ b/Soneso/StellarSDK/Soroban/Responses/GetTransactionResponse.php @@ -96,6 +96,11 @@ class GetTransactionResponse extends SorobanRpcResponse */ public ?string $resultMetaXdr = null; + /** + * @var string|null $txHash hex-encoded transaction hash string. Only available for protocol version >= 22 + */ + public ?string $txHash = null; + public static function fromJson(array $json) : GetTransactionResponse { $result = new GetTransactionResponse($json); if (isset($json['result'])) { @@ -136,6 +141,9 @@ public static function fromJson(array $json) : GetTransactionResponse { if (isset($json['result']['resultMetaXdr'])) { $result->resultMetaXdr = $json['result']['resultMetaXdr']; } + if (isset($json['result']['txHash'])) { + $result->txHash = $json['result']['txHash']; // protocol version >= 22 + } } else if (isset($json['error'])) { $result->error = SorobanRpcErrorResponse::fromJson($json); } @@ -332,4 +340,20 @@ public function getXdrTransactionMeta(): ? XdrTransactionMeta } return null; } + + /** + * @return string|null hex-encoded transaction hash string. Only available for protocol version >= 22 + */ + public function getTxHash(): ?string + { + return $this->txHash; + } + + /** + * @param string|null $txHash hex-encoded transaction hash string. Only for protocol version >= 22 + */ + public function setTxHash(?string $txHash): void + { + $this->txHash = $txHash; + } } \ No newline at end of file diff --git a/Soneso/StellarSDK/Soroban/Responses/GetVersionInfoResponse.php b/Soneso/StellarSDK/Soroban/Responses/GetVersionInfoResponse.php index cbd06c7..6908064 100644 --- a/Soneso/StellarSDK/Soroban/Responses/GetVersionInfoResponse.php +++ b/Soneso/StellarSDK/Soroban/Responses/GetVersionInfoResponse.php @@ -43,16 +43,28 @@ public static function fromJson(array $json) : GetVersionInfoResponse { $result->version = $json['result']['version']; } if (isset($json['result']['commit_hash'])) { - $result->commitHash = $json['result']['commit_hash']; + $result->commitHash = $json['result']['commit_hash']; // protocol < 22 + } + else if (isset($json['result']['commitHash'])) { + $result->commitHash = $json['result']['commitHash']; // protocol 22 } if (isset($json['result']['build_time_stamp'])) { - $result->buildTimeStamp = $json['result']['build_time_stamp']; + $result->buildTimeStamp = $json['result']['build_time_stamp']; // protocol < 22 + } + else if (isset($json['result']['buildTimestamp'])) { + $result->buildTimeStamp = $json['result']['buildTimestamp']; // protocol 22 } if (isset($json['result']['captive_core_version'])) { - $result->captiveCoreVersion = $json['result']['captive_core_version']; + $result->captiveCoreVersion = $json['result']['captive_core_version']; // protocol < 22 + } + if (isset($json['result']['captiveCoreVersion'])) { + $result->captiveCoreVersion = $json['result']['captiveCoreVersion']; // protocol 22 } if (isset($json['result']['protocol_version'])) { - $result->protocolVersion = $json['result']['protocol_version']; + $result->protocolVersion = $json['result']['protocol_version']; // protocol < 22 + } + if (isset($json['result']['protocolVersion'])) { + $result->protocolVersion = $json['result']['protocolVersion']; // protocol 22 } } else if (isset($json['error'])) { $result->error = SorobanRpcErrorResponse::fromJson($json); diff --git a/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionCost.php b/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionCost.php deleted file mode 100644 index 93fa0d6..0000000 --- a/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionCost.php +++ /dev/null @@ -1,71 +0,0 @@ -cpuInsns = intval($json['cpuInsns']); - $this->memBytes = intval($json['memBytes']); - } - - public static function fromJson(array $json) : SimulateTransactionCost { - $result = new SimulateTransactionCost(); - $result->loadFromJson($json); - return $result; - } - - /** - * @return int Number of the total cpu instructions consumed by this transaction. - */ - public function getCpuInsns(): int - { - return $this->cpuInsns; - } - - /** - * @param int $cpuInsns Number of the total cpu instructions consumed by this transaction - */ - public function setCpuInsns(int $cpuInsns): void - { - $this->cpuInsns = $cpuInsns; - } - - /** - * @return int Number of the total memory bytes allocated by this transaction. - */ - public function getMemBytes(): int - { - return $this->memBytes; - } - - /** - * @param int $memBytes Number of the total memory bytes allocated by this transaction. - */ - public function setMemBytes(int $memBytes): void - { - $this->memBytes = $memBytes; - } - -} \ No newline at end of file diff --git a/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionResponse.php b/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionResponse.php index cb9b21f..1987c7b 100644 --- a/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionResponse.php +++ b/Soneso/StellarSDK/Soroban/Responses/SimulateTransactionResponse.php @@ -29,12 +29,6 @@ class SimulateTransactionResponse extends SorobanRpcResponse */ public ?int $minResourceFee = null; - /** - * @var SimulateTransactionCost $cost (optional) - The cost object is legacy, inaccurate, and will be - * deprecated in future RPC releases. Please decode transactionData XDR to retrieve the correct resources. - */ - public SimulateTransactionCost $cost; - /** * @var SimulateTransactionResults|null This object will only have one element: the result for the Host * Function invocation. Only present on successful simulation (i.e. no error) of InvokeHostFunction operations. @@ -90,9 +84,6 @@ public static function fromJson(array $json) : SimulateTransactionResponse { $result->results->add($value); } } - if (isset($json['result']['cost'])) { - $result->cost = SimulateTransactionCost::fromJson($json['result']['cost']); - } if (isset($json['result']['latestLedger'])) { $result->latestLedger = $json['result']['latestLedger']; } @@ -250,24 +241,6 @@ public function setResultError(?string $resultError): void $this->resultError = $resultError; } - /** - * @return SimulateTransactionCost (optional) - The cost object is legacy, inaccurate, and will be - * deprecated in future RPC releases. Please decode transactionData XDR to retrieve the correct resources. - */ - public function getCost(): SimulateTransactionCost - { - return $this->cost; - } - - /** - * @param SimulateTransactionCost $cost (optional) - The cost object is legacy, inaccurate, and will be - * deprecated in future RPC releases. Please decode transactionData XDR to retrieve the correct resources. - */ - public function setCost(SimulateTransactionCost $cost): void - { - $this->cost = $cost; - } - /** * @return array|null (optional) Array of serialized base64 strings - Array of the events emitted during * the contract invocation. The events are ordered by their emission time. (an array of serialized base64 strings). diff --git a/Soneso/StellarSDK/Soroban/Responses/TransactionInfo.php b/Soneso/StellarSDK/Soroban/Responses/TransactionInfo.php index 08b9da3..c119493 100644 --- a/Soneso/StellarSDK/Soroban/Responses/TransactionInfo.php +++ b/Soneso/StellarSDK/Soroban/Responses/TransactionInfo.php @@ -42,15 +42,20 @@ class TransactionInfo */ public int $ledger; /** - * @var int $createdAt The unix timestamp of when the transaction was included in the ledger. + * @var string $createdAt The unix timestamp of when the transaction was included in the ledger. */ - public int $createdAt; + public string $createdAt; /** * @var array|null (optional) A base64 encoded slice of xdr.DiagnosticEvent. * This is only present if the ENABLE_SOROBAN_DIAGNOSTIC_EVENTS has been enabled in the stellar-core config. */ public ?array $diagnosticEventsXdr = null; + /** + * @var ?string $txHash hex-encoded transaction hash string. Only available for protocol version >= 22 + */ + public ?string $txHash; + /** * @param string $status Indicates whether the transaction was successful or not. * @param int $applicationOrder The 1-based index of the transaction among all transactions included in the ledger. @@ -59,7 +64,8 @@ class TransactionInfo * @param string $resultXdr A base64 encoded string of the raw TransactionResult XDR struct for this transaction. * @param string $resultMetaXdr A base64 encoded string of the raw TransactionMeta XDR struct for this transaction. * @param int $ledger The sequence number of the ledger which included the transaction. - * @param int $createdAt The unix timestamp of when the transaction was included in the ledger. + * @param string $createdAt The unix timestamp of when the transaction was included in the ledger. + * @param string|null $txHash hex-encoded transaction hash string. Only available for protocol version >= 22 * @param array|null $diagnosticEventsXdr (optional) A base64 encoded slice of xdr.DiagnosticEvent. * This is only present if the ENABLE_SOROBAN_DIAGNOSTIC_EVENTS has been enabled in the stellar-core config. */ @@ -71,7 +77,8 @@ public function __construct( string $resultXdr, string $resultMetaXdr, int $ledger, - int $createdAt, + string $createdAt, + ?string $txHash = null, ?array $diagnosticEventsXdr = null, ) { @@ -83,6 +90,7 @@ public function __construct( $this->resultMetaXdr = $resultMetaXdr; $this->ledger = $ledger; $this->createdAt = $createdAt; + $this->txHash = $txHash; $this->diagnosticEventsXdr = $diagnosticEventsXdr; } @@ -100,6 +108,11 @@ public static function fromJson(array $json): TransactionInfo } } + $txHash = null; + if (isset($json["txHash"])) { + $txHash = $json["txHash"]; // protocol version >= 22 + } + return new TransactionInfo( $json['status'], $json['applicationOrder'], @@ -108,10 +121,9 @@ public static function fromJson(array $json): TransactionInfo $json['resultXdr'], $json['resultMetaXdr'], $json['ledger'], - $json['createdAt'], - $diagnosticEventsXdr, + strval($json['createdAt']), + txHash: $txHash, + diagnosticEventsXdr: $diagnosticEventsXdr, ); } - - } \ No newline at end of file diff --git a/Soneso/StellarSDK/Soroban/SorobanAuthorizedFunction.php b/Soneso/StellarSDK/Soroban/SorobanAuthorizedFunction.php index 09f3faa..a902421 100644 --- a/Soneso/StellarSDK/Soroban/SorobanAuthorizedFunction.php +++ b/Soneso/StellarSDK/Soroban/SorobanAuthorizedFunction.php @@ -8,6 +8,7 @@ use InvalidArgumentException; use Soneso\StellarSDK\Xdr\XdrCreateContractArgs; +use Soneso\StellarSDK\Xdr\XdrCreateContractArgsV2; use Soneso\StellarSDK\Xdr\XdrInvokeContractArgs; use Soneso\StellarSDK\Xdr\XdrSorobanAuthorizedFunction; use Soneso\StellarSDK\Xdr\XdrSorobanAuthorizedFunctionType; @@ -21,22 +22,24 @@ class SorobanAuthorizedFunction { public ?XdrInvokeContractArgs $contractFn = null; public ?XdrCreateContractArgs $createContractHostFn = null; + public ?XdrCreateContractArgsV2 $createContractV2HostFn = null; /** * @param XdrInvokeContractArgs|null $contractFn * @param XdrCreateContractArgs|null $createContractHostFn */ - public function __construct(?XdrInvokeContractArgs $contractFn = null, ?XdrCreateContractArgs $createContractHostFn = null) + public function __construct( + ?XdrInvokeContractArgs $contractFn = null, + ?XdrCreateContractArgs $createContractHostFn = null, + ?XdrCreateContractArgsV2 $createContractV2HostFn = null) { - if ($contractFn == null && $createContractHostFn == null) { - throw new InvalidArgumentException("Invalid arguments"); - } - if ($contractFn != null && $createContractHostFn != null) { + if ($contractFn == null && $createContractHostFn == null && $createContractV2HostFn == null) { throw new InvalidArgumentException("Invalid arguments"); } $this->contractFn = $contractFn; $this->createContractHostFn = $createContractHostFn; + $this->createContractV2HostFn = $createContractV2HostFn; } public static function forContractFunction(Address $contractAddress, string $functionName, array $args = array()) : SorobanAuthorizedFunction { @@ -48,11 +51,17 @@ public static function forCreateContractFunction(XdrCreateContractArgs $createCo return new SorobanAuthorizedFunction(null, $createContractHostFn); } + public static function forCreateContractWithConstructorFunction(XdrCreateContractArgsV2 $createContractV2HostFn) : SorobanAuthorizedFunction { + return new SorobanAuthorizedFunction(null, null, $createContractV2HostFn); + } + public static function fromXdr(XdrSorobanAuthorizedFunction $xdr) : SorobanAuthorizedFunction { if ($xdr->type->value == XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN && $xdr->contractFn != null) { return new SorobanAuthorizedFunction($xdr->contractFn); + } else if ($xdr->type->value == XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN && $xdr->createContractHostFn != null) { + return new SorobanAuthorizedFunction(null, $xdr->createContractHostFn); } - return new SorobanAuthorizedFunction(null, $xdr->createContractHostFn); + return new SorobanAuthorizedFunction(null, null, $xdr->createContractV2HostFn); } public function toXdr(): XdrSorobanAuthorizedFunction { @@ -60,9 +69,13 @@ public function toXdr(): XdrSorobanAuthorizedFunction { $af = new XdrSorobanAuthorizedFunction(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN()); $af->contractFn = $this->contractFn; return $af; + } else if ($this->createContractHostFn != null) { + $af = new XdrSorobanAuthorizedFunction(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN()); + $af->createContractHostFn = $this->createContractHostFn; + return $af; } - $af = new XdrSorobanAuthorizedFunction(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN()); - $af->createContractHostFn = $this->createContractHostFn; + $af = new XdrSorobanAuthorizedFunction(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN()); + $af->createContractV2HostFn = $this->createContractV2HostFn; return $af; } @@ -98,4 +111,20 @@ public function setCreateContractHostFn(?XdrCreateContractArgs $createContractHo $this->createContractHostFn = $createContractHostFn; } + /** + * @return XdrCreateContractArgsV2|null + */ + public function getCreateContractV2HostFn(): ?XdrCreateContractArgsV2 + { + return $this->createContractV2HostFn; + } + + /** + * @param XdrCreateContractArgsV2|null $createContractV2HostFn + */ + public function setCreateContractV2HostFn(?XdrCreateContractArgsV2 $createContractV2HostFn): void + { + $this->createContractV2HostFn = $createContractV2HostFn; + } + } \ No newline at end of file diff --git a/Soneso/StellarSDK/Xdr/XdrCreateContractArgsV2.php b/Soneso/StellarSDK/Xdr/XdrCreateContractArgsV2.php new file mode 100644 index 0000000..649131a --- /dev/null +++ b/Soneso/StellarSDK/Xdr/XdrCreateContractArgsV2.php @@ -0,0 +1,53 @@ + + */ + public array $constructorArgs; + + /** + * @param XdrContractIDPreimage $contractIDPreimage + * @param XdrContractExecutable $executable + * @param array $constructorArgs + */ + public function __construct(XdrContractIDPreimage $contractIDPreimage, XdrContractExecutable $executable, array $constructorArgs) + { + $this->contractIDPreimage = $contractIDPreimage; + $this->executable = $executable; + $this->constructorArgs = $constructorArgs; + } + + + public function encode(): string { + $bytes = $this->contractIDPreimage->encode(); + $bytes .= $this->executable->encode(); + $bytes .= XdrEncoder::integer32(count($this->constructorArgs)); + foreach($this->constructorArgs as $val) { + $bytes .= $val->encode(); + } + return $bytes; + } + + public static function decode(XdrBuffer $xdr): XdrCreateContractArgsV2 { + $preimage = XdrContractIDPreimage::decode($xdr); + $exec = XdrContractExecutable::decode($xdr); + $valCount = $xdr->readInteger32(); + $argsArr = array(); + for ($i = 0; $i < $valCount; $i++) { + array_push($argsArr, XdrSCVal::decode($xdr)); + } + + return new XdrCreateContractArgsV2($preimage, $exec, $argsArr); + } +} \ No newline at end of file diff --git a/Soneso/StellarSDK/Xdr/XdrHostFunction.php b/Soneso/StellarSDK/Xdr/XdrHostFunction.php index ff18d8f..4294284 100644 --- a/Soneso/StellarSDK/Xdr/XdrHostFunction.php +++ b/Soneso/StellarSDK/Xdr/XdrHostFunction.php @@ -13,6 +13,7 @@ class XdrHostFunction public XdrHostFunctionType $type; public ?XdrInvokeContractArgs $invokeContract = null; public ?XdrCreateContractArgs $createContract = null; + public ?XdrCreateContractArgsV2 $createContractV2 = null; public ?XdrDataValueMandatory $wasm = null; /** @@ -37,6 +38,9 @@ public function encode(): string { case XdrHostFunctionType::HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: $bytes .= $this->wasm->encode(); break; + case XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2: + $bytes .= $this->createContractV2->encode(); + break; } return $bytes; } @@ -53,6 +57,9 @@ public static function decode(XdrBuffer $xdr): XdrHostFunction { case XdrHostFunctionType::HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM: $result->wasm = XdrDataValueMandatory::decode($xdr); break; + case XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2: + $result->createContractV2 = XdrCreateContractArgsV2::decode($xdr); + break; } return $result; } @@ -80,6 +87,24 @@ public static function forCreatingContract(XdrSCAddress $address, string $wasmId return $result; } + /** + * @param XdrSCAddress $address + * @param string $wasmIdHex + * @param string $salt + * @param array $constructorArgs + * @return XdrHostFunction + */ + public static function forCreatingContractV2(XdrSCAddress $address, string $wasmIdHex, string $salt, array $constructorArgs) : XdrHostFunction { + $result = new XdrHostFunction(XdrHostFunctionType::CREATE_CONTRACT_V2()); + $cId = new XdrContractIDPreimage(XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS()); + $cId->address = $address; + $cId->salt = $salt; + $cCode = new XdrContractExecutable(XdrContractExecutableType::CONTRACT_EXECUTABLE_WASM()); + $cCode->wasmIdHex = $wasmIdHex; + $result->createContractV2 = new XdrCreateContractArgsV2($cId, $cCode, $constructorArgs); + return $result; + } + public static function forDeploySACWithSourceAccount(XdrSCAddress $address, string $salt) : XdrHostFunction { $result = new XdrHostFunction(XdrHostFunctionType::CREATE_CONTRACT()); $cId = new XdrContractIDPreimage(XdrContractIDPreimageType::CONTRACT_ID_PREIMAGE_FROM_ADDRESS()); @@ -105,6 +130,12 @@ public static function forCreatingContractWithArgs(XdrCreateContractArgs $args) return $result; } + public static function forCreatingContractV2WithArgs(XdrCreateContractArgsV2 $args) : XdrHostFunction { + $result = new XdrHostFunction(XdrHostFunctionType::CREATE_CONTRACT_V2()); + $result->createContractV2 = $args; + return $result; + } + /** * @return XdrHostFunctionType */ @@ -169,4 +200,19 @@ public function setWasm(?XdrDataValueMandatory $wasm): void $this->wasm = $wasm; } + /** + * @return XdrCreateContractArgsV2|null + */ + public function getCreateContractV2(): ?XdrCreateContractArgsV2 + { + return $this->createContractV2; + } + + /** + * @param XdrCreateContractArgsV2|null $createContractV2 + */ + public function setCreateContractV2(?XdrCreateContractArgsV2 $createContractV2): void + { + $this->createContractV2 = $createContractV2; + } } \ No newline at end of file diff --git a/Soneso/StellarSDK/Xdr/XdrHostFunctionType.php b/Soneso/StellarSDK/Xdr/XdrHostFunctionType.php index 522579e..64d32a5 100644 --- a/Soneso/StellarSDK/Xdr/XdrHostFunctionType.php +++ b/Soneso/StellarSDK/Xdr/XdrHostFunctionType.php @@ -13,6 +13,7 @@ class XdrHostFunctionType const HOST_FUNCTION_TYPE_INVOKE_CONTRACT = 0; const HOST_FUNCTION_TYPE_CREATE_CONTRACT = 1; const HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM = 2; + const HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2 = 3; public function __construct(int $value) { @@ -46,6 +47,10 @@ public static function CREATE_CONTRACT() : XdrHostFunctionType { return new XdrHostFunctionType(XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT); } + public static function CREATE_CONTRACT_V2() : XdrHostFunctionType { + return new XdrHostFunctionType(XdrHostFunctionType::HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2); + } + public static function UPLOAD_CONTRACT_WASM() : XdrHostFunctionType { return new XdrHostFunctionType(XdrHostFunctionType::HOST_FUNCTION_TYPE_UPLOAD_CONTRACT_WASM); } diff --git a/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunction.php b/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunction.php index 686159e..109cf78 100644 --- a/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunction.php +++ b/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunction.php @@ -12,6 +12,7 @@ class XdrSorobanAuthorizedFunction public XdrSorobanAuthorizedFunctionType $type; public ?XdrInvokeContractArgs $contractFn; public ?XdrCreateContractArgs $createContractHostFn = null; + public ?XdrCreateContractArgsV2 $createContractV2HostFn = null; /** * @param XdrSorobanAuthorizedFunctionType $type @@ -32,6 +33,9 @@ public function encode(): string { case XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: $bytes .= $this->createContractHostFn->encode(); break; + case XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN: + $bytes .= $this->createContractV2HostFn->encode(); + break; } return $bytes; } @@ -45,6 +49,9 @@ public static function decode(XdrBuffer $xdr): XdrSorobanAuthorizedFunction { case XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN: $result->createContractHostFn = XdrCreateContractArgs::decode($xdr); break; + case XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN: + $result->createContractV2HostFn = XdrCreateContractArgsV2::decode($xdr); + break; } return $result; } @@ -61,6 +68,12 @@ public static function forCreateContractArgs(XdrCreateContractArgs $args): XdrSo return $result; } + public static function forCreateContractArgsV2(XdrCreateContractArgsV2 $args): XdrSorobanAuthorizedFunction { + $result = new XdrSorobanAuthorizedFunction(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN()); + $result->createContractV2HostFn = $args; + return $result; + } + /** * @return XdrSorobanAuthorizedFunctionType */ @@ -109,4 +122,20 @@ public function setCreateContractHostFn(?XdrCreateContractArgs $createContractHo $this->createContractHostFn = $createContractHostFn; } + /** + * @return XdrCreateContractArgsV2|null + */ + public function getCreateContractV2HostFn(): ?XdrCreateContractArgsV2 + { + return $this->createContractV2HostFn; + } + + /** + * @param XdrCreateContractArgsV2|null $createContractV2HostFn + */ + public function setCreateContractV2HostFn(?XdrCreateContractArgsV2 $createContractV2HostFn): void + { + $this->createContractV2HostFn = $createContractV2HostFn; + } + } \ No newline at end of file diff --git a/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunctionType.php b/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunctionType.php index 4c6825f..bc2fbf7 100644 --- a/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunctionType.php +++ b/Soneso/StellarSDK/Xdr/XdrSorobanAuthorizedFunctionType.php @@ -12,6 +12,7 @@ class XdrSorobanAuthorizedFunctionType const SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN = 0; const SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN = 1; + const SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN = 2; public function __construct(int $value) { @@ -44,4 +45,8 @@ public static function SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN() : XdrSorob public static function SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN() : XdrSorobanAuthorizedFunctionType { return new XdrSorobanAuthorizedFunctionType(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_HOST_FN); } + + public static function SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN() : XdrSorobanAuthorizedFunctionType { + return new XdrSorobanAuthorizedFunctionType(XdrSorobanAuthorizedFunctionType::SOROBAN_AUTHORIZED_FUNCTION_TYPE_CREATE_CONTRACT_V2_HOST_FN); + } } \ No newline at end of file diff --git a/Soneso/StellarSDKTests/QueryTest.php b/Soneso/StellarSDKTests/QueryTest.php index 3fe3555..cb3ac8d 100644 --- a/Soneso/StellarSDKTests/QueryTest.php +++ b/Soneso/StellarSDKTests/QueryTest.php @@ -152,7 +152,7 @@ public function testQueryForClaimableBalance(): void { $sdk = StellarSDK::getTestNetInstance(); // get balance id from ClaimableBalancesTest - $bId = "000000009469cd35e0d2184df3e4b235438f89d22e5c9a02228d2fb9bae7ca74b5ccf8cb"; + $bId = "0000000091f7a7d65ac1fd7a853ee00d0929f5093fc80d90574e9b5506c4e14d4b46e753"; $response = $sdk->operations()->forClaimableBalance($bId)->limit(1)->order("desc")->execute(); $this->assertTrue($response->getOperations()->count() == 1); $response = $sdk->transactions()->forClaimableBalance($bId)->limit(1)->order("desc")->execute(); diff --git a/Soneso/StellarSDKTests/SorobanAuthTest.php b/Soneso/StellarSDKTests/SorobanAuthTest.php index a5f0b16..0f49368 100644 --- a/Soneso/StellarSDKTests/SorobanAuthTest.php +++ b/Soneso/StellarSDKTests/SorobanAuthTest.php @@ -9,8 +9,8 @@ use Exception; use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\TestCase; +use Soneso\StellarSDK\CreateContractWithConstructorHostFunction; use Soneso\StellarSDK\ExtendFootprintTTLOperationBuilder; -use Soneso\StellarSDK\CreateContractHostFunction; use Soneso\StellarSDK\Crypto\KeyPair; use Soneso\StellarSDK\InvokeContractHostFunction; use Soneso\StellarSDK\InvokeHostFunctionOperationBuilder; @@ -49,7 +49,7 @@ class SorobanAuthTest extends TestCase const TESTNET_SERVER_URL = "https://soroban-testnet.stellar.org"; const FUTURENET_SERVER_URL = "https://rpc-futurenet.stellar.org"; - private string $testOn = 'testnet'; // 'futurenet' + private string $testOn = 'futurenet'; // testnet private Network $network; private SorobanServer $server; private StellarSDK $sdk; @@ -465,7 +465,7 @@ private function deployContract(SorobanServer $server, String $pathToCode, KeyPa $this->bumpContractCodeFootprint($server, $submitterKp, $wasmId, 100000); // create contract - $createContractHostFunction = new CreateContractHostFunction(Address::fromAccountId($submitterId), $wasmId); + $createContractHostFunction = new CreateContractWithConstructorHostFunction(Address::fromAccountId($submitterId), $wasmId, []); $builder = new InvokeHostFunctionOperationBuilder($createContractHostFunction); $op = $builder->build(); diff --git a/Soneso/StellarSDKTests/SorobanCustomAccountTest.php b/Soneso/StellarSDKTests/SorobanCustomAccountTest.php index a57a1f2..4f4462d 100644 --- a/Soneso/StellarSDKTests/SorobanCustomAccountTest.php +++ b/Soneso/StellarSDKTests/SorobanCustomAccountTest.php @@ -348,7 +348,7 @@ private function deployContract(SorobanServer $server, String $pathToCode, KeyPa sleep(5); $result = array(); - //$this->restoreContractFootprint($server, $submitterKp, $pathToCode); + $this->restoreContractFootprint($server, $submitterKp, $pathToCode); // upload contract wasm $contractCode = file_get_contents($pathToCode, false); diff --git a/Soneso/StellarSDKTests/SorobanTest.php b/Soneso/StellarSDKTests/SorobanTest.php index 08b8018..41d98a6 100644 --- a/Soneso/StellarSDKTests/SorobanTest.php +++ b/Soneso/StellarSDKTests/SorobanTest.php @@ -134,7 +134,7 @@ public function testSoroban(): void // get transactions $latestLedgerResponse = $this->server->getLatestLedger(); assertNotNull($latestLedgerResponse->sequence); - $startLedger = $latestLedgerResponse->sequence - 20; + $startLedger = $latestLedgerResponse->sequence - 200; $paginationOptions = new PaginationOptions(limit: 2); $getTransactionsRequest = new GetTransactionsRequest( startLedger: $startLedger, @@ -182,8 +182,6 @@ public function testSoroban(): void $this->assertEquals(1, $simulateResponse->results->count()); $this->assertNotNull($simulateResponse->getTransactionData()); $this->assertNotNull($simulateResponse->getFootprint()); - $this->assertGreaterThan(1, $simulateResponse->cost->cpuInsns); - $this->assertGreaterThan(1, $simulateResponse->cost->memBytes); $this->assertGreaterThan(1, $simulateResponse->minResourceFee); $transactionData = $simulateResponse->transactionData; @@ -270,8 +268,6 @@ public function testSoroban(): void $this->assertNotNull($simulateResponse->getTransactionData()); $this->assertNotNull($simulateResponse->getSorobanAuth()); $this->assertNotNull($simulateResponse->getFootprint()); - $this->assertGreaterThan(1, $simulateResponse->cost->cpuInsns); - $this->assertGreaterThan(1, $simulateResponse->cost->memBytes); $this->assertGreaterThan(1, $simulateResponse->minResourceFee); // set the transaction data + fee + auth and sign @@ -383,8 +379,6 @@ public function testSoroban(): void $this->assertEquals(1, $simulateResponse->results->count()); $this->assertNotNull($simulateResponse->getTransactionData()); $this->assertNotNull($simulateResponse->getFootprint()); - $this->assertGreaterThan(1, $simulateResponse->cost->cpuInsns); - $this->assertGreaterThan(1, $simulateResponse->cost->memBytes); $this->assertGreaterThan(1, $simulateResponse->minResourceFee); // set the transaction data + fee and sign @@ -474,8 +468,6 @@ public function testSoroban(): void $this->assertNotNull($simulateResponse->getTransactionData()); $this->assertNotNull($simulateResponse->getSorobanAuth()); $this->assertNotNull($simulateResponse->getFootprint()); - $this->assertGreaterThan(1, $simulateResponse->cost->cpuInsns); - $this->assertGreaterThan(1, $simulateResponse->cost->memBytes); $this->assertGreaterThan(1, $simulateResponse->minResourceFee); if ($this->testOn === 'futurenet') { $this->assertNotNull($simulateResponse->stateChanges); @@ -485,10 +477,6 @@ public function testSoroban(): void assertNotNull($after); } - /*print("Cost cpu: " . $simulateResponse->cost->cpuInsns . PHP_EOL); - print("Cost mem: " . $simulateResponse->cost->memBytes . PHP_EOL); - print("min res fee: " . $simulateResponse->minResourceFee . PHP_EOL);*/ - // set the transaction data and sign $transaction->setSorobanTransactionData($simulateResponse->getTransactionData()); $transaction->setSorobanAuth($simulateResponse->getSorobanAuth()); @@ -587,8 +575,6 @@ public function testSoroban(): void $this->assertNotNull($simulateResponse->results->toArray()[0]->getResultValue()); $this->assertNotNull($simulateResponse->getTransactionData()); $this->assertNotNull($simulateResponse->getFootprint()); - $this->assertGreaterThan(1, $simulateResponse->cost->cpuInsns); - $this->assertGreaterThan(1, $simulateResponse->cost->memBytes); $this->assertGreaterThan(1, $simulateResponse->minResourceFee); diff --git a/composer.json b/composer.json index a622b7b..d7072b5 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,6 @@ } ], "require-dev" : { - "phpunit/phpunit" : "~9.5" + "phpunit/phpunit" : "~10.0" } }