├── .github ├── extraton_elephant.png └── workflows │ ├── client-package-macos.yml │ └── client-package-ubuntu.yml ├── .gitignore ├── .php_cs.dist ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── bin └── .gitkeep ├── composer.json ├── examples ├── catching_exceptions.php ├── client_api.php ├── client_version.php ├── crypto_generate_random_sign_keys.php ├── crypto_nacl_sign.php ├── get_test_rubies.php ├── net_subscribe_collection.php ├── processing_process_message.php ├── send_rubies_with_comment_to_surf.php └── utils_convert_address.php ├── phpstan-baseline.neon ├── phpstan.neon.dist ├── phpunit.xml.dist ├── src ├── Abi.php ├── AbstractModule.php ├── App │ └── AppInterface.php ├── Binding │ ├── Binding.php │ ├── Encoder.php │ └── Type │ │ └── ResponseType.php ├── Boc.php ├── Composer │ └── Scripts.php ├── Crypto.php ├── Debot.php ├── Entity │ ├── Abi │ │ ├── AbiType.php │ │ ├── CallSet.php │ │ ├── DecodedMessageBody.php │ │ ├── DeploySet.php │ │ ├── FunctionHeader.php │ │ ├── MessageSource.php │ │ ├── ResultOfAttachSignature.php │ │ ├── ResultOfAttachSignatureToMessageBody.php │ │ ├── ResultOfDecodeData.php │ │ ├── ResultOfEncodeAccount.php │ │ ├── ResultOfEncodeInternalMessage.php │ │ ├── ResultOfEncodeMessage.php │ │ ├── ResultOfEncodeMessageBody.php │ │ ├── Signer.php │ │ ├── StateInitParams.php │ │ └── StateInitSource.php │ ├── AbstractData.php │ ├── AbstractResult.php │ ├── App │ │ └── AppRequestResult.php │ ├── Boc │ │ ├── BuilderOp.php │ │ ├── CacheType.php │ │ ├── ResultOfBocCacheGet.php │ │ ├── ResultOfBocCacheSet.php │ │ ├── ResultOfEncodeBoc.php │ │ ├── ResultOfGetBlockchainConfig.php │ │ ├── ResultOfGetBocHash.php │ │ ├── ResultOfGetCodeFromTvc.php │ │ └── ResultOfParse.php │ ├── Client │ │ ├── ClientError.php │ │ ├── ResultOfBuildInfo.php │ │ ├── ResultOfGetApiReference.php │ │ └── ResultOfVersion.php │ ├── Crypto │ │ ├── AesParams.php │ │ ├── EncryptionAlgorithm.php │ │ ├── KeyPair.php │ │ ├── RegisteredEncryptionBox.php │ │ ├── ResultOfChaCha20.php │ │ ├── ResultOfConvertPublicKeyToTonSafeFormat.php │ │ ├── ResultOfEncryptionBoxDecrypt.php │ │ ├── ResultOfEncryptionBoxEncrypt.php │ │ ├── ResultOfEncryptionBoxGetInfo.php │ │ ├── ResultOfFactorize.php │ │ ├── ResultOfGenerateMnemonic.php │ │ ├── ResultOfGenerateRandomBytes.php │ │ ├── ResultOfGenerateSignKeys.php │ │ ├── ResultOfGetSigningBox.php │ │ ├── ResultOfHDKeyPublicFromXPrv.php │ │ ├── ResultOfHDKeySecretFromXPrv.php │ │ ├── ResultOfHDKeyXPrv.php │ │ ├── ResultOfHash.php │ │ ├── ResultOfMnemonicVerify.php │ │ ├── ResultOfMnemonicWords.php │ │ ├── ResultOfModularPower.php │ │ ├── ResultOfNaclBox.php │ │ ├── ResultOfNaclBoxOpen.php │ │ ├── ResultOfNaclSign.php │ │ ├── ResultOfNaclSignDetached.php │ │ ├── ResultOfNaclSignDetachedVerify.php │ │ ├── ResultOfNaclSignOpen.php │ │ ├── ResultOfScrypt.php │ │ ├── ResultOfSign.php │ │ ├── ResultOfSigningBoxGetPublicKey.php │ │ ├── ResultOfSigningBoxSign.php │ │ ├── ResultOfTonCrc16.php │ │ └── ResultOfVerifySignature.php │ ├── Debot │ │ ├── DebotAction.php │ │ └── RegisteredDebot.php │ ├── Net │ │ ├── AbstractQuery.php │ │ ├── Aggregation.php │ │ ├── DeepFilters.php │ │ ├── EndpointsSet.php │ │ ├── Event.php │ │ ├── Filters.php │ │ ├── MessageNode.php │ │ ├── OrderBy.php │ │ ├── ParamsOfAggregateCollection.php │ │ ├── ParamsOfBatchQuery.php │ │ ├── ParamsOfQueryCollection.php │ │ ├── ParamsOfSubscribeCollection.php │ │ ├── ParamsOfWaitForCollection.php │ │ ├── QueryInterface.php │ │ ├── RegisteredIterator.php │ │ ├── ResultOfAggregateCollection.php │ │ ├── ResultOfBatchQuery.php │ │ ├── ResultOfFindLastShardBlock.php │ │ ├── ResultOfIteratorNext.php │ │ ├── ResultOfQuery.php │ │ ├── ResultOfQueryCollection.php │ │ ├── ResultOfQueryCounterparties.php │ │ ├── ResultOfQueryTransactionTree.php │ │ ├── ResultOfSubscribeCollection.php │ │ ├── ResultOfWaitForCollection.php │ │ └── TransactionNode.php │ ├── Params.php │ ├── Processing │ │ ├── DecodedOutput.php │ │ ├── ProcessingEvent.php │ │ ├── ResultOfProcessMessage.php │ │ └── ResultOfSendMessage.php │ ├── Tvm │ │ ├── AccountForExecutor.php │ │ ├── ExecutionOptions.php │ │ ├── ResultOfRunExecutor.php │ │ ├── ResultOfRunGet.php │ │ ├── ResultOfRunTvm.php │ │ └── TransactionFees.php │ └── Utils │ │ ├── AddressStringFormat.php │ │ ├── ResultOfCalcStorageFee.php │ │ ├── ResultOfCompressZstd.php │ │ ├── ResultOfConvertAddress.php │ │ ├── ResultOfDecompressZstd.php │ │ └── ResultOfGetAddressType.php ├── Exception │ ├── ConfigException.php │ ├── ContextException.php │ ├── DataException.php │ ├── EncoderException.php │ ├── FFIException.php │ ├── LogicException.php │ ├── SDKException.php │ └── TonException.php ├── FFI │ └── FFIAdapter.php ├── Handler │ ├── Response.php │ └── ResponseHandler.php ├── Module.php ├── Net.php ├── Processing.php ├── TonClient.php ├── Tvm.php └── Utils.php └── tests ├── Integration ├── AbiTest.php ├── AbstractModuleTest.php ├── BocTest.php ├── CryptoTest.php ├── Data │ ├── DataProvider.php │ ├── EventSaver.php │ ├── Events.abi.json │ ├── Events.tvc │ ├── Giver.abi.json │ ├── Hello.abi.json │ ├── Hello.tvc │ ├── Subscription.abi.json │ ├── Subscription.tvc │ ├── aes.iv.bin │ ├── aes.plaintext.bin │ ├── aes.plaintext.for.padding.bin │ ├── aes128.key.bin │ ├── aes256.key.bin │ ├── cbc-aes128.ciphertext.bin │ └── cbc-aes256.ciphertext.padded.bin ├── NetTest.php ├── ProcessingTest.php ├── TonClientTest.php ├── TvmTest.php ├── UtilsTest.php └── artifacts │ └── .gitkeep └── Unit ├── AbiTest.php ├── AbstractModuleTest.php ├── BocTest.php ├── CryptoTest.php ├── Entity └── ResultOfConvertAddressTest.php ├── NetTest.php ├── ProcessingTest.php ├── TonClientTest.php ├── TvmTest.php └── UtilsTest.php /.github/extraton_elephant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/.github/extraton_elephant.png -------------------------------------------------------------------------------- /.github/workflows/client-package-macos.yml: -------------------------------------------------------------------------------- 1 | name: php7.4, macOS latest 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: macos-latest 12 | strategy: 13 | matrix: 14 | php-versions: [ '7.4' ] 15 | name: PHP ${{ matrix.php-versions }} Test on macOS latest 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: ${{ matrix.php-versions }} 22 | extensions: ffi, json, zlib 23 | tools: composer 24 | - name: Install Dependencies 25 | run: composer install --verbose 26 | - name: Unit tests 27 | run: ./vendor/bin/phpunit --testdox tests/Unit/ 28 | - name: Integration tests 29 | run: ./vendor/bin/phpunit --testdox tests/Integration/ 30 | -------------------------------------------------------------------------------- /.github/workflows/client-package-ubuntu.yml: -------------------------------------------------------------------------------- 1 | name: php7.4, Ubuntu 20.04 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-20.04 12 | strategy: 13 | matrix: 14 | php-versions: [ '7.4' ] 15 | name: PHP ${{ matrix.php-versions }} Test on Ubuntu 20.04 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Setup PHP 19 | uses: shivammathur/setup-php@v2 20 | with: 21 | php-version: ${{ matrix.php-versions }} 22 | extensions: ffi, json, zlib 23 | tools: composer 24 | - name: Install Dependencies 25 | run: composer install --verbose 26 | - name: Unit tests 27 | run: ./vendor/bin/phpunit --testdox tests/Unit/ 28 | - name: Integration tests 29 | run: ./vendor/bin/phpunit --testdox tests/Integration/ 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | composer.lock 4 | bin/tonclient.* 5 | .php_cs.cache 6 | .phpunit.result.cache 7 | tests/Integration/artifacts/*.txt 8 | -------------------------------------------------------------------------------- /.php_cs.dist: -------------------------------------------------------------------------------- 1 | setRiskyAllowed(true) 5 | ->setRules([ 6 | '@PSR2' => true, 7 | 'array_syntax' => ['syntax' => 'short'], 8 | 'declare_strict_types' => true, 9 | 'global_namespace_import' => true, 10 | ]) 11 | ->setFinder( 12 | PhpCsFixer\Finder::create() 13 | ->in(__DIR__.'/src') 14 | ->in(__DIR__.'/tests') 15 | ->name('*.php') 16 | ) 17 | ; 18 | 19 | return $config; 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | CHANGELOG 2 | ========= 3 | 4 | 1.23.0 5 | ----- 6 | * Updated TON SDK library to version 1.22.0 7 | * Fix integration tests 8 | 9 | 1.22.0 10 | ----- 11 | * Updated TON SDK library to version 1.22.0 12 | * Added new method `Crypto::createEncryptionBox` 13 | * Added new method `Crypto::registerEncryptionBox` 14 | * Added new method `Crypto::removeEncryptionBox` 15 | * Added new method `Crypto::encryptionBoxEncrypt` 16 | * Added new method `Crypto::encryptionBoxDecrypt` 17 | * Added new method `Crypto::encryptionBoxGetInfo` 18 | * Added new integration and unit tests 19 | * Fix integration tests 20 | 21 | 1.21.0 22 | ----- 23 | * Updated TON SDK library to version 1.21.2 24 | * Fix integration tests 25 | 26 | 1.20.0 27 | ----- 28 | * Updated TON SDK library to version 1.20.0 29 | * Fix integration tests 30 | 31 | 1.19.0 32 | ----- 33 | 34 | * Updated TON SDK library to version 1.19.0 35 | * Added new method `Utils::getAddressType` 36 | * Added new method `Abi::decodeAccountData` 37 | * Added new integration and unit tests 38 | * Fix integration tests 39 | 40 | 1.18.0 41 | ----- 42 | 43 | * Added new method `Net::createBlockIterator` 44 | * Added new method `Net::resumeBlockIterator` 45 | * Added new method `Net::createTransactionIterator` 46 | * Added new method `Net::resumeTransactionIterator` 47 | * Added new method `Net::iteratorNext` 48 | * Added new method `Net::removeIterator` 49 | 50 | 1.17.0 51 | ----- 52 | 53 | * Updated TON SDK library to version 1.18.0 54 | * Fix integration tests 55 | 56 | 1.16.0 57 | ----- 58 | 59 | * Updated TON SDK library to version 1.17.0 60 | * Fix integration tests 61 | 62 | 1.15.0 63 | ----- 64 | 65 | * Added new method `Net::queryTransactionTree` 66 | * Added new integration and unit tests 67 | 68 | 1.14.0 69 | ----- 70 | 71 | * Updated TON SDK library to version 1.16.0 72 | 73 | 1.13.0 74 | ----- 75 | 76 | * Updated TON SDK library to version 1.15.0 77 | * Disabled broken test 78 | 79 | 1.12.1 80 | ----- 81 | 82 | * Updated TON SDK library to version 1.14.1 83 | * Fix integration tests 84 | 85 | 1.12.0 86 | ----- 87 | 88 | * Updated TON SDK library to version 1.14.0 89 | * Added new method `Net::queryCounterparties` 90 | * Added new integration and unit tests 91 | 92 | 1.11.0 93 | ----- 94 | 95 | * Updated TON SDK library to version 1.12.0 96 | * Added new method `Utils::compressZstd` 97 | * Added new method `Utils::decompressZstd` 98 | * Added new integration and unit tests 99 | 100 | 1.10.0 101 | ----- 102 | 103 | * Added new interface `AppInterface` 104 | * Added new method `Debot::start` 105 | * Added new method `Debot::fetch` 106 | * Added new method `Debot::execute` 107 | * Added new method `Debot::send` 108 | * Added new method `Debot::remove` 109 | * Added new method `TonClient::resolveAppRequest` 110 | * Added new method `Crypto::registerSigningBox` 111 | * Added new integration and unit tests 112 | 113 | 1.9.0 114 | ----- 115 | 116 | * Added new method `Crypto::naclSignDetachedVerify` 117 | * Added new method `Crypto::getSigningBox` 118 | * Added new method `Crypto::signingBoxGetPublicKey` 119 | * Added new method `Crypto::signingBoxSign` 120 | * Added new method `Crypto::removeSigningBox` 121 | * Added new integration and unit tests 122 | 123 | 1.8.0 124 | ----- 125 | 126 | * Added new parameter `tuple_list_as_array` 127 | * Fix unit tests 128 | 129 | 1.7.0 130 | ----- 131 | 132 | * Added new method `Net::aggregateCollection` 133 | * Added new method `Net::batchQuery` 134 | * Added new integration and unit tests 135 | 136 | 1.6.0 137 | ----- 138 | 139 | * Updated TON SDK library to version 1.11.1 140 | * Added new method `Utils::calcStorageFee` 141 | * Added new integration and unit tests 142 | 143 | 1.5.1 144 | ----- 145 | 146 | * Removed SmartSleeper 147 | * Added a fixed waiting period for async calls 148 | * Fix integration tests 149 | 150 | 1.5.0 151 | ----- 152 | 153 | * Added new method `Abi::encodeInternalMessage` 154 | * Added new integration and unit tests 155 | 156 | 1.4.0 157 | ----- 158 | 159 | * Added new method `Boc::cacheGet` 160 | * Added new method `Boc::cacheSet` 161 | * Added new method `Boc::cacheUnpin` 162 | * Added new method `Boc::encodeBoc` 163 | * Added new flag `boc_cache` to methods `Tvm::runTvm` and `Tvm::runExecutor` 164 | * Added new integration and unit tests 165 | * Update docker image 166 | 167 | 1.3.1 168 | ----- 169 | 170 | * Fix dev tools 171 | * Fix code-style 172 | * Update docker image to php8.0 173 | 174 | 1.3.0 175 | ----- 176 | 177 | * Updated TON SDK library to version 1.10.0 178 | * Added new flag `return_updated_account` to methods `Tvm::runTvm` and `Tvm::runExecutor` 179 | * Fixed integration and unit tests 180 | 181 | 1.2.0 182 | ----- 183 | 184 | * Updated TON SDK library to version 1.5.2 185 | * Added PHP 8 support 186 | * Fixed integration tests 187 | * Added new method `Net::query` 188 | * Added new method `Net::findLastShardBlock` 189 | * Added new method `Net::setEndpoints` 190 | * Added new method `Net::fetchEndpoints` 191 | * Added new method `Net::suspend` 192 | * Added new method `Net::resume` 193 | * Added new method `Boc::getCodeFromTvc` 194 | 195 | 1.1.0 196 | ----- 197 | 198 | * Added new method `Crypto::chaCha20` 199 | * Added new method `Boc::parseShardstate` 200 | * Added new method `Boc::getBocHash` 201 | 202 | 1.0.2 203 | ----- 204 | 205 | * Updated TON SDK library to version 1.1.2 206 | * Added default value (`null`) for some methods 207 | * Added new example: send rubies with comment to surf 208 | * Refactoring for the method `AbiType::fromJson()` 209 | 210 | 1.0.1 211 | ----- 212 | 213 | * Fixed parameter name for the method `Net::queryCollection()` 214 | 215 | 1.0.0 216 | ----- 217 | 218 | * First public release. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | If you have improvements to PHP Ton Client, send us your pull requests! 4 | PRs to our libraries are always welcome and can be a quick way to get your fix 5 | or improvement slated for the next release. 6 | 7 | In general, we follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr): 8 | 9 | 1. Fork the repository to your own Github account 10 | 2. Clone the project to your machine 11 | 3. Create a branch locally with a succinct but descriptive name 12 | 4. Make changes 13 | 5. Write tests 14 | 6. Run tests, phpstan, check codestyle. 15 | 7. Commit changes to the branch 16 | 8. Push changes to your fork 17 | 9. Open a PR in our repository and follow the PR template so that we can efficiently review the changes. 18 | 19 | ExtraTON team members will be assigned to review your pull requests. 20 | 21 | Also you can report a problem via [issue section](https://github.com/extraton/php-ton-client/issues) 22 | or in [telegram chat](https://t.me/extraton). 23 | 24 | ### Coding style 25 | Changes to PHP Ton Client code should conform to 26 | [PSR2 Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) 27 | 28 | Use php-cs-fixer to check your changes: 29 | 30 | make codestyle 31 | 32 | ### Running tests 33 | 34 | make test 35 | 36 | ### Running phpstan checks 37 | 38 | make analyze 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.0-cli 2 | 3 | WORKDIR /app 4 | 5 | COPY --from=composer:2.0.11 /usr/bin/composer /usr/local/bin/composer 6 | 7 | RUN apt-get update && apt-get install -y \ 8 | zip git libffi-dev \ 9 | && docker-php-ext-install ffi -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | help: 2 | @echo "Please use \`make ' where is one of" 3 | @echo " build (optional) to build docker image locally." 4 | @echo " push (optional) push docker image to docker hub." 5 | @echo " install to install composer dependencies." 6 | @echo " update to update composer dependencies." 7 | @echo " test to perform all tests." 8 | @echo " test-unit to perform unit tests." 9 | @echo " test-integration to perform integration tests." 10 | @echo " analyze to run phpstan on the codebase." 11 | @echo " codestyle to run php-cs-fixer on the codebase." 12 | @echo " codestyle-fix to run php-cs-fixer on the codebase with code formatting." 13 | 14 | build: 15 | docker build --tag extraton/php-ton-client:latest . 2>&1 16 | 17 | push: 18 | docker image push extraton/php-ton-client:latest 2>&1 19 | 20 | install: 21 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest composer install 2>&1 22 | 23 | update: 24 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest composer update 2>&1 25 | 26 | test: 27 | if [ ! -f "./vendor/bin/phpunit" ]; then $(MAKE) install; fi; 28 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest ./vendor/bin/phpunit --testdox tests/$(FOLDER) 2>&1 29 | 30 | test-unit: 31 | $(MAKE) test FOLDER="Unit" 32 | 33 | test-integration: 34 | $(MAKE) test FOLDER="Integration" 35 | 36 | analyze: 37 | if [ ! -f "./vendor/bin/phpstan" ]; then $(MAKE) install; fi; 38 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest ./vendor/bin/phpstan analyze src 2>&1 39 | 40 | codestyle: 41 | if [ ! -f "./vendor/bin/php-cs-fixer" ]; then $(MAKE) install; fi; 42 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest ./vendor/bin/php-cs-fixer fix --config=.php_cs.dist --diff-format=udiff --dry-run --allow-risky=yes 2>&1 43 | 44 | codestyle-fix: 45 | if [ ! -f "./vendor/bin/php-cs-fixer" ]; then $(MAKE) install; fi; 46 | docker run --rm -it -v ${PWD}:/app extraton/php-ton-client:latest ./vendor/bin/php-cs-fixer fix 2>&1 -------------------------------------------------------------------------------- /bin/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/bin/.gitkeep -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "extraton/php-ton-client", 3 | "description": "Extraton, PHP TON client", 4 | "type": "library", 5 | "license": "Apache-2.0", 6 | "homepage": "https://extraton.io/", 7 | "keywords": [ 8 | "extraton", 9 | "freeton", 10 | "ton", 11 | "ton crystal", 12 | "dapp" 13 | ], 14 | "authors": [ 15 | { 16 | "name": "Maxim Karanaev", 17 | "email": "imaxvx@gmail.com", 18 | "homepage": "https://github.com/maxvx" 19 | }, 20 | { 21 | "name": "qwertys318", 22 | "homepage": "https://github.com/qwertys318" 23 | } 24 | ], 25 | "require": { 26 | "php": "^7.4|^8.0", 27 | "ext-ffi": "*", 28 | "ext-json": "*", 29 | "ext-zlib": "*", 30 | "guzzlehttp/promises": "^1.0" 31 | }, 32 | "require-dev": { 33 | "phpunit/phpunit": "^9.4", 34 | "friendsofphp/php-cs-fixer": "^2.18", 35 | "phpstan/phpstan": "^0.12" 36 | }, 37 | "autoload": { 38 | "psr-4": { 39 | "Extraton\\TonClient\\": "src/", 40 | "Extraton\\Tests\\Unit\\TonClient\\": "tests/Unit/", 41 | "Extraton\\Tests\\Integration\\TonClient\\": "tests/Integration/" 42 | } 43 | }, 44 | "scripts": { 45 | "download-ton-sdk-library": "Extraton\\TonClient\\Composer\\Scripts::downloadLibrary", 46 | "post-update-cmd": [ 47 | "@download-ton-sdk-library" 48 | ], 49 | "post-install-cmd": [ 50 | "@download-ton-sdk-library" 51 | ] 52 | } 53 | } -------------------------------------------------------------------------------- /examples/catching_exceptions.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'server_address' => 'unknown', 18 | ] 19 | ] 20 | ); 21 | 22 | // Get New module 23 | $net = $tonClient->getNet(); 24 | 25 | // Prepare query 26 | $query = (new ParamsOfSubscribeCollection('transactions')) 27 | ->addResultField('id') 28 | ->addOrderBy('id', OrderBy::DESC); 29 | 30 | // Method call using the network 31 | $net->subscribeCollection($query); 32 | } catch (TonException $exception) { 33 | echo 'Exception code: ' . $exception->getCode() . PHP_EOL; 34 | echo 'Exception message: ' . $exception->getMessage() . PHP_EOL; 35 | } 36 | -------------------------------------------------------------------------------- /examples/client_api.php: -------------------------------------------------------------------------------- 1 | getApiReference(); 12 | 13 | echo 'API: ' . print_r($result->getApi(), true) . PHP_EOL; 14 | -------------------------------------------------------------------------------- /examples/client_version.php: -------------------------------------------------------------------------------- 1 | version(); 12 | 13 | echo 'TON SDK version: ' . $result->getVersion() . PHP_EOL; 14 | -------------------------------------------------------------------------------- /examples/crypto_generate_random_sign_keys.php: -------------------------------------------------------------------------------- 1 | getCrypto(); 14 | 15 | // Generate random ed25519 key pair. 16 | $result = $crypto->generateRandomSignKeys(); 17 | $keyPair = $result->getKeyPair(); 18 | 19 | echo 'Public key: ' . $keyPair->getPublic() . PHP_EOL; 20 | echo 'Private key: ' . $keyPair->getSecret() . PHP_EOL; 21 | -------------------------------------------------------------------------------- /examples/crypto_nacl_sign.php: -------------------------------------------------------------------------------- 1 | getCrypto(); 14 | 15 | // Unsigned test message 16 | $unsigned = base64_encode('Test Message'); 17 | // Signing secret key 18 | $secretKey = '56b6a77093d6fdf14e593f36275d872d75de5b341942376b2a08759f3cbae78f1869b7ef29d58026217e9cf163cbfbd0de889bdf1bf4daebf5433a312f5b8d6e'; 19 | 20 | // Sign data using the signer's secret key. 21 | $result = $crypto->naclSign($unsigned, $secretKey); 22 | 23 | // Showing result 24 | echo 'Unsigned: ' . $unsigned . PHP_EOL; 25 | echo 'Secret key: ' . $secretKey . PHP_EOL; 26 | echo 'Signed: ' . $result->getSigned() . PHP_EOL; 27 | -------------------------------------------------------------------------------- /examples/get_test_rubies.php: -------------------------------------------------------------------------------- 1 | getProcessing(); 50 | 51 | // Giver address 52 | $giverAddress = '0:653b9a6452c7a982c6dc92b2da9eba832ade1c467699ebb3b43dca6d77b780dd'; 53 | 54 | // Destination address (change the address to yours) 55 | $destinationAddress = '0:c479ba10644a6715f34f3486a9c6c343c2efa44eeffa4e7d9f4515def7864d21'; 56 | 57 | // Create abi from JSON 58 | $abi = AbiType::fromJson($giverAbiJson); 59 | 60 | $callSet = (new CallSet('grant')) 61 | ->withInput( 62 | [ 63 | 'dest' => $destinationAddress 64 | ] 65 | ); 66 | 67 | $signer = Signer::fromNone(); 68 | 69 | // Send rubies 70 | $result = $processing->processMessage( 71 | $abi, 72 | $signer, 73 | null, 74 | $callSet, 75 | $giverAddress 76 | ); 77 | 78 | var_dump($result->getResponseData()); 79 | 80 | echo 'Total account fees: ' . $result->getFees()->getTotalAccountFees() . PHP_EOL; 81 | 82 | echo 'Finished.' . PHP_EOL; -------------------------------------------------------------------------------- /examples/net_subscribe_collection.php: -------------------------------------------------------------------------------- 1 | getNet(); 16 | 17 | // Build query 18 | $query = (new ParamsOfSubscribeCollection('transactions')) 19 | ->addResultField('id', 'block_id', 'balance_delta') 20 | ->addFilter('balance_delta', Filters::GT, '0x5f5e100'); 21 | 22 | // Get result with handle and start watching 23 | $result = $net->subscribeCollection($query); 24 | 25 | echo "Handle: {$result->getHandle()}." . PHP_EOL; 26 | 27 | $counter = 0; 28 | 29 | // Iterate generator 30 | foreach ($result->getIterator() as $event) { 31 | $counter++; 32 | 33 | echo "Event counter: {$counter}, event data:" . PHP_EOL; 34 | var_dump($event->getResult()); 35 | 36 | if ($counter > 25) { 37 | echo 'Manual stop watching.' . PHP_EOL; 38 | $result->stop(); // or call: $net->unsubscribe($result->getHandle()); 39 | } 40 | } 41 | 42 | echo 'Finished.' . PHP_EOL; 43 | -------------------------------------------------------------------------------- /examples/processing_process_message.php: -------------------------------------------------------------------------------- 1 | getProcessing(); 21 | 22 | // Get Abi module 23 | $abi = $tonClient->getAbi(); 24 | 25 | // Get Crypto module 26 | $crypto = $tonClient->getCrypto(); 27 | 28 | $abiParams = AbiType::fromArray($dataProvider->getEventsAbiArray()); 29 | $deploySet = new DeploySet($dataProvider->getEventsTvc()); 30 | $keyPair = $crypto->generateRandomSignKeys()->getKeyPair(); 31 | $signer = Signer::fromKeys($keyPair); 32 | $callSet = (new CallSet('constructor'))->withFunctionHeaderParams($keyPair->getPublic()); 33 | 34 | $resultOfEncodeMessage = $abi->encodeMessage( 35 | $abiParams, 36 | $signer, 37 | $deploySet, 38 | $callSet 39 | ); 40 | 41 | $address = $resultOfEncodeMessage->getAddress(); 42 | 43 | $dataProvider->sendTons($address); 44 | 45 | // Creates message, sends it to the network and monitors its processing 46 | $resultOfProcessMessage = $processing->processMessage( 47 | $abiParams, 48 | $signer, 49 | $deploySet, 50 | $callSet, 51 | null, 52 | null, 53 | true 54 | ); 55 | 56 | // Iterate generator 57 | foreach ($resultOfProcessMessage->getIterator() as $event) { 58 | echo 'New event ' . $event->getType() . PHP_EOL; 59 | 60 | var_dump($event->getResponseData()); 61 | } 62 | 63 | echo 'Fees: ' . PHP_EOL; 64 | var_dump($resultOfProcessMessage->getFees()); 65 | 66 | echo 'Finished.' . PHP_EOL; 67 | -------------------------------------------------------------------------------- /examples/utils_convert_address.php: -------------------------------------------------------------------------------- 1 | getUtils(); 13 | 14 | $result = $tonClient->version(); 15 | 16 | echo 'TON SDK version: ' . $result->getVersion() . PHP_EOL; 17 | -------------------------------------------------------------------------------- /phpstan-baseline.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | ignoreErrors: 3 | 4 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | 4 | parameters: 5 | level: max 6 | paths: 7 | - src 8 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | tests/Unit 12 | tests/Integration 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/AbstractModule.php: -------------------------------------------------------------------------------- 1 | tonClient = $tonClient; 20 | } 21 | 22 | /** 23 | * @return TonClient 24 | */ 25 | public function getTonClient(): TonClient 26 | { 27 | return $this->tonClient; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/App/AppInterface.php: -------------------------------------------------------------------------------- 1 | $requestData 17 | * @param int|null $appRequestId 18 | */ 19 | public function __invoke(TonClient $tonClient, array $requestData, ?int $appRequestId = null): void; 20 | } 21 | -------------------------------------------------------------------------------- /src/Binding/Encoder.php: -------------------------------------------------------------------------------- 1 | ffiAdapter = $ffiAdapter; 34 | } 35 | 36 | /** 37 | * Create CData of tc_string_data_t via FFI 38 | * 39 | * @param array $value 40 | * @return CData 41 | * @throws EncoderException 42 | */ 43 | public function encodeArray(array $value): CData 44 | { 45 | try { 46 | $json = (string)json_encode( 47 | empty($value) ? new stdClass() : $value, 48 | JSON_THROW_ON_ERROR 49 | ); 50 | } catch (JsonException $exception) { 51 | throw new EncoderException($exception); 52 | } 53 | 54 | return $this->encodeString($json); 55 | } 56 | 57 | /** 58 | * Create CData of tc_string_data_t via FFI 59 | * 60 | * @param string $value 61 | * @return CData 62 | * @throws FFIException 63 | */ 64 | public function encodeString(string $value): CData 65 | { 66 | try { 67 | $cData = $this->ffiAdapter->callNew('tc_string_data_t'); 68 | 69 | $size = strlen($value); 70 | // @phpstan-ignore-next-line 71 | $cData->content = $this->ffiAdapter->callNew("char[{$size}]", false); 72 | // @phpstan-ignore-next-line 73 | $cData->len = $size; 74 | 75 | $content = &$cData->content; 76 | $this->ffiAdapter->callMemCpy($content, $value, $size); 77 | 78 | return $cData; 79 | } catch (Exception $exception) { 80 | throw new FFIException($exception); 81 | } 82 | } 83 | 84 | /** 85 | * @param CData $cData 86 | * @return array 87 | * @throws EncoderException 88 | */ 89 | public function decodeToArray(CData $cData): array 90 | { 91 | try { 92 | $content = &$cData->content; 93 | // @phpstan-ignore-next-line 94 | $size = $cData->len; 95 | 96 | $json = $this->ffiAdapter->callString($content, $size); 97 | } catch (Exception $exception) { 98 | throw new FFIException($exception); 99 | } 100 | 101 | if (empty($json)) { 102 | return []; 103 | } 104 | 105 | try { 106 | return (array)json_decode($json, true, 512, JSON_THROW_ON_ERROR); 107 | } catch (JsonException $exception) { 108 | throw new EncoderException($exception); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Binding/Type/ResponseType.php: -------------------------------------------------------------------------------- 1 | 'tonclient_%s_%s_dll.gz', 40 | 'darwin' => 'tonclient_%s_%s.gz', 41 | 'linux' => 'tonclient_%s_%s.gz', 42 | ]; 43 | 44 | private const DESTINATION_FILE_NAME = [ 45 | 'win32' => 'tonclient.dll', 46 | 'darwin' => 'tonclient.dylib', 47 | 'linux' => 'tonclient.so', 48 | ]; 49 | 50 | private const DOWNLOAD_URL = 'http://sdkbinaries.tonlabs.io/%s'; 51 | 52 | /** 53 | * Download TON SDK library and save to bin directory 54 | */ 55 | public static function downloadLibrary(): void 56 | { 57 | $os = strtolower(PHP_OS); 58 | if (!isset(self::SOURCE_FILE_NAME[$os], self::DESTINATION_FILE_NAME[$os])) { 59 | throw new RuntimeException(sprintf('Unknown OS %s.', $os)); 60 | } 61 | 62 | $srcFileName = sprintf(self::SOURCE_FILE_NAME[$os], str_replace('.', '_', self::DEFAULT_SDK_VERSION), $os); 63 | $downloadUrl = sprintf(self::DOWNLOAD_URL, $srcFileName); 64 | $tmpPath = tempnam(sys_get_temp_dir(), 'ton_client_'); 65 | if ($tmpPath === false) { 66 | throw new RuntimeException(sprintf('Failed to create temporary file %s.', $tmpPath)); 67 | } 68 | 69 | $downloadScript = <<tonClient->request( 29 | 'debot.start', 30 | [ 31 | 'address' => $address, 32 | ], 33 | $app 34 | )->wait() 35 | ); 36 | } 37 | 38 | /** 39 | * Fetches debot from blockchain. 40 | * Downloads debot smart contract (code and data) from blockchain and creates an instance of Debot Engine for it. 41 | * 42 | * @param string $address Debot smart contract address 43 | * @param AppInterface $app Debot Browser callbacks. Called by debot engine to communicate with debot browser. 44 | * @return RegisteredDebot 45 | * @throws TonException 46 | */ 47 | public function fetch(string $address, AppInterface $app): RegisteredDebot 48 | { 49 | return new RegisteredDebot( 50 | $this->tonClient->request( 51 | 'debot.fetch', 52 | [ 53 | 'address' => $address, 54 | ], 55 | $app 56 | )->wait() 57 | ); 58 | } 59 | 60 | /** 61 | * Fetches debot from blockchain. 62 | * Downloads debot smart contract (code and data) from blockchain and creates an instance of Debot Engine for it. 63 | * 64 | * @param int $debotHandle Debot handle which references an instance of debot engine. 65 | * @param DebotAction $debotAction Debot Action that must be executed. 66 | * @return void 67 | * @throws TonException 68 | */ 69 | public function execute(int $debotHandle, DebotAction $debotAction): void 70 | { 71 | $this->tonClient->request( 72 | 'debot.execute', 73 | [ 74 | 'debot_handle' => $debotHandle, 75 | 'action' => $debotAction, 76 | ] 77 | )->wait(); 78 | } 79 | 80 | /** 81 | * Sends message to Debot. 82 | * Used by Debot Browser to send response on Dinterface call or from other Debots. 83 | * 84 | * @param int $debotHandle Debot handle which references an instance of debot engine. 85 | * @param string $message BOC of internal message to debot encoded in base64 format. 86 | * @return void 87 | * @throws TonException 88 | */ 89 | public function send(int $debotHandle, string $message): void 90 | { 91 | $this->tonClient->request( 92 | 'debot.send', 93 | [ 94 | 'debot_handle' => $debotHandle, 95 | 'message' => $message, 96 | ] 97 | )->wait(); 98 | } 99 | 100 | /** 101 | * Destroys debot handle. 102 | * Removes handle from Client Context and drops debot engine referenced by that handle. 103 | * 104 | * @param int $debotHandle Debot handle which references an instance of debot engine. 105 | * @param string $debotAbi Debot abi as json string. 106 | * @return void 107 | * @throws TonException 108 | */ 109 | public function remove(int $debotHandle, string $debotAbi): void 110 | { 111 | $this->tonClient->request( 112 | 'debot.remove', 113 | [ 114 | 'debot_handle' => $debotHandle, 115 | 'debot_abi' => $debotAbi, 116 | ] 117 | )->wait(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /src/Entity/Abi/AbiType.php: -------------------------------------------------------------------------------- 1 | */ 29 | private array $arrayValue; 30 | 31 | private string $json; 32 | 33 | /** 34 | * @param string $type 35 | */ 36 | public function __construct(string $type) 37 | { 38 | $this->type = $type; 39 | } 40 | 41 | /** 42 | * Create Abi object from json 43 | * 44 | * @param string $json Abi josn 45 | * @return self 46 | * @throws EncoderException 47 | */ 48 | public static function fromJson(string $json): self 49 | { 50 | $instance = new self(self::TYPE_JSON); 51 | $instance->setJson($json); 52 | 53 | return $instance; 54 | } 55 | 56 | /** 57 | * Create Abi object from array 58 | * 59 | * @param array $arrayValue 60 | * @return self 61 | */ 62 | public static function fromArray(array $arrayValue): self 63 | { 64 | $instance = new self(self::TYPE_SERIALIZED); 65 | $instance->setArrayValue($arrayValue); 66 | 67 | return $instance; 68 | } 69 | 70 | /** 71 | * Create Abi object from handle 72 | * 73 | * @param int $handle Handle 74 | * @return self 75 | */ 76 | public static function fromHandle(int $handle): self 77 | { 78 | $instance = new self(self::TYPE_HANDLE); 79 | $instance->setHandle($handle); 80 | 81 | return $instance; 82 | } 83 | 84 | /** 85 | * Set array value 86 | * 87 | * @param array $arrayValue 88 | * @return self 89 | */ 90 | private function setArrayValue(array $arrayValue): self 91 | { 92 | $this->arrayValue = $arrayValue; 93 | 94 | return $this; 95 | } 96 | 97 | /** 98 | * Set json value 99 | * 100 | * @param string $json 101 | * @return self 102 | */ 103 | private function setJson(string $json): self 104 | { 105 | $this->json = $json; 106 | 107 | return $this; 108 | } 109 | 110 | /** 111 | * Set handle 112 | * 113 | * @param int $handle Handle 114 | * @return self 115 | */ 116 | private function setHandle(int $handle): self 117 | { 118 | $this->handle = $handle; 119 | 120 | return $this; 121 | } 122 | 123 | /** 124 | * @inheritDoc 125 | */ 126 | public function jsonSerialize(): array 127 | { 128 | $result['type'] = $this->type; 129 | 130 | if ($this->type === self::TYPE_HANDLE) { 131 | $result['value'] = $this->handle; 132 | } elseif ($this->type === self::TYPE_SERIALIZED) { 133 | $result['value'] = $this->arrayValue; 134 | } elseif ($this->type === self::TYPE_JSON) { 135 | $result['value'] = $this->json; 136 | } else { 137 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 138 | } 139 | 140 | return $result; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/Entity/Abi/CallSet.php: -------------------------------------------------------------------------------- 1 | functionName = $functionName; 27 | } 28 | 29 | /** 30 | * Set function input parameters 31 | * 32 | * @param mixed $input Function input parameters according to ABI 33 | * @return self 34 | */ 35 | public function withInput($input = null): self 36 | { 37 | $this->setInput($input); 38 | 39 | return $this; 40 | } 41 | 42 | /** 43 | * Set function input parameters 44 | * 45 | * @param mixed $input Function input parameters according to ABI 46 | * @return self 47 | */ 48 | private function setInput($input): self 49 | { 50 | $this->input = $input; 51 | 52 | return $this; 53 | } 54 | 55 | /** 56 | * Set FunctionHeader by params 57 | * 58 | * @param string|null $pubKey Public key used to sign message. Encoded with hex 59 | * @param int|null $time Message creation time in milliseconds 60 | * @param int|null $expire Message expiration time in seconds 61 | * @return self 62 | */ 63 | public function withFunctionHeaderParams(?string $pubKey = null, ?int $time = null, ?int $expire = null): self 64 | { 65 | $this->setFunctionHeader(new FunctionHeader($pubKey, $time, $expire)); 66 | 67 | return $this; 68 | } 69 | 70 | /** 71 | * Set FunctionHeader 72 | * 73 | * @param FunctionHeader $functionHeader Function header. If an application omits some header parameters required 74 | * by the contract's ABI, the library will set the default values forthem. 75 | * @return self 76 | */ 77 | private function setFunctionHeader(FunctionHeader $functionHeader): self 78 | { 79 | $this->functionHeader = $functionHeader; 80 | 81 | return $this; 82 | } 83 | 84 | /** 85 | * @inheritDoc 86 | */ 87 | public function jsonSerialize(): array 88 | { 89 | return [ 90 | 'function_name' => $this->functionName, 91 | 'header' => $this->functionHeader, 92 | 'input' => $this->input, 93 | ]; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Entity/Abi/DecodedMessageBody.php: -------------------------------------------------------------------------------- 1 | requireString('body_type'); 22 | } 23 | 24 | /** 25 | * Get function or event name 26 | * 27 | * @return string 28 | */ 29 | public function getName(): string 30 | { 31 | return $this->requireString('name'); 32 | } 33 | 34 | /** 35 | * Get parameters or result value 36 | * 37 | * @return mixed 38 | */ 39 | public function getValue() 40 | { 41 | return $this->getOriginData('value'); 42 | } 43 | 44 | /** 45 | * Get function header 46 | * 47 | * @return FunctionHeader|null 48 | */ 49 | public function getFunctionHeader(): ?FunctionHeader 50 | { 51 | $result = $this->getArray('header'); 52 | if ($result === null) { 53 | return null; 54 | } 55 | 56 | return new FunctionHeader(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Entity/Abi/DeploySet.php: -------------------------------------------------------------------------------- 1 | tvc = $tvc; 29 | $this->workchainId = $workchainId; 30 | $this->initialData = $initialData; 31 | } 32 | 33 | /** 34 | * @inheritDoc 35 | */ 36 | public function jsonSerialize(): array 37 | { 38 | return [ 39 | 'tvc' => $this->tvc, 40 | 'workchain_id' => $this->workchainId, 41 | 'initial_data' => $this->initialData, 42 | ]; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Entity/Abi/FunctionHeader.php: -------------------------------------------------------------------------------- 1 | expire = $expire; 28 | $this->time = $time; 29 | $this->pubKey = $pubKey; 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public function jsonSerialize(): array 36 | { 37 | return [ 38 | 'pubkey' => $this->pubKey, 39 | 'time' => $this->time, 40 | 'expire' => $this->expire, 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfAttachSignature.php: -------------------------------------------------------------------------------- 1 | requireString('message'); 22 | } 23 | 24 | /** 25 | * Get message ID 26 | * 27 | * @return string 28 | */ 29 | public function getMessageId(): string 30 | { 31 | return $this->requireString('message_id'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfAttachSignatureToMessageBody.php: -------------------------------------------------------------------------------- 1 | requireString('body'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfDecodeData.php: -------------------------------------------------------------------------------- 1 | requireData('data'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfEncodeAccount.php: -------------------------------------------------------------------------------- 1 | requireString('account'); 22 | } 23 | 24 | /** 25 | * Get account ID encoded in hex 26 | * 27 | * @return string 28 | */ 29 | public function getId(): string 30 | { 31 | return $this->requireString('id'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfEncodeInternalMessage.php: -------------------------------------------------------------------------------- 1 | requireString('message'); 22 | } 23 | 24 | /** 25 | * Get destination address 26 | * 27 | * @return string 28 | */ 29 | public function getAddress(): string 30 | { 31 | return $this->requireString('address'); 32 | } 33 | 34 | /** 35 | * Get message ID 36 | * 37 | * @return string 38 | */ 39 | public function getMessageId(): string 40 | { 41 | return $this->requireString('message_id'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfEncodeMessage.php: -------------------------------------------------------------------------------- 1 | requireString('message'); 22 | } 23 | 24 | /** 25 | * Get optional data to be signed encoded in base64 26 | * 27 | * @return string|null 28 | */ 29 | public function getDataToSign(): ?string 30 | { 31 | return $this->getString('data_to_sign'); 32 | } 33 | 34 | /** 35 | * Get destination address 36 | * 37 | * @return string 38 | */ 39 | public function getAddress(): string 40 | { 41 | return $this->requireString('address'); 42 | } 43 | 44 | /** 45 | * Get message ID 46 | * 47 | * @return string 48 | */ 49 | public function getMessageId(): string 50 | { 51 | return $this->requireString('message_id'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Entity/Abi/ResultOfEncodeMessageBody.php: -------------------------------------------------------------------------------- 1 | requireString('body'); 22 | } 23 | 24 | /** 25 | * Get data to sign, optional, encoded with base64 26 | * 27 | * @return string|null 28 | */ 29 | public function getDataToSign(): ?string 30 | { 31 | return $this->getString('data_to_sign'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Abi/Signer.php: -------------------------------------------------------------------------------- 1 | type = $type; 40 | } 41 | 42 | /** 43 | * Create with type none 44 | * No keys are provided. Creates an unsigned message 45 | * 46 | * @return self 47 | */ 48 | public static function fromNone(): self 49 | { 50 | return new self(self::TYPE_NONE); 51 | } 52 | 53 | /** 54 | * Create from external public key 55 | * 56 | * @param string $publicKey Public key 57 | * @return self 58 | */ 59 | public static function fromExternal(string $publicKey): self 60 | { 61 | $instance = new self(self::TYPE_EXTERNAL); 62 | $instance->setPublicKey($publicKey); 63 | 64 | return $instance; 65 | } 66 | 67 | /** 68 | * Create Signer from KeyPair 69 | * 70 | * @param KeyPair $keyPair Key pair 71 | * @return self 72 | */ 73 | public static function fromKeys(KeyPair $keyPair): self 74 | { 75 | return self::fromKeyPair($keyPair); 76 | } 77 | 78 | /** 79 | * Create Signer from KeyPair 80 | * 81 | * @param KeyPair $keyPair Key pair 82 | * @return self 83 | */ 84 | public static function fromKeyPair(KeyPair $keyPair): self 85 | { 86 | $instance = new self(self::TYPE_KEYS); 87 | $instance->setKeyPair($keyPair); 88 | 89 | return $instance; 90 | } 91 | 92 | /** 93 | * Set public key 94 | * 95 | * @param string $publicKey Public key 96 | * @return self 97 | */ 98 | public function setPublicKey(string $publicKey): self 99 | { 100 | $this->publicKey = $publicKey; 101 | 102 | return $this; 103 | } 104 | 105 | /** 106 | * Set key pair 107 | * 108 | * @param KeyPair $keyPair Key pair 109 | * @return self 110 | */ 111 | public function setKeyPair(KeyPair $keyPair): self 112 | { 113 | $this->keyPair = $keyPair; 114 | 115 | return $this; 116 | } 117 | 118 | /** 119 | * Create Signer from signing box handle 120 | * 121 | * @param int $signingBoxHandle Signing box handle 122 | * @return self 123 | */ 124 | public static function fromSigningBox(int $signingBoxHandle): self 125 | { 126 | $instance = new self(self::TYPE_SIGNING_BOX); 127 | $instance->setSigningBoxHandle($signingBoxHandle); 128 | 129 | return $instance; 130 | } 131 | 132 | /** 133 | * Set signing box handle 134 | * 135 | * @param int $signingBoxHandle Signing box handle 136 | * @return self 137 | */ 138 | public function setSigningBoxHandle(int $signingBoxHandle): self 139 | { 140 | $this->signingBoxHandle = $signingBoxHandle; 141 | 142 | return $this; 143 | } 144 | 145 | /** 146 | * @inheritDoc 147 | */ 148 | public function jsonSerialize(): array 149 | { 150 | $result['type'] = $this->type; 151 | 152 | if ($this->type === self::TYPE_NONE) { 153 | return $result; 154 | } 155 | 156 | if ($this->type === self::TYPE_EXTERNAL) { 157 | $result['public_key'] = $this->publicKey; 158 | } elseif ($this->type === self::TYPE_KEYS) { 159 | $result['keys'] = $this->keyPair; 160 | } elseif ($this->type === self::TYPE_SIGNING_BOX) { 161 | $result['handle'] = $this->signingBoxHandle; 162 | } else { 163 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 164 | } 165 | 166 | return $result; 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /src/Entity/Abi/StateInitParams.php: -------------------------------------------------------------------------------- 1 | abi = $abi; 26 | $this->value = $value; 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | public function jsonSerialize(): array 33 | { 34 | return [ 35 | 'abi' => $this->abi, 36 | 'value' => $this->value, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entity/Abi/StateInitSource.php: -------------------------------------------------------------------------------- 1 | type = $type; 45 | } 46 | 47 | /** 48 | * Create StateInitSource from MessageSource 49 | * 50 | * @param MessageSource $messageSource Message source 51 | * @return self 52 | */ 53 | public static function fromMessage(MessageSource $messageSource): self 54 | { 55 | $instance = new self(self::TYPE_MESSAGE); 56 | $instance->setMessageSource($messageSource); 57 | 58 | return $instance; 59 | } 60 | 61 | /** 62 | * Create StateInitSource from state init parameters 63 | * 64 | * @param string $code Code BOC. Encoded in base64 65 | * @param string $data Data BOC. Encoded in base64 66 | * @param string|null $library Library BOC. Encoded in base64 67 | * @return self 68 | */ 69 | public static function fromStateInit(string $code, string $data, ?string $library = null): self 70 | { 71 | $instance = new self(self::TYPE_STATE_INIT); 72 | $instance->setCode($code); 73 | $instance->setData($data); 74 | $instance->setLibrary($library); 75 | 76 | return $instance; 77 | } 78 | 79 | /** 80 | * Create StateInitSource from tvc 81 | * 82 | * @param string $tvc Tvc 83 | * @param string|null $publicKey Public key 84 | * @param StateInitParams|null $stateInitParams State init params 85 | * @return self 86 | */ 87 | public static function fromTvc( 88 | string $tvc, 89 | ?string $publicKey = null, 90 | ?StateInitParams $stateInitParams = null 91 | ): self { 92 | $instance = new self(self::TYPE_TVC); 93 | $instance->setTvc($tvc); 94 | $instance->setPublicKey($publicKey); 95 | $instance->setStateInitParams($stateInitParams); 96 | 97 | return $instance; 98 | } 99 | 100 | /** 101 | * Set message source 102 | * 103 | * @param MessageSource $messageSource 104 | * @return self 105 | */ 106 | private function setMessageSource(MessageSource $messageSource): self 107 | { 108 | $this->messageSource = $messageSource; 109 | 110 | return $this; 111 | } 112 | 113 | /** 114 | * Set code 115 | * 116 | * @param string $code Code BOC. Encoded in base64 117 | * @return self 118 | */ 119 | private function setCode(string $code): self 120 | { 121 | $this->code = $code; 122 | 123 | return $this; 124 | } 125 | 126 | /** 127 | * Set data boc 128 | * 129 | * @param string $data Data BOC. Encoded in base64 130 | * @return self 131 | */ 132 | private function setData(string $data): self 133 | { 134 | $this->data = $data; 135 | 136 | return $this; 137 | } 138 | 139 | /** 140 | * Set library boc 141 | * 142 | * @param string|null $library Library BOC. Encoded in base64 143 | * @return self 144 | */ 145 | private function setLibrary(?string $library): self 146 | { 147 | $this->library = $library; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * Set tvc 154 | * 155 | * @param string $tvc Tvc 156 | * @return self 157 | */ 158 | public function setTvc(string $tvc): self 159 | { 160 | $this->tvc = $tvc; 161 | 162 | return $this; 163 | } 164 | 165 | /** 166 | * Set public key 167 | * 168 | * @param string|null $publicKey Public key 169 | * @return self 170 | */ 171 | public function setPublicKey(?string $publicKey): self 172 | { 173 | $this->publicKey = $publicKey; 174 | 175 | return $this; 176 | } 177 | 178 | /** 179 | * Set state init parameters 180 | * 181 | * @param StateInitParams|null $stateInitParams State init parameters 182 | * @return self 183 | */ 184 | public function setStateInitParams(?StateInitParams $stateInitParams): self 185 | { 186 | $this->stateInitParams = $stateInitParams; 187 | 188 | return $this; 189 | } 190 | 191 | /** 192 | * @inheritDoc 193 | */ 194 | public function jsonSerialize(): array 195 | { 196 | $result['type'] = $this->type; 197 | 198 | if ($this->type === self::TYPE_MESSAGE) { 199 | $result['source'] = $this->messageSource; 200 | } elseif ($this->type === self::TYPE_STATE_INIT) { 201 | $result['code'] = $this->code; 202 | $result['data'] = $this->data; 203 | $result['library'] = $this->library; 204 | } elseif ($this->type === self::TYPE_TVC) { 205 | $result['type'] = $this->type; 206 | $result['tvc'] = $this->tvc; 207 | $result['public_key'] = $this->publicKey; 208 | $result['init_params'] = $this->stateInitParams; 209 | } else { 210 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 211 | } 212 | 213 | return $result; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /src/Entity/AbstractData.php: -------------------------------------------------------------------------------- 1 | */ 12 | private array $data; 13 | 14 | /** 15 | * @param array $data 16 | */ 17 | public function __construct(array $data) 18 | { 19 | $this->data = $data; 20 | } 21 | 22 | /** 23 | * @param string ...$keys 24 | * @return array|mixed|null 25 | */ 26 | protected function getOriginData(string ...$keys) 27 | { 28 | $result = $this->data; 29 | while ($key = array_shift($keys)) { 30 | if (!is_array($result) || !isset($result[$key])) { 31 | return null; 32 | } 33 | 34 | $result = $result[$key]; 35 | } 36 | 37 | return $result; 38 | } 39 | 40 | /** 41 | * @param string ...$keys 42 | * @return array|null 43 | */ 44 | protected function getArray(string ...$keys): ?array 45 | { 46 | $result = $this->getOriginData(...$keys); 47 | 48 | if (!is_array($result)) { 49 | return null; 50 | } 51 | 52 | return $result; 53 | } 54 | 55 | /** 56 | * @param string ...$keys 57 | * @return string|null 58 | */ 59 | protected function getString(string ...$keys): ?string 60 | { 61 | $result = $this->getOriginData(...$keys); 62 | 63 | if (!is_string($result)) { 64 | return null; 65 | } 66 | 67 | return $result; 68 | } 69 | 70 | /** 71 | * @param string ...$keys 72 | * @return int|null 73 | */ 74 | protected function getInt(string ...$keys): ?int 75 | { 76 | $result = $this->getOriginData(...$keys); 77 | 78 | if (!is_int($result)) { 79 | return null; 80 | } 81 | 82 | return $result; 83 | } 84 | 85 | /** 86 | * @param string ...$keys 87 | * @return mixed 88 | * @throws DataException 89 | */ 90 | protected function requireData(string ...$keys) 91 | { 92 | $result = $this->getOriginData(...$keys); 93 | 94 | if ($result === null) { 95 | $path = implode('.', $keys); 96 | 97 | throw new DataException(sprintf('Data not found by key %s.', $path)); 98 | } 99 | 100 | return $result; 101 | } 102 | 103 | /** 104 | * @param string ...$keys 105 | * @return array 106 | * @throws DataException 107 | */ 108 | protected function requireArray(string ...$keys): array 109 | { 110 | $result = $this->requireData(...$keys); 111 | 112 | if (!is_array($result)) { 113 | $path = implode('.', $keys); 114 | 115 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 116 | } 117 | 118 | return $result; 119 | } 120 | 121 | /** 122 | * @param string ...$keys 123 | * @return string 124 | * @throws DataException 125 | */ 126 | protected function requireString(string ...$keys): string 127 | { 128 | $result = $this->requireData(...$keys); 129 | 130 | if (!is_string($result)) { 131 | $path = implode('.', $keys); 132 | 133 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 134 | } 135 | 136 | return $result; 137 | } 138 | 139 | /** 140 | * @param string ...$keys 141 | * @return int 142 | * @throws DataException 143 | */ 144 | protected function requireInt(string ...$keys): int 145 | { 146 | $result = $this->requireData(...$keys); 147 | 148 | if (!is_int($result)) { 149 | $path = implode('.', $keys); 150 | 151 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 152 | } 153 | 154 | return $result; 155 | } 156 | 157 | /** 158 | * @param string ...$keys 159 | * @return bool 160 | * @throws DataException 161 | */ 162 | protected function requireBool(string ...$keys): bool 163 | { 164 | $result = $this->requireData(...$keys); 165 | 166 | if (!is_bool($result)) { 167 | $path = implode('.', $keys); 168 | 169 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 170 | } 171 | 172 | return $result; 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /src/Entity/AbstractResult.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | abstract class AbstractResult implements IteratorAggregate 26 | { 27 | private Response $response; 28 | 29 | /** 30 | * @param Response $response 31 | */ 32 | public function __construct(Response $response) 33 | { 34 | $this->response = $response; 35 | } 36 | 37 | /** 38 | * @return array 39 | */ 40 | public function getResponseData(): array 41 | { 42 | return $this->response->getResponseData(); 43 | } 44 | 45 | /** 46 | * @return bool 47 | */ 48 | public function isFinished(): bool 49 | { 50 | return $this->response->isEventsFinished(); 51 | } 52 | 53 | /** 54 | * @return Response 55 | */ 56 | protected function getResponse(): Response 57 | { 58 | return $this->response; 59 | } 60 | 61 | /** 62 | * @param string ...$keys 63 | * @return mixed 64 | * @throws DataException 65 | */ 66 | protected function requireData(string ...$keys) 67 | { 68 | $result = $this->getOriginData(...$keys); 69 | 70 | if ($result === null) { 71 | $path = implode('.', $keys); 72 | 73 | throw new DataException(sprintf('Data not found by key %s.', $path)); 74 | } 75 | 76 | return $result; 77 | } 78 | 79 | /** 80 | * @param string ...$keys 81 | * @return array|mixed|null 82 | */ 83 | protected function getOriginData(string ...$keys) 84 | { 85 | $result = $this->getResponseData(); 86 | while ($key = array_shift($keys)) { 87 | if (!is_array($result) || !isset($result[$key])) { 88 | return null; 89 | } 90 | 91 | $result = $result[$key]; 92 | } 93 | 94 | return $result; 95 | } 96 | 97 | /** 98 | * @param string ...$keys 99 | * @return array|null 100 | */ 101 | protected function getArray(string ...$keys): ?array 102 | { 103 | $result = $this->getOriginData(...$keys); 104 | 105 | if (!is_array($result)) { 106 | return null; 107 | } 108 | 109 | return $result; 110 | } 111 | 112 | /** 113 | * @param string ...$keys 114 | * @return string|null 115 | */ 116 | protected function getString(string ...$keys): ?string 117 | { 118 | $result = $this->getOriginData(...$keys); 119 | 120 | if (!is_string($result)) { 121 | return null; 122 | } 123 | 124 | return $result; 125 | } 126 | 127 | /** 128 | * @param string ...$keys 129 | * @return array 130 | * @throws DataException 131 | */ 132 | protected function requireArray(string ...$keys): array 133 | { 134 | $result = $this->requireData(...$keys); 135 | 136 | if (!is_array($result)) { 137 | $path = implode('.', $keys); 138 | 139 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 140 | } 141 | 142 | return $result; 143 | } 144 | 145 | /** 146 | * @param string ...$keys 147 | * @return string 148 | * @throws DataException 149 | */ 150 | protected function requireString(string ...$keys): string 151 | { 152 | $result = $this->requireData(...$keys); 153 | 154 | if (!is_string($result)) { 155 | $path = implode('.', $keys); 156 | 157 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 158 | } 159 | 160 | return $result; 161 | } 162 | 163 | /** 164 | * @param string ...$keys 165 | * @return int 166 | * @throws DataException 167 | */ 168 | protected function requireInt(string ...$keys): int 169 | { 170 | $result = $this->requireData(...$keys); 171 | 172 | if (!is_int($result)) { 173 | $path = implode('.', $keys); 174 | 175 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 176 | } 177 | 178 | return $result; 179 | } 180 | 181 | /** 182 | * @param string ...$keys 183 | * @return bool 184 | * @throws DataException 185 | */ 186 | protected function requireBool(string ...$keys): bool 187 | { 188 | $result = $this->requireData(...$keys); 189 | 190 | if (!is_bool($result)) { 191 | $path = implode('.', $keys); 192 | 193 | throw new DataException(sprintf('Data is corrupted by key %s.', $path)); 194 | } 195 | 196 | return $result; 197 | } 198 | 199 | /** 200 | * @return Generator 201 | * @throws LogicException 202 | */ 203 | public function getIterator(): Generator 204 | { 205 | $generator = new Generator(); 206 | 207 | yield $generator->throw(new LogicException('Response cannot be iterated.')); 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/Entity/App/AppRequestResult.php: -------------------------------------------------------------------------------- 1 | type = $type; 29 | } 30 | 31 | /** 32 | * @param string $text 33 | * @return self 34 | */ 35 | public static function fromError(string $text): self 36 | { 37 | $instance = new self(self::TYPE_ERROR); 38 | $instance->setText($text); 39 | 40 | return $instance; 41 | } 42 | 43 | /** 44 | * @param mixed $result 45 | * @return self 46 | */ 47 | public static function fromOK($result): self 48 | { 49 | $instance = new self(self::TYPE_OK); 50 | $instance->setResult($result); 51 | 52 | return $instance; 53 | } 54 | 55 | /** 56 | * Set error text 57 | * 58 | * @param string $text 59 | */ 60 | private function setText(string $text): void 61 | { 62 | $this->text = $text; 63 | } 64 | 65 | /** 66 | * Set result 67 | * 68 | * @param mixed $result 69 | */ 70 | private function setResult($result): void 71 | { 72 | $this->result = $result; 73 | } 74 | 75 | public function jsonSerialize(): array 76 | { 77 | if (!in_array($this->type, [self::TYPE_OK, self::TYPE_ERROR], true)) { 78 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 79 | } 80 | 81 | $result = [ 82 | 'type' => $this->type, 83 | ]; 84 | 85 | if ($this->type === self::TYPE_OK) { 86 | $result['result'] = $this->result; 87 | } 88 | 89 | if ($this->type === self::TYPE_ERROR) { 90 | $result['text'] = $this->text; 91 | } 92 | 93 | return $result; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Entity/Boc/BuilderOp.php: -------------------------------------------------------------------------------- 1 | */ 35 | private array $builderOps; 36 | 37 | public function __construct(string $type) 38 | { 39 | $this->type = $type; 40 | } 41 | 42 | /** 43 | * @param int $size 44 | * @param mixed $value 45 | * @return self 46 | */ 47 | public static function fromInteger(int $size, $value): self 48 | { 49 | $instance = new self(self::TYPE_INTEGER); 50 | $instance->setSize($size); 51 | $instance->setValue($value); 52 | 53 | return $instance; 54 | } 55 | 56 | /** 57 | * @param string $bitString 58 | * @return self 59 | */ 60 | public static function fromBitString(string $bitString): self 61 | { 62 | $instance = new self(self::TYPE_BIT_STRING); 63 | $instance->setBitString($bitString); 64 | 65 | return $instance; 66 | } 67 | 68 | /** 69 | * @param array $builderOps 70 | * @return self 71 | */ 72 | public static function fromBuilderOps(array $builderOps): self 73 | { 74 | $instance = new self(self::TYPE_CELL); 75 | $instance->setBuilderOps($builderOps); 76 | 77 | return $instance; 78 | } 79 | 80 | /** 81 | * @param string $boc 82 | * @return self 83 | */ 84 | public static function fromCellBoc(string $boc): self 85 | { 86 | $instance = new self(self::TYPE_CELL); 87 | $instance->setBoc($boc); 88 | 89 | return $instance; 90 | } 91 | 92 | /** 93 | * @param int $size 94 | */ 95 | public function setSize(int $size): void 96 | { 97 | $this->size = $size; 98 | } 99 | 100 | /** 101 | * @param mixed $value 102 | */ 103 | public function setValue($value): void 104 | { 105 | $this->value = $value; 106 | } 107 | 108 | /** 109 | * @param string $bitString 110 | */ 111 | public function setBitString(string $bitString): void 112 | { 113 | $this->bitString = $bitString; 114 | } 115 | 116 | /** 117 | * @param string $boc 118 | */ 119 | public function setBoc(string $boc): void 120 | { 121 | $this->boc = $boc; 122 | } 123 | 124 | /** 125 | * @param array $builderOps 126 | */ 127 | public function setBuilderOps(array $builderOps): void 128 | { 129 | $this->builderOps = $builderOps; 130 | } 131 | 132 | public function jsonSerialize(): array 133 | { 134 | if (!in_array( 135 | $this->type, 136 | [ 137 | self::TYPE_INTEGER, 138 | self::TYPE_BIT_STRING, 139 | self::TYPE_CELL, 140 | self::TYPE_CELL_BOC 141 | ], 142 | true 143 | )) { 144 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 145 | } 146 | 147 | $result = [ 148 | 'type' => $this->type, 149 | ]; 150 | 151 | if ($this->type === self::TYPE_INTEGER) { 152 | $result['size'] = $this->size; 153 | $result['value'] = $this->value; 154 | } 155 | 156 | if ($this->type === self::TYPE_BIT_STRING) { 157 | $result['value'] = $this->bitString; 158 | } 159 | 160 | if ($this->type === self::TYPE_CELL) { 161 | $result['builder'] = $this->builderOps; 162 | } 163 | 164 | if ($this->type === self::TYPE_CELL_BOC) { 165 | $result['boc'] = $this->boc; 166 | } 167 | 168 | return $result; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/Entity/Boc/CacheType.php: -------------------------------------------------------------------------------- 1 | type = $type; 29 | } 30 | 31 | /** 32 | * Create cache type pinned 33 | * 34 | * @param string $pin Pin name 35 | * @return self 36 | */ 37 | public static function fromPinned(string $pin): self 38 | { 39 | $instance = new self(self::TYPE_PINNED); 40 | $instance->setPin($pin); 41 | 42 | return $instance; 43 | } 44 | 45 | /** 46 | * Create cache type unpinned 47 | * 48 | * @return self 49 | */ 50 | public static function fromUnpinned(): self 51 | { 52 | return new self(self::TYPE_UNPINNED); 53 | } 54 | 55 | /** 56 | * @param string $pin 57 | */ 58 | public function setPin(string $pin): void 59 | { 60 | $this->pin = $pin; 61 | } 62 | 63 | /** 64 | * @inheritDoc 65 | */ 66 | public function jsonSerialize(): array 67 | { 68 | if (!in_array($this->type, [self::TYPE_PINNED, self::TYPE_UNPINNED], true)) { 69 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 70 | } 71 | 72 | $result = [ 73 | 'type' => $this->type, 74 | ]; 75 | 76 | if ($this->type === self::TYPE_PINNED) { 77 | $result['pin'] = $this->pin; 78 | } 79 | 80 | return $result; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfBocCacheGet.php: -------------------------------------------------------------------------------- 1 | getOriginData('boc'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfBocCacheSet.php: -------------------------------------------------------------------------------- 1 | requireString('boc_ref'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfEncodeBoc.php: -------------------------------------------------------------------------------- 1 | requireString('boc'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfGetBlockchainConfig.php: -------------------------------------------------------------------------------- 1 | requireString('config_boc'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfGetBocHash.php: -------------------------------------------------------------------------------- 1 | requireString('hash'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfGetCodeFromTvc.php: -------------------------------------------------------------------------------- 1 | requireString('code'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Boc/ResultOfParse.php: -------------------------------------------------------------------------------- 1 | getOriginData('parsed'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Client/ClientError.php: -------------------------------------------------------------------------------- 1 | requireInt('code'); 22 | } 23 | 24 | /** 25 | * Get error message 26 | * 27 | * @return string 28 | */ 29 | public function getMessage(): string 30 | { 31 | return $this->requireString('message'); 32 | } 33 | 34 | /** 35 | * Get error data 36 | * 37 | * @return mixed 38 | */ 39 | public function getErrorData() 40 | { 41 | return $this->getOriginData('data'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Client/ResultOfBuildInfo.php: -------------------------------------------------------------------------------- 1 | requireInt('build_number'); 22 | } 23 | 24 | /** 25 | * Get dependencies 26 | * 27 | * @return array 28 | */ 29 | public function getDependencies(): array 30 | { 31 | return $this->requireArray('dependencies'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Client/ResultOfGetApiReference.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getApi(): array 20 | { 21 | return $this->requireArray('api'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Client/ResultOfVersion.php: -------------------------------------------------------------------------------- 1 | requireString('version'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/AesParams.php: -------------------------------------------------------------------------------- 1 | cipherMode = $cipherMode; 27 | $this->key = $key; 28 | $this->iv = $iv; 29 | } 30 | 31 | public function jsonSerialize(): array 32 | { 33 | return [ 34 | 'mode' => $this->cipherMode, 35 | 'key' => $this->key, 36 | 'iv' => $this->iv, 37 | ]; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entity/Crypto/EncryptionAlgorithm.php: -------------------------------------------------------------------------------- 1 | type = $type; 20 | } 21 | 22 | public static function createFromAES(AesParams $aesParams): self 23 | { 24 | $instance = new self(self::TYPE_AES); 25 | $instance->setAesParams($aesParams); 26 | 27 | return $instance; 28 | } 29 | 30 | public function setAesParams(AesParams $aesParams): self 31 | { 32 | $this->aesParams = $aesParams; 33 | 34 | return $this; 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public function jsonSerialize(): array 41 | { 42 | if ($this->type === self::TYPE_AES) { 43 | $params['type'] = $this->type; 44 | $params['value'] = $this->aesParams; 45 | 46 | return $params; 47 | } 48 | 49 | return []; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Entity/Crypto/KeyPair.php: -------------------------------------------------------------------------------- 1 | public = $public; 25 | $this->secret = $secret; 26 | } 27 | 28 | /** 29 | * Get public key - 64 symbols hex string 30 | * 31 | * @return string 32 | */ 33 | public function getPublic(): string 34 | { 35 | return $this->public; 36 | } 37 | 38 | /** 39 | * Get private key - u64 symbols hex string 40 | * 41 | * @return string 42 | */ 43 | public function getSecret(): string 44 | { 45 | return $this->secret; 46 | } 47 | 48 | /** 49 | * @inheritDoc 50 | */ 51 | public function jsonSerialize(): array 52 | { 53 | return [ 54 | 'public' => $this->getPublic(), 55 | 'secret' => $this->getSecret(), 56 | ]; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Entity/Crypto/RegisteredEncryptionBox.php: -------------------------------------------------------------------------------- 1 | requireInt('handle'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfChaCha20.php: -------------------------------------------------------------------------------- 1 | requireString('data'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfConvertPublicKeyToTonSafeFormat.php: -------------------------------------------------------------------------------- 1 | requireString('ton_public_key'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfEncryptionBoxDecrypt.php: -------------------------------------------------------------------------------- 1 | requireString('data'); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfEncryptionBoxEncrypt.php: -------------------------------------------------------------------------------- 1 | requireString('data'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfEncryptionBoxGetInfo.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function getInfo(): array 18 | { 19 | return $this->requireArray('info'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfFactorize.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getFactors(): array 20 | { 21 | return $this->requireArray('factors'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfGenerateMnemonic.php: -------------------------------------------------------------------------------- 1 | requireString('phrase'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfGenerateRandomBytes.php: -------------------------------------------------------------------------------- 1 | requireString('bytes'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfGenerateSignKeys.php: -------------------------------------------------------------------------------- 1 | requireString('public'); 22 | } 23 | 24 | /** 25 | * Get private key - u64 symbols hex string 26 | * 27 | * @return string 28 | */ 29 | public function getSecret(): string 30 | { 31 | return $this->requireString('secret'); 32 | } 33 | 34 | /** 35 | * Get KeyPair 36 | * 37 | * @return KeyPair 38 | */ 39 | public function getKeyPair(): KeyPair 40 | { 41 | return new KeyPair( 42 | $this->requireString('public'), 43 | $this->requireString('secret') 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfGetSigningBox.php: -------------------------------------------------------------------------------- 1 | requireInt('handle'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfHDKeyPublicFromXPrv.php: -------------------------------------------------------------------------------- 1 | requireString('public'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfHDKeySecretFromXPrv.php: -------------------------------------------------------------------------------- 1 | requireString('secret'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfHDKeyXPrv.php: -------------------------------------------------------------------------------- 1 | requireString('xprv'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfHash.php: -------------------------------------------------------------------------------- 1 | requireString('hash'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfMnemonicVerify.php: -------------------------------------------------------------------------------- 1 | requireBool('valid'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfMnemonicWords.php: -------------------------------------------------------------------------------- 1 | requireString('words'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfModularPower.php: -------------------------------------------------------------------------------- 1 | requireString('modular_power'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclBox.php: -------------------------------------------------------------------------------- 1 | requireString('encrypted'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclBoxOpen.php: -------------------------------------------------------------------------------- 1 | requireString('decrypted'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclSign.php: -------------------------------------------------------------------------------- 1 | requireString('signed'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclSignDetached.php: -------------------------------------------------------------------------------- 1 | requireString('signature'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclSignDetachedVerify.php: -------------------------------------------------------------------------------- 1 | requireBool('succeeded'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfNaclSignOpen.php: -------------------------------------------------------------------------------- 1 | requireString('unsigned'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfScrypt.php: -------------------------------------------------------------------------------- 1 | requireString('key'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfSign.php: -------------------------------------------------------------------------------- 1 | requireString('signed'); 22 | } 23 | 24 | /** 25 | * Get signature encoded in hex 26 | * 27 | * @return string 28 | */ 29 | public function getSignature(): string 30 | { 31 | return $this->requireString('signature'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfSigningBoxGetPublicKey.php: -------------------------------------------------------------------------------- 1 | requireString('pubkey'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfSigningBoxSign.php: -------------------------------------------------------------------------------- 1 | requireString('signature'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfTonCrc16.php: -------------------------------------------------------------------------------- 1 | requireInt('crc'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Crypto/ResultOfVerifySignature.php: -------------------------------------------------------------------------------- 1 | requireString('unsigned'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Debot/DebotAction.php: -------------------------------------------------------------------------------- 1 | description = $description; 45 | $this->name = $name; 46 | $this->actionType = $actionType; 47 | $this->to = $to; 48 | $this->attributes = $attributes; 49 | $this->misc = $misc; 50 | } 51 | 52 | public function jsonSerialize(): array 53 | { 54 | return [ 55 | 'description' => $this->description, 56 | 'name' => $this->name, 57 | 'action_type' => $this->actionType, 58 | 'to' => $this->to, 59 | 'attributes' => $this->attributes, 60 | 'misc' => $this->misc, 61 | ]; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Entity/Debot/RegisteredDebot.php: -------------------------------------------------------------------------------- 1 | requireInt('debot_handle'); 22 | } 23 | 24 | /** 25 | * Get debot abi as json string 26 | * 27 | * @return string 28 | */ 29 | public function getDebotAbi(): string 30 | { 31 | return $this->requireString('debot_abi'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Net/AbstractQuery.php: -------------------------------------------------------------------------------- 1 | */ 24 | private array $resultFields; 25 | 26 | private ?Filters $filters = null; 27 | 28 | private ?OrderBy $orderBy = null; 29 | 30 | private ?int $limit = null; 31 | 32 | private ?int $timeout = null; 33 | 34 | private ?Aggregation $aggregation = null; 35 | 36 | /** 37 | * @param string $collection 38 | * @param array $resultFields 39 | */ 40 | public function __construct(string $collection, array $resultFields = []) 41 | { 42 | $this->collection = $collection; 43 | $this->resultFields = $resultFields; 44 | } 45 | 46 | /** 47 | * @param string ...$fieldNames 48 | * @return self 49 | */ 50 | public function addResultField(string ...$fieldNames): self 51 | { 52 | $this->resultFields = [...$this->resultFields, ...$fieldNames]; 53 | 54 | return $this; 55 | } 56 | 57 | /** 58 | * @param string $field 59 | * @param string $direction 60 | * @return self 61 | */ 62 | public function addOrderBy(string $field, string $direction): self 63 | { 64 | if ($this->orderBy === null) { 65 | $this->orderBy = new OrderBy(); 66 | } 67 | 68 | $this->orderBy->add($field, $direction); 69 | 70 | return $this; 71 | } 72 | 73 | /** 74 | * @param string $field 75 | * @param string $operator 76 | * @param mixed $value 77 | * @return self 78 | */ 79 | public function addFilter(string $field, string $operator, $value): self 80 | { 81 | if ($this->filters === null) { 82 | $this->filters = new Filters(); 83 | } 84 | 85 | $this->filters->add($field, $operator, $value); 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * @inheritDoc 92 | */ 93 | public function getCollection(): string 94 | { 95 | return $this->collection; 96 | } 97 | 98 | /** 99 | * @inheritDoc 100 | */ 101 | public function getResult(): string 102 | { 103 | if (empty($this->resultFields)) { 104 | throw new LogicException('Result fields cannot be empty'); 105 | } 106 | 107 | return implode(' ', $this->resultFields); 108 | } 109 | 110 | /** 111 | * @inheritDoc 112 | */ 113 | public function getFilters(): ?Params 114 | { 115 | return $this->filters; 116 | } 117 | 118 | /** 119 | * @param Filters|null $filters 120 | * @return self 121 | */ 122 | public function setFilters(?Filters $filters): self 123 | { 124 | $this->filters = $filters; 125 | 126 | return $this; 127 | } 128 | 129 | /** 130 | * @inheritDoc 131 | */ 132 | public function getOrderBy(): ?Params 133 | { 134 | return $this->orderBy; 135 | } 136 | 137 | /** 138 | * @param OrderBy|null $orderBy 139 | * @return self 140 | */ 141 | public function setOrderBy(?OrderBy $orderBy): self 142 | { 143 | $this->orderBy = $orderBy; 144 | 145 | return $this; 146 | } 147 | 148 | /** 149 | * @inheritDoc 150 | */ 151 | public function getLimit(): ?int 152 | { 153 | return $this->limit; 154 | } 155 | 156 | /** 157 | * @param int|null $limit 158 | * @return self 159 | */ 160 | public function setLimit(?int $limit): self 161 | { 162 | $this->limit = $limit; 163 | 164 | return $this; 165 | } 166 | 167 | /** 168 | * @inheritDoc 169 | */ 170 | public function getTimeout(): ?int 171 | { 172 | return $this->timeout; 173 | } 174 | 175 | /** 176 | * @param int|null $timeout 177 | * @return self 178 | */ 179 | public function setTimeout(?int $timeout): self 180 | { 181 | $this->timeout = $timeout; 182 | 183 | return $this; 184 | } 185 | 186 | /** 187 | * @inheritDoc 188 | */ 189 | public function getAggregation(): ?Aggregation 190 | { 191 | return $this->aggregation; 192 | } 193 | 194 | /** 195 | * @param Aggregation|null $aggregation 196 | */ 197 | public function setAggregation(?Aggregation $aggregation): void 198 | { 199 | $this->aggregation = $aggregation; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/Entity/Net/Aggregation.php: -------------------------------------------------------------------------------- 1 | > */ 37 | private array $fields = []; 38 | 39 | /** 40 | * @param string $field 41 | * @param string $function 42 | * @return self 43 | */ 44 | public function add(string $field, string $function): self 45 | { 46 | if (!in_array($function, self::FUNCTIONS, true)) { 47 | throw new LogicException(sprintf('Unknown aggregation function %s.', $function)); 48 | } 49 | 50 | $this->fields[] = [ 51 | 'field' => $field, 52 | 'fn' => $function, 53 | ]; 54 | 55 | return $this; 56 | } 57 | 58 | /** 59 | * @inheritDoc 60 | */ 61 | public function jsonSerialize(): array 62 | { 63 | return $this->fields; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Entity/Net/DeepFilters.php: -------------------------------------------------------------------------------- 1 | filters[$field])) { 17 | throw new LogicException(sprintf('Field %s already defined.', $field)); 18 | } 19 | 20 | $fieldChain = [$operator => $value]; 21 | foreach (array_reverse($fields) as $newField) { 22 | $fieldChain = [ 23 | $newField => $fieldChain 24 | ]; 25 | } 26 | 27 | $this->filters[$field] = $fieldChain[$field]; 28 | 29 | return $this; 30 | } 31 | } -------------------------------------------------------------------------------- /src/Entity/Net/EndpointsSet.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function getEndpoints(): array 18 | { 19 | return $this->requireArray('endpoints'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Entity/Net/Event.php: -------------------------------------------------------------------------------- 1 | 16 | */ 17 | public function getResult(): array 18 | { 19 | return $this->requireArray('result'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Entity/Net/Filters.php: -------------------------------------------------------------------------------- 1 | */ 46 | protected array $filters = []; 47 | 48 | /** 49 | * @param string $field 50 | * @param string $operator 51 | * @param mixed $value 52 | * @return self 53 | */ 54 | public function add(string $field, string $operator, $value): self 55 | { 56 | if (isset($this->filters[$field])) { 57 | throw new LogicException(sprintf('Field %s already defined.', $field)); 58 | } 59 | 60 | if (!in_array($operator, self::OPERATORS, true)) { 61 | throw new LogicException(sprintf('Unknown operator %s.', $operator)); 62 | } 63 | 64 | $this->filters[$field] = [ 65 | $operator => $value, 66 | ]; 67 | 68 | return $this; 69 | } 70 | 71 | /** 72 | * @inheritDoc 73 | */ 74 | public function jsonSerialize(): array 75 | { 76 | return $this->filters; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Entity/Net/MessageNode.php: -------------------------------------------------------------------------------- 1 | > $list 20 | * @return array 21 | */ 22 | public static function createCollection(array $list): array 23 | { 24 | return array_map( 25 | fn ($data): self => new self($data), 26 | $list 27 | ); 28 | } 29 | 30 | /** 31 | * Get message id 32 | * 33 | * @return string 34 | */ 35 | public function getId(): string 36 | { 37 | return $this->requireString('id'); 38 | } 39 | 40 | /** 41 | * Source transaction id. This field is missing for an external inbound messages. 42 | * 43 | * @return string|null 44 | */ 45 | public function getSrcTransactionId(): ?string 46 | { 47 | return $this->getString('src_transaction_id'); 48 | } 49 | 50 | /** 51 | * Destination transaction id. This field is missing for an external outbound messages. 52 | * 53 | * @return string|null 54 | */ 55 | public function getDstTransactionId(): ?string 56 | { 57 | return $this->getString('dst_transaction_id'); 58 | } 59 | 60 | /** 61 | * Get source address 62 | * 63 | * @return string|null 64 | */ 65 | public function getSrcAddress(): ?string 66 | { 67 | return $this->getString('src'); 68 | } 69 | 70 | /** 71 | * Destination address 72 | * 73 | * @return string|null 74 | */ 75 | public function getDstAddress(): ?string 76 | { 77 | return $this->getString('dst'); 78 | } 79 | 80 | /** 81 | * Get transferred tokens value 82 | * 83 | * @return string|null 84 | */ 85 | public function getValue(): ?string 86 | { 87 | return $this->getString('value'); 88 | } 89 | 90 | /** 91 | * Get bounce flag 92 | * 93 | * @return bool|null 94 | */ 95 | public function getBounce(): ?bool 96 | { 97 | return $this->requireBool('bounce'); 98 | } 99 | 100 | /** 101 | * Get decoded body. 102 | * Library tries to decode message body using provided params.abi_registry. 103 | * This field will be missing if none of the provided abi can be used to decode. 104 | * 105 | * @return DecodedMessageBody|null 106 | */ 107 | public function getDecodedBody(): ?DecodedMessageBody 108 | { 109 | $data = $this->getArray('decoded_body'); 110 | if ($data === null) { 111 | return null; 112 | } 113 | 114 | return new DecodedMessageBody(new Response($data)); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Entity/Net/OrderBy.php: -------------------------------------------------------------------------------- 1 | */ 23 | private array $orderBy; 24 | 25 | /** 26 | * Add OrderBy condition 27 | * 28 | * @param string $field 29 | * @param string $direction 30 | * @return self 31 | * @throws LogicException 32 | */ 33 | public function add(string $field, string $direction): self 34 | { 35 | if (!in_array($direction, [self::ASC, self::DESC], true)) { 36 | throw new LogicException(sprintf('Invalid direction %s.', $direction)); 37 | } 38 | 39 | if (isset($this->orderBy[$field])) { 40 | throw new LogicException(sprintf('OrderBy field %s already defined.', $field)); 41 | } 42 | 43 | $this->orderBy[$field] = $direction; 44 | 45 | return $this; 46 | } 47 | 48 | /** 49 | * @inheritDoc 50 | */ 51 | public function jsonSerialize(): array 52 | { 53 | $orderBy = []; 54 | 55 | foreach ($this->orderBy as $field => $direction) { 56 | $orderBy[] = [ 57 | 'path' => $field, 58 | 'direction' => $direction, 59 | ]; 60 | } 61 | 62 | return $orderBy; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Entity/Net/ParamsOfAggregateCollection.php: -------------------------------------------------------------------------------- 1 | setFilters($filters); 27 | $this->setAggregation($aggregation); 28 | } 29 | 30 | /** 31 | * @return string 32 | */ 33 | public function getResult(): string 34 | { 35 | throw new LogicException('Method ParamsOfAggregateCollection::getResult is not implemented.'); 36 | } 37 | 38 | /** 39 | * @inheritDoc 40 | */ 41 | public function getOrderBy(): ?Params 42 | { 43 | throw new LogicException('Method ParamsOfAggregateCollection::getOrderBy is not implemented.'); 44 | } 45 | 46 | /** 47 | * @inheritDoc 48 | */ 49 | public function getLimit(): ?int 50 | { 51 | throw new LogicException('Method ParamsOfAggregateCollection::getLimit is not implemented.'); 52 | } 53 | 54 | /** 55 | * @inheritDoc 56 | */ 57 | public function getTimeout(): ?int 58 | { 59 | throw new LogicException('Method ParamsOfAggregateCollection::getTimeout is not implemented.'); 60 | } 61 | 62 | /** 63 | * @inheritDoc 64 | */ 65 | public function jsonSerialize(): array 66 | { 67 | return [ 68 | 'collection' => $this->getCollection(), 69 | 'filter' => $this->getFilters(), 70 | 'fields' => $this->getAggregation(), 71 | ]; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Entity/Net/ParamsOfBatchQuery.php: -------------------------------------------------------------------------------- 1 | 'QueryCollection', 17 | ParamsOfWaitForCollection::class => 'WaitForCollection', 18 | ParamsOfAggregateCollection::class => 'AggregateCollection', 19 | ]; 20 | 21 | /** @var array> */ 22 | private array $paramsOfQueries = []; 23 | 24 | /** 25 | * @param QueryInterface $query 26 | */ 27 | public function add(QueryInterface $query): void 28 | { 29 | $class = get_class($query); 30 | 31 | if (!array_key_exists($class, self::MAP)) { 32 | throw new LogicException(sprintf('Unsupported query type %s was passed.', $class)); 33 | } 34 | 35 | $params = $query->jsonSerialize(); 36 | $params['type'] = self::MAP[$class]; 37 | 38 | $this->paramsOfQueries[] = $params; 39 | } 40 | 41 | public function jsonSerialize(): array 42 | { 43 | return $this->paramsOfQueries; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Entity/Net/ParamsOfQueryCollection.php: -------------------------------------------------------------------------------- 1 | $resultFields 17 | * @param Filters|null $filters 18 | * @param OrderBy|null $orderBy 19 | * @param int|null $limit 20 | */ 21 | public function __construct( 22 | string $collection, 23 | array $resultFields = [], 24 | ?Filters $filters = null, 25 | ?OrderBy $orderBy = null, 26 | ?int $limit = null 27 | ) { 28 | parent::__construct($collection, $resultFields); 29 | $this->setFilters($filters); 30 | $this->setOrderBy($orderBy); 31 | $this->setLimit($limit); 32 | } 33 | 34 | /** 35 | * @inheritDoc 36 | */ 37 | public function getTimeout(): ?int 38 | { 39 | throw new LogicException('Method ParamsOfQueryCollection::getTimeout is not implemented.'); 40 | } 41 | 42 | /** 43 | * @inheritDoc 44 | */ 45 | public function getAggregation(): ?Aggregation 46 | { 47 | throw new LogicException('Method ParamsOfQueryCollection::getAggregation is not implemented.'); 48 | } 49 | 50 | /** 51 | * @inheritDoc 52 | */ 53 | public function jsonSerialize(): array 54 | { 55 | return [ 56 | 'collection' => $this->getCollection(), 57 | 'result' => $this->getResult(), 58 | 'filter' => $this->getFilters(), 59 | 'order' => $this->getOrderBy(), 60 | 'limit' => $this->getLimit(), 61 | ]; 62 | } 63 | 64 | /** 65 | * @param string[] $fieldNames 66 | * @return $this 67 | */ 68 | public function addDeepResultField(string ...$fieldNames): self 69 | { 70 | $this->addResultField($this->getRecursiveDeepResultField($fieldNames, 0)); 71 | return $this; 72 | } 73 | 74 | /** 75 | * @param string[] $fieldNames 76 | * @param int $index 77 | * @return string 78 | */ 79 | private function getRecursiveDeepResultField(array $fieldNames, int $index): string 80 | { 81 | if ($index >= count($fieldNames)) { 82 | return ''; 83 | } 84 | $result = $fieldNames[$index]; 85 | $nextPart = $this->getRecursiveDeepResultField($fieldNames, $index + 1); 86 | $nextPart = $nextPart ? "{ {$nextPart} }" : ''; 87 | return "{$result} {$nextPart}"; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/Entity/Net/ParamsOfSubscribeCollection.php: -------------------------------------------------------------------------------- 1 | $resultFields 18 | * @param Filters|null $filters 19 | */ 20 | public function __construct( 21 | string $collection, 22 | array $resultFields = [], 23 | ?Filters $filters = null 24 | ) { 25 | parent::__construct($collection, $resultFields); 26 | $this->setFilters($filters); 27 | } 28 | 29 | /** 30 | * @inheritDoc 31 | */ 32 | public function getOrderBy(): ?Params 33 | { 34 | throw new LogicException('Method ParamsOfSubscribeCollection::getOrderBy is not implemented.'); 35 | } 36 | 37 | /** 38 | * @inheritDoc 39 | */ 40 | public function getLimit(): ?int 41 | { 42 | throw new LogicException('Method ParamsOfSubscribeCollection::getLimit is not implemented.'); 43 | } 44 | 45 | /** 46 | * @inheritDoc 47 | */ 48 | public function getTimeout(): ?int 49 | { 50 | throw new LogicException('Method ParamsOfSubscribeCollection::getTimeout is not implemented.'); 51 | } 52 | 53 | /** 54 | * @inheritDoc 55 | */ 56 | public function getAggregation(): ?Aggregation 57 | { 58 | throw new LogicException('Method ParamsOfSubscribeCollection::getAggregation is not implemented.'); 59 | } 60 | 61 | /** 62 | * @inheritDoc 63 | */ 64 | public function jsonSerialize(): array 65 | { 66 | return [ 67 | 'collection' => $this->getCollection(), 68 | 'result' => $this->getResult(), 69 | 'filter' => $this->getFilters(), 70 | ]; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Entity/Net/ParamsOfWaitForCollection.php: -------------------------------------------------------------------------------- 1 | $resultFields 18 | * @param Filters|null $filters 19 | * @param int|null $timeout 20 | */ 21 | public function __construct( 22 | string $collection, 23 | array $resultFields = [], 24 | ?Filters $filters = null, 25 | ?int $timeout = null 26 | ) { 27 | parent::__construct($collection, $resultFields); 28 | $this->setFilters($filters); 29 | $this->setTimeout($timeout); 30 | } 31 | 32 | /** 33 | * @inheritDoc 34 | */ 35 | public function getOrderBy(): ?Params 36 | { 37 | throw new LogicException('Method ParamsOfWaitForCollection::getOrderBy is not implemented.'); 38 | } 39 | 40 | /** 41 | * @inheritDoc 42 | */ 43 | public function getLimit(): ?int 44 | { 45 | throw new LogicException('Method ParamsOfWaitForCollection::getLimit is not implemented.'); 46 | } 47 | 48 | /** 49 | * @inheritDoc 50 | */ 51 | public function getAggregation(): ?Aggregation 52 | { 53 | throw new LogicException('Method ParamsOfWaitForCollection::getAggregation is not implemented.'); 54 | } 55 | 56 | /** 57 | * @inheritDoc 58 | */ 59 | public function jsonSerialize(): array 60 | { 61 | return [ 62 | 'collection' => $this->getCollection(), 63 | 'result' => $this->getResult(), 64 | 'filter' => $this->getFilters(), 65 | 'timeout' => $this->getTimeout(), 66 | ]; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/Entity/Net/QueryInterface.php: -------------------------------------------------------------------------------- 1 | requireInt('handle'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfAggregateCollection.php: -------------------------------------------------------------------------------- 1 | getOriginData('values'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfBatchQuery.php: -------------------------------------------------------------------------------- 1 | 19 | */ 20 | public function getResults(): array 21 | { 22 | return $this->requireArray('results'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfFindLastShardBlock.php: -------------------------------------------------------------------------------- 1 | requireString('block_id'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfIteratorNext.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getItems(): array 20 | { 21 | return $this->requireArray('items'); 22 | } 23 | 24 | /** 25 | * Indicates that there are more available items in iterated range. 26 | * 27 | * @return bool 28 | */ 29 | public function hasMore(): bool 30 | { 31 | return $this->requireBool('has_more'); 32 | } 33 | 34 | /** 35 | * Optional iterator state that can be used for resuming iteration. 36 | * 37 | * @return list|mixed 38 | */ 39 | public function getResumeState() 40 | { 41 | return $this->requireData('resume_state'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfQuery.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getResult(): array 20 | { 21 | return $this->requireArray('result'); 22 | } 23 | 24 | /** 25 | * @return array 26 | */ 27 | public function getData(): array 28 | { 29 | return $this->getResult()['data'] ?? []; 30 | } 31 | 32 | /** 33 | * @return array 34 | */ 35 | public function getMessages(): array 36 | { 37 | return $this->getData()['messages'] ?? []; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfQueryCollection.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getResult(): array 20 | { 21 | return $this->requireArray('result'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfQueryCounterparties.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getResult(): array 20 | { 21 | return $this->requireArray('result'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfQueryTransactionTree.php: -------------------------------------------------------------------------------- 1 | 18 | */ 19 | public function getMessages(): array 20 | { 21 | return MessageNode::createCollection($this->requireArray('messages')); 22 | } 23 | 24 | /** 25 | * Get transactions 26 | * 27 | * @return array 28 | */ 29 | public function getTransactions(): array 30 | { 31 | return TransactionNode::createCollection($this->requireArray('transactions')); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfSubscribeCollection.php: -------------------------------------------------------------------------------- 1 | net = $net; 28 | } 29 | 30 | /** 31 | * Stop watching 32 | * 33 | * @throws TonException 34 | */ 35 | public function stop(): void 36 | { 37 | $this->net->unsubscribe($this->getHandle()); 38 | } 39 | 40 | /** 41 | * Get subscription handle. Must be closed with unsubscribe 42 | * 43 | * @return int 44 | */ 45 | public function getHandle(): int 46 | { 47 | return $this->requireInt('handle'); 48 | } 49 | 50 | /** 51 | * Get generator for iterate Event objects 52 | * 53 | * @return Generator 54 | */ 55 | public function getIterator(): Generator 56 | { 57 | $response = $this->getResponse(); 58 | 59 | $response->setEventDataTransformer( 60 | static fn ($eventData) => new Event(new Response($eventData)) 61 | ); 62 | 63 | yield from $response; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Entity/Net/ResultOfWaitForCollection.php: -------------------------------------------------------------------------------- 1 | getOriginData('result'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Net/TransactionNode.php: -------------------------------------------------------------------------------- 1 | > $list 18 | * @return array 19 | */ 20 | public static function createCollection(array $list): array 21 | { 22 | return array_map( 23 | fn ($data): self => new self($data), 24 | $list 25 | ); 26 | } 27 | 28 | /** 29 | * Get transaction id 30 | * 31 | * @return string 32 | */ 33 | public function getId(): string 34 | { 35 | return $this->requireString('id'); 36 | } 37 | 38 | /** 39 | * Get in message id 40 | * 41 | * @return string 42 | */ 43 | public function getInMessage(): string 44 | { 45 | return $this->requireString('in_msg'); 46 | } 47 | 48 | /** 49 | * Get out message ids 50 | * 51 | * @return array 52 | */ 53 | public function getOutMessages(): array 54 | { 55 | return $this->requireArray('out_msgs'); 56 | } 57 | 58 | /** 59 | * Get account address 60 | * 61 | * @return string 62 | */ 63 | public function getAccountAddress(): string 64 | { 65 | return $this->requireString('account_addr'); 66 | } 67 | 68 | /** 69 | * Get transactions total fees 70 | * 71 | * @return string 72 | */ 73 | public function getTotalFees(): string 74 | { 75 | return $this->requireString('total_fees'); 76 | } 77 | 78 | /** 79 | * Get aborted flag 80 | * 81 | * @return bool 82 | */ 83 | public function getAborted(): bool 84 | { 85 | return $this->requireBool('aborted'); 86 | } 87 | 88 | /** 89 | * Get compute phase exit code 90 | * 91 | * @return int|null 92 | */ 93 | public function getExitCode(): ?int 94 | { 95 | return $this->getInt('exit_code'); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/Entity/Params.php: -------------------------------------------------------------------------------- 1 | 17 | * @throws DataException 18 | */ 19 | public function jsonSerialize(): array; 20 | } 21 | -------------------------------------------------------------------------------- /src/Entity/Processing/DecodedOutput.php: -------------------------------------------------------------------------------- 1 | requireArray('out_messages'))); 25 | } 26 | 27 | /** 28 | * Get decoded body of the function output message 29 | * 30 | * @return mixed 31 | */ 32 | public function getOutput() 33 | { 34 | return $this->getOriginData('output'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Entity/Processing/ProcessingEvent.php: -------------------------------------------------------------------------------- 1 | requireString('type'); 40 | } 41 | 42 | /** 43 | * Get client error 44 | * 45 | * @return ClientError 46 | */ 47 | public function getError(): ClientError 48 | { 49 | return new ClientError(new Response($this->requireArray('error'))); 50 | } 51 | 52 | /** 53 | * Get shard block ID 54 | * 55 | * @return string 56 | */ 57 | public function getShardBlockId(): string 58 | { 59 | return $this->requireString('shard_block_id'); 60 | } 61 | 62 | /** 63 | * Get message ID 64 | * 65 | * @return string 66 | */ 67 | public function getMessageId(): string 68 | { 69 | return $this->requireString('message_id'); 70 | } 71 | 72 | /** 73 | * Get message 74 | * 75 | * @return string 76 | */ 77 | public function getMessage(): string 78 | { 79 | return $this->requireString('message'); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Entity/Processing/ResultOfProcessMessage.php: -------------------------------------------------------------------------------- 1 | requireData('transaction'); 25 | } 26 | 27 | /** 28 | * Get list of output messages BOCs. Encoded as base64 29 | * 30 | * @return array 31 | */ 32 | public function getOutMessages(): array 33 | { 34 | return $this->requireArray('out_messages'); 35 | } 36 | 37 | /** 38 | * Get transaction fees 39 | * 40 | * @return TransactionFees 41 | */ 42 | public function getTransactionFees(): TransactionFees 43 | { 44 | return new TransactionFees( 45 | new Response( 46 | $this->requireArray('fees') 47 | ) 48 | ); 49 | } 50 | 51 | /** 52 | * Get transaction fees 53 | * 54 | * @return TransactionFees 55 | */ 56 | public function getFees(): TransactionFees 57 | { 58 | return $this->getTransactionFees(); 59 | } 60 | 61 | /** 62 | * Get optional decoded message bodies according to the optional abi parameter. 63 | * 64 | * @return DecodedOutput|null 65 | */ 66 | public function getDecoded(): ?DecodedOutput 67 | { 68 | return $this->getDecodedOutput(); 69 | } 70 | 71 | /** 72 | * Get optional decoded message bodies according to the optional abi parameter. 73 | * 74 | * @return DecodedOutput|null 75 | */ 76 | public function getDecodedOutput(): ?DecodedOutput 77 | { 78 | $result = $this->getArray('decoded'); 79 | 80 | if ($result === null) { 81 | return null; 82 | } 83 | 84 | return new DecodedOutput(new Response($result)); 85 | } 86 | 87 | /** 88 | * Get generator for iterate ProcessingEvent objects 89 | * 90 | * @return Generator 91 | */ 92 | public function getIterator(): Generator 93 | { 94 | $response = $this->getResponse(); 95 | 96 | $response->setEventDataTransformer( 97 | static fn ($eventData) => new ProcessingEvent(new Response($eventData)) 98 | ); 99 | 100 | yield from $response; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Entity/Processing/ResultOfSendMessage.php: -------------------------------------------------------------------------------- 1 | requireString('shard_block_id'); 22 | } 23 | 24 | /** 25 | * Get generator for iterate ProcessingEvent objects 26 | * 27 | * @return Generator 28 | */ 29 | public function getIterator(): Generator 30 | { 31 | $response = $this->getResponse(); 32 | 33 | $response->setEventDataTransformer( 34 | static fn ($eventData) => new ProcessingEvent(new Response($eventData)) 35 | ); 36 | 37 | yield from $response; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Entity/Tvm/AccountForExecutor.php: -------------------------------------------------------------------------------- 1 | type = $type; 36 | } 37 | 38 | /** 39 | * Non-existing account to run a creation internal message. 40 | * Should be used with skip_transaction_check = true if the message has no deploy data 41 | * since transactions on the uninitialized account are always aborted 42 | * 43 | * @return self 44 | */ 45 | public static function fromNone(): self 46 | { 47 | return new self(self::TYPE_NONE); 48 | } 49 | 50 | /** 51 | * Emulate uninitialized account to run deploy message 52 | * 53 | * @return self 54 | */ 55 | public static function fromUninit(): self 56 | { 57 | return new self(self::TYPE_UNINIT); 58 | } 59 | 60 | /** 61 | * Account state to run message 62 | * 63 | * @param string $boc Account BOC. Encoded as base64. 64 | * @param bool|null $unlimitedBalance Flag for running account with the unlimited balance. 65 | * Can be used to calculate transaction fees without balance check 66 | * @return self 67 | */ 68 | public static function fromAccount(string $boc, ?bool $unlimitedBalance = null): self 69 | { 70 | $instance = new self(self::TYPE_ACCOUNT); 71 | $instance->setBoc($boc); 72 | $instance->setUnlimitedBalance($unlimitedBalance); 73 | 74 | return $instance; 75 | } 76 | 77 | /** 78 | * Set account BOC. Encoded as base64. 79 | * 80 | * @param string $boc Account BOC. Encoded as base64. 81 | * @return self 82 | */ 83 | private function setBoc(string $boc): self 84 | { 85 | $this->boc = $boc; 86 | 87 | return $this; 88 | } 89 | 90 | /** 91 | * Set unlimited balance flag 92 | * 93 | * @param bool|null $unlimitedBalance Flag for running account with the unlimited balance. 94 | * Can be used to calculate transaction fees without balance check 95 | * @return self 96 | */ 97 | private function setUnlimitedBalance(?bool $unlimitedBalance): self 98 | { 99 | $this->unlimitedBalance = $unlimitedBalance; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @inheritDoc 106 | */ 107 | public function jsonSerialize(): array 108 | { 109 | if (!in_array($this->type, [self::TYPE_NONE, self::TYPE_UNINIT, self::TYPE_ACCOUNT], true)) { 110 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 111 | } 112 | 113 | $result['type'] = $this->type; 114 | 115 | if ($this->type === self::TYPE_ACCOUNT) { 116 | $result['boc'] = $this->boc; 117 | $result['unlimited_balance'] = $this->unlimitedBalance; 118 | } 119 | 120 | return $result; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Entity/Tvm/ExecutionOptions.php: -------------------------------------------------------------------------------- 1 | blockchainConfig = $blockchainConfig; 31 | $this->blockTime = $blockTime; 32 | $this->blockLt = $blockLt; 33 | $this->transactionLt = $transactionLt; 34 | } 35 | 36 | /** 37 | * @inheritDoc 38 | */ 39 | public function jsonSerialize(): array 40 | { 41 | return [ 42 | 'blockchain_config' => $this->blockchainConfig, 43 | 'block_time' => $this->blockTime, 44 | 'block_lt' => $this->blockLt, 45 | 'transaction_lt' => $this->transactionLt, 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Entity/Tvm/ResultOfRunExecutor.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | public function getTransaction(): array 22 | { 23 | return $this->requireArray('transaction'); 24 | } 25 | 26 | /** 27 | * Get updated account state BOC. Encoded as base64 28 | * 29 | * @return string 30 | */ 31 | public function getAccount(): string 32 | { 33 | return $this->requireString('account'); 34 | } 35 | 36 | /** 37 | * Get list of output messages BOCs. Encoded as base64 38 | * 39 | * @return array 40 | */ 41 | public function getOutMessages(): array 42 | { 43 | return $this->requireArray('out_messages'); 44 | } 45 | 46 | /** 47 | * Get transaction fees 48 | * 49 | * @return TransactionFees 50 | */ 51 | public function getTransactionFees(): TransactionFees 52 | { 53 | return new TransactionFees(new Response($this->requireArray('fees'))); 54 | } 55 | 56 | /** 57 | * Get optional decoded message bodies according to the optional abi parameter. 58 | * 59 | * @return DecodedOutput|null 60 | */ 61 | public function getDecoded(): ?DecodedOutput 62 | { 63 | return $this->getDecodedOutput(); 64 | } 65 | 66 | /** 67 | * Get optional decoded message bodies according to the optional abi parameter 68 | * 69 | * @return DecodedOutput|null 70 | */ 71 | public function getDecodedOutput(): ?DecodedOutput 72 | { 73 | $result = $this->getArray('decoded'); 74 | 75 | if ($result === null) { 76 | return null; 77 | } 78 | 79 | return new DecodedOutput(new Response($result)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Entity/Tvm/ResultOfRunGet.php: -------------------------------------------------------------------------------- 1 | requireData('output'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Tvm/ResultOfRunTvm.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | public function getOutMessages(): array 22 | { 23 | return $this->requireArray('out_messages'); 24 | } 25 | 26 | /** 27 | * Get updated account state BOC. Encoded as base64. 28 | * Attention! Only data in account state is updated. 29 | * 30 | * @return string 31 | */ 32 | public function getAccount(): string 33 | { 34 | return $this->requireString('account'); 35 | } 36 | 37 | /** 38 | * Get optional decoded message bodies according to the optional abi parameter. 39 | * 40 | * @return DecodedOutput|null 41 | */ 42 | public function getDecoded(): ?DecodedOutput 43 | { 44 | return $this->getDecodedOutput(); 45 | } 46 | 47 | /** 48 | * Get optional decoded message bodies according to the optional abi parameter 49 | * 50 | * @return DecodedOutput|null 51 | */ 52 | public function getDecodedOutput(): ?DecodedOutput 53 | { 54 | $result = $this->getArray('decoded'); 55 | 56 | if ($result === null) { 57 | return null; 58 | } 59 | 60 | return new DecodedOutput(new Response($result)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Entity/Tvm/TransactionFees.php: -------------------------------------------------------------------------------- 1 | requireInt('in_msg_fwd_fee'); 20 | } 21 | 22 | /** 23 | * @return int 24 | */ 25 | public function getStorageFee(): int 26 | { 27 | return $this->requireInt('storage_fee'); 28 | } 29 | 30 | /** 31 | * @return int 32 | */ 33 | public function getGasFee(): int 34 | { 35 | return $this->requireInt('gas_fee'); 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public function getOutMsgsFwdFee(): int 42 | { 43 | return $this->requireInt('out_msgs_fwd_fee'); 44 | } 45 | 46 | /** 47 | * @return int 48 | */ 49 | public function getTotalAccountFees(): int 50 | { 51 | return $this->requireInt('total_account_fees'); 52 | } 53 | 54 | /** 55 | * @return int 56 | */ 57 | public function getTotalOutput(): int 58 | { 59 | return $this->requireInt('total_output'); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Entity/Utils/AddressStringFormat.php: -------------------------------------------------------------------------------- 1 | type = $type; 40 | $this->url = $url; 41 | $this->test = $test; 42 | $this->bounce = $bounce; 43 | } 44 | 45 | /** 46 | * @return self 47 | */ 48 | public static function accountId(): self 49 | { 50 | return new self(self::TYPE_ACCOUNT_ID); 51 | } 52 | 53 | /** 54 | * @return self 55 | */ 56 | public static function hex(): self 57 | { 58 | return new self(self::TYPE_HEX); 59 | } 60 | 61 | /** 62 | * @param bool $url Is url 63 | * @param bool $test Is test 64 | * @param bool $bounce Is bounce 65 | * @return self 66 | */ 67 | public static function base64(bool $url = false, bool $test = false, bool $bounce = false): self 68 | { 69 | return new self(self::TYPE_BASE64, $url, $test, $bounce); 70 | } 71 | 72 | /** 73 | * @inheritDoc 74 | */ 75 | public function jsonSerialize(): array 76 | { 77 | if (!in_array($this->type, [self::TYPE_ACCOUNT_ID, self::TYPE_HEX, self::TYPE_BASE64], true)) { 78 | throw new DataException(sprintf('Unknown type %s.', $this->type)); 79 | } 80 | 81 | $result = [ 82 | 'type' => $this->type, 83 | ]; 84 | 85 | if ($this->type === self::TYPE_BASE64) { 86 | $result['url'] = $this->url; 87 | $result['test'] = $this->test; 88 | $result['bounce'] = $this->bounce; 89 | } 90 | 91 | return $result; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Entity/Utils/ResultOfCalcStorageFee.php: -------------------------------------------------------------------------------- 1 | requireString('fee'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Utils/ResultOfCompressZstd.php: -------------------------------------------------------------------------------- 1 | requireString('compressed'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Utils/ResultOfConvertAddress.php: -------------------------------------------------------------------------------- 1 | requireString('address'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Utils/ResultOfDecompressZstd.php: -------------------------------------------------------------------------------- 1 | requireString('decompressed'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Entity/Utils/ResultOfGetAddressType.php: -------------------------------------------------------------------------------- 1 | requireString('address_type'); 31 | } 32 | 33 | /** 34 | * Check: address type is AccountId 35 | * 36 | * @return bool 37 | */ 38 | public function isAccountId(): bool 39 | { 40 | return $this->getAddressType() === self::ACCOUNT_ID; 41 | } 42 | 43 | /** 44 | * Check: address type is Hex 45 | * 46 | * @return bool 47 | */ 48 | public function isHex(): bool 49 | { 50 | return $this->getAddressType() === self::HEX; 51 | } 52 | 53 | /** 54 | * Check: address type is Base64 55 | * 56 | * @return bool 57 | */ 58 | public function isBase64(): bool 59 | { 60 | return $this->getAddressType() === self::BASE64; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Exception/ConfigException.php: -------------------------------------------------------------------------------- 1 | getMessage(), 22 | $previous->getCode(), 23 | $previous 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Exception/FFIException.php: -------------------------------------------------------------------------------- 1 | getMessage(), 22 | $previous->getCode(), 23 | $previous 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Exception/LogicException.php: -------------------------------------------------------------------------------- 1 | */ 15 | private array $data; 16 | 17 | /** 18 | * @param array $result 19 | * @return self 20 | */ 21 | public static function create(array $result): self 22 | { 23 | $exception = new self( 24 | $result['message'] ?? 'Unknown TON SDK error', 25 | $result['code'] ?? 0 26 | ); 27 | $exception->data = $result['data'] ?? []; 28 | 29 | return $exception; 30 | } 31 | 32 | /** 33 | * Get extra data 34 | * 35 | * @return array 36 | */ 37 | public function getData(): array 38 | { 39 | return $this->data; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Exception/TonException.php: -------------------------------------------------------------------------------- 1 | libraryInterface = $libraryInterface; 26 | $this->libraryPath = $libraryPath; 27 | } 28 | 29 | /** 30 | * @param string $functionName 31 | * @param array $arguments 32 | * @return CData 33 | */ 34 | public function __call(string $functionName, array $arguments = []): FFI\CData 35 | { 36 | return $this->call($functionName, $arguments); 37 | } 38 | 39 | /** 40 | * @param string $functionName 41 | * @param array $arguments 42 | * @return CData 43 | */ 44 | public function call(string $functionName, array $arguments = []): FFI\CData 45 | { 46 | return $this->getFFI()->{$functionName}(...$arguments); 47 | } 48 | 49 | public function getFFI(): FFI 50 | { 51 | if ($this->ffi === null) { 52 | $this->ffi = FFI::cdef( 53 | $this->getLibraryInterface(), 54 | $this->getLibraryPath() 55 | ); 56 | } 57 | 58 | return $this->ffi; 59 | } 60 | 61 | public function getLibraryInterface(): string 62 | { 63 | return $this->libraryInterface; 64 | } 65 | 66 | public function getLibraryPath(): string 67 | { 68 | return $this->libraryPath; 69 | } 70 | 71 | /** 72 | * @param string $type 73 | * @param bool $owned 74 | * @return CData 75 | */ 76 | public function callNew(string $type, bool $owned = true): FFI\CData 77 | { 78 | $cData = $this->getFFI()->new($type, $owned); 79 | if ($cData === null) { 80 | throw new RuntimeException('Invalid data from call FFI::new().'); 81 | } 82 | 83 | return $cData; 84 | } 85 | 86 | /** 87 | * Creates a PHP string from a memory area 88 | * 89 | * @param CData $ptr The start of the memory area from which to create a string 90 | * @param int $size The number of bytes to copy to the string 91 | * @return string 92 | */ 93 | public function callString(CData $ptr, int $size): string 94 | { 95 | return FFI::string($ptr, $size); 96 | } 97 | 98 | /** 99 | * Copies one memory area to another 100 | * 101 | * @param CData $destination The start of the memory area to copy to 102 | * @param string $source The start of the memory area to copy from 103 | * @param int $size The number of bytes to copy 104 | */ 105 | public function callMemCpy(CData $destination, string $source, int $size): void 106 | { 107 | FFI::memcpy($destination, $source, $size); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/Handler/Response.php: -------------------------------------------------------------------------------- 1 | 17 | */ 18 | class Response implements IteratorAggregate 19 | { 20 | private bool $dataFetched; 21 | 22 | private bool $eventsFinished; 23 | 24 | /** @var array */ 25 | private array $responseData; 26 | 27 | /** @var array */ 28 | private array $eventData = []; 29 | 30 | private ?Closure $eventDataTransformer = null; 31 | 32 | /** 33 | * @param array $responseData 34 | * @param bool $dataFetched 35 | * @param bool $eventsFinished 36 | */ 37 | public function __construct(array $responseData = [], bool $dataFetched = true, bool $eventsFinished = true) 38 | { 39 | $this->responseData = $responseData; 40 | $this->dataFetched = $dataFetched; 41 | $this->eventsFinished = $eventsFinished; 42 | } 43 | 44 | /** 45 | * @param array $responseData 46 | * @return self 47 | */ 48 | public function setResponseData(array $responseData): self 49 | { 50 | $this->responseData = $responseData; 51 | $this->dataFetched = true; 52 | 53 | return $this; 54 | } 55 | 56 | /** 57 | * @return array 58 | */ 59 | public function getResponseData(): array 60 | { 61 | if ($this->dataFetched) { 62 | return $this->responseData; 63 | } 64 | 65 | // @phpstan-ignore-next-line 66 | while (!$this->dataFetched) { 67 | usleep(500_000); 68 | } 69 | 70 | // @phpstan-ignore-next-line 71 | return $this->responseData; 72 | } 73 | 74 | public function setEventDataTransformer(callable $eventTransformer): void 75 | { 76 | $this->eventDataTransformer = Closure::fromCallable($eventTransformer); 77 | } 78 | 79 | public function finish(): void 80 | { 81 | $this->eventsFinished = true; 82 | } 83 | 84 | public function isEventsFinished(): bool 85 | { 86 | return $this->eventsFinished; 87 | } 88 | 89 | /** 90 | * @param array $eventData 91 | */ 92 | public function __invoke(array $eventData): void 93 | { 94 | if ($this->eventsFinished) { 95 | throw new LogicException('Event data cannot be transferred to a completed Response object.'); 96 | } 97 | 98 | $this->eventData[] = $eventData; 99 | } 100 | 101 | /** 102 | * @return Generator 103 | */ 104 | public function getIterator(): Generator 105 | { 106 | for (; ;) { 107 | while ($data = array_shift($this->eventData)) { 108 | if ($this->eventDataTransformer === null) { 109 | yield $data; 110 | } else { 111 | yield call_user_func($this->eventDataTransformer, $data); 112 | } 113 | } 114 | 115 | if ($this->isEventsFinished()) { 116 | break; 117 | } 118 | 119 | usleep(500_000); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Module.php: -------------------------------------------------------------------------------- 1 | tonClient->request( 33 | 'processing.send_message', 34 | [ 35 | 'message' => $message, 36 | 'send_events' => $sendEvents, 37 | 'abi' => $abi, 38 | ] 39 | )->wait() 40 | ); 41 | } 42 | 43 | /** 44 | * Performs monitoring of the network for the result transaction of the external inbound message processing. 45 | * 46 | * @param string $message Message BOC. Encoded with base64 47 | * @param string $shardBlockId The last generated block id of the destination account shard before the message was sent 48 | * @param bool $sendEvents Flag that enables / disables intermediate events 49 | * @param AbiType|null $abi Optional ABI for decoding the transaction result 50 | * @return ResultOfProcessMessage 51 | * @throws TonException 52 | */ 53 | public function waitForTransaction( 54 | string $message, 55 | string $shardBlockId, 56 | bool $sendEvents, 57 | ?AbiType $abi = null 58 | ): ResultOfProcessMessage { 59 | return new ResultOfProcessMessage( 60 | $this->tonClient->request( 61 | 'processing.wait_for_transaction', 62 | [ 63 | 'message' => $message, 64 | 'shard_block_id' => $shardBlockId, 65 | 'send_events' => $sendEvents, 66 | 'abi' => $abi, 67 | ] 68 | )->wait() 69 | ); 70 | } 71 | 72 | /** 73 | * Creates message, sends it to the network and monitors its processing 74 | * 75 | * @param AbiType $abi Contract ABI 76 | * @param Signer $signer Signing parameters 77 | * @param DeploySet|null $deploySet Deploy parameters 78 | * @param CallSet|null $callSet Function call parameters 79 | * @param string|null $address Target address the message will be sent to 80 | * @param int|null $processingTryIndex Processing try index 81 | * @param bool $sendEvents Flag for requesting events sending 82 | * @return ResultOfProcessMessage 83 | * @throws TonException 84 | */ 85 | public function processMessage( 86 | AbiType $abi, 87 | Signer $signer, 88 | ?DeploySet $deploySet = null, 89 | ?CallSet $callSet = null, 90 | ?string $address = null, 91 | ?int $processingTryIndex = null, 92 | bool $sendEvents = false 93 | ): ResultOfProcessMessage { 94 | return new ResultOfProcessMessage( 95 | $this->tonClient->request( 96 | 'processing.process_message', 97 | [ 98 | 'message_encode_params' => [ 99 | 'abi' => $abi, 100 | 'signer' => $signer, 101 | 'deploy_set' => $deploySet, 102 | 'call_set' => $callSet, 103 | 'address' => $address, 104 | 'processing_try_index' => $processingTryIndex, 105 | ], 106 | 'send_events' => $sendEvents, 107 | ] 108 | )->wait() 109 | ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Tvm.php: -------------------------------------------------------------------------------- 1 | tonClient->request( 45 | 'tvm.run_executor', 46 | [ 47 | 'message' => $message, 48 | 'account' => $accountForExecutor, 49 | 'execution_options' => $executionOptions, 50 | 'abi' => $abi, 51 | 'skip_transaction_check' => $skipTransactionCheck, 52 | 'return_updated_account' => $returnUpdatedAccount, 53 | 'boc_cache' => $cacheType, 54 | ] 55 | )->wait() 56 | ); 57 | } 58 | 59 | /** 60 | * Run tvm 61 | * 62 | * @param string $message Input message BOC. Must be encoded as base64 63 | * @param string $account Account BOC. Must be encoded as base64 64 | * @param ExecutionOptions|null $executionOptions Execution options 65 | * @param AbiType|null $abi Contract ABI for decoding output messages 66 | * @param bool $returnUpdatedAccount Return updated account flag (empty string is returned if the flag is false) 67 | * @param CacheType|null $cacheType Cache type to put the result (the BOC itself returned if no cache type provided) 68 | * @return ResultOfRunTvm 69 | * @throws TonException 70 | */ 71 | public function runTvm( 72 | string $message, 73 | string $account, 74 | ?ExecutionOptions $executionOptions = null, 75 | ?AbiType $abi = null, 76 | bool $returnUpdatedAccount = false, 77 | ?CacheType $cacheType = null 78 | ): ResultOfRunTvm { 79 | return new ResultOfRunTvm( 80 | $this->tonClient->request( 81 | 'tvm.run_tvm', 82 | [ 83 | 'message' => $message, 84 | 'account' => $account, 85 | 'execution_options' => $executionOptions, 86 | 'abi' => $abi, 87 | 'return_updated_account' => $returnUpdatedAccount, 88 | 'boc_cache' => $cacheType, 89 | ] 90 | )->wait() 91 | ); 92 | } 93 | 94 | /** 95 | * Executes get method and returns data from TVM stack 96 | * 97 | * @param string $account Account BOC in base64 98 | * @param string $functionName Function name 99 | * @param ExecutionOptions|null $executionOptions Execution options 100 | * @param mixed $input Input parameters 101 | * @param bool $tupleListAsArray Convert lists based on nested tuples in the result into plain arrays. 102 | * @return ResultOfRunGet 103 | * @throws TonException 104 | */ 105 | public function runGet( 106 | string $account, 107 | string $functionName, 108 | ?ExecutionOptions $executionOptions = null, 109 | $input = null, 110 | $tupleListAsArray = false 111 | ): ResultOfRunGet { 112 | return new ResultOfRunGet( 113 | $this->tonClient->request( 114 | 'tvm.run_get', 115 | [ 116 | 'account' => $account, 117 | 'function_name' => $functionName, 118 | 'execution_options' => $executionOptions, 119 | 'input' => $input, 120 | 'tuple_list_as_array' => $tupleListAsArray, 121 | ] 122 | )->wait() 123 | ); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /tests/Integration/AbstractModuleTest.php: -------------------------------------------------------------------------------- 1 | tonClient = TonClient::createDefault(); 47 | $this->processing = $this->tonClient->getProcessing(); 48 | $this->crypto = $this->tonClient->getCrypto(); 49 | $this->abi = $this->tonClient->getAbi(); 50 | $this->boc = $this->tonClient->getBoc(); 51 | $this->net = $this->tonClient->getNet(); 52 | $this->utils = $this->tonClient->getUtils(); 53 | $this->tvm = $this->tonClient->getTvm(); 54 | $this->dataProvider = new DataProvider($this->tonClient); 55 | $this->eventSaver = new EventSaver(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Integration/Data/EventSaver.php: -------------------------------------------------------------------------------- 1 | flock(LOCK_EX | LOCK_NB); 43 | 44 | if (!$locked) { 45 | throw new RuntimeException(sprintf('Can\'t acquire lock for file %s', $path)); 46 | } 47 | 48 | $file->ftruncate(0); 49 | $file->fseek(0); 50 | 51 | while (true) { 52 | $line = yield; 53 | $file->fwrite(json_encode($line, JSON_PRETTY_PRINT)); 54 | $file->fwrite(PHP_EOL); 55 | $file->fwrite(PHP_EOL); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Integration/Data/Events.abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "ABI version": 2, 3 | "header": [ 4 | "pubkey", 5 | "time", 6 | "expire" 7 | ], 8 | "functions": [ 9 | { 10 | "name": "emitValue", 11 | "inputs": [ 12 | { 13 | "name": "id", 14 | "type": "uint256" 15 | } 16 | ], 17 | "outputs": [ 18 | ] 19 | }, 20 | { 21 | "name": "returnValue", 22 | "inputs": [ 23 | { 24 | "name": "id", 25 | "type": "uint256" 26 | } 27 | ], 28 | "outputs": [ 29 | { 30 | "name": "value0", 31 | "type": "uint256" 32 | } 33 | ] 34 | }, 35 | { 36 | "name": "sendAllMoney", 37 | "inputs": [ 38 | { 39 | "name": "dest_addr", 40 | "type": "address" 41 | } 42 | ], 43 | "outputs": [ 44 | ] 45 | }, 46 | { 47 | "name": "constructor", 48 | "inputs": [ 49 | ], 50 | "outputs": [ 51 | ] 52 | } 53 | ], 54 | "data": [ 55 | ], 56 | "events": [ 57 | { 58 | "name": "EventThrown", 59 | "inputs": [ 60 | { 61 | "name": "id", 62 | "type": "uint256" 63 | } 64 | ], 65 | "outputs": [ 66 | ] 67 | } 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /tests/Integration/Data/Events.tvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/Events.tvc -------------------------------------------------------------------------------- /tests/Integration/Data/Giver.abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "ABI version": 2, 3 | "header": [ 4 | "time" 5 | ], 6 | "functions": [ 7 | { 8 | "name": "constructor", 9 | "inputs": [ 10 | ], 11 | "outputs": [ 12 | ] 13 | }, 14 | { 15 | "name": "grant", 16 | "inputs": [ 17 | { 18 | "name": "dest", 19 | "type": "address" 20 | } 21 | ], 22 | "outputs": [ 23 | ] 24 | } 25 | ], 26 | "data": [ 27 | ], 28 | "events": [ 29 | ] 30 | } -------------------------------------------------------------------------------- /tests/Integration/Data/Hello.abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "ABI version": 2, 3 | "header": [ 4 | "time", 5 | "expire" 6 | ], 7 | "functions": [ 8 | { 9 | "name": "constructor", 10 | "inputs": [ 11 | ], 12 | "outputs": [ 13 | ] 14 | }, 15 | { 16 | "name": "touch", 17 | "inputs": [ 18 | ], 19 | "outputs": [ 20 | ] 21 | }, 22 | { 23 | "name": "sayHello", 24 | "inputs": [ 25 | ], 26 | "outputs": [ 27 | { 28 | "name": "value0", 29 | "type": "uint32" 30 | } 31 | ] 32 | }, 33 | { 34 | "name": "sendAllMoney", 35 | "inputs": [ 36 | { 37 | "name": "dest_addr", 38 | "type": "address" 39 | } 40 | ], 41 | "outputs": [ 42 | ] 43 | } 44 | ], 45 | "events": [ 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /tests/Integration/Data/Hello.tvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/Hello.tvc -------------------------------------------------------------------------------- /tests/Integration/Data/Subscription.abi.json: -------------------------------------------------------------------------------- 1 | { 2 | "ABI version": 2, 3 | "header": [ 4 | "time", 5 | "expire" 6 | ], 7 | "functions": [ 8 | { 9 | "name": "constructor", 10 | "inputs": [ 11 | { 12 | "name": "wallet", 13 | "type": "address" 14 | } 15 | ], 16 | "outputs": [ 17 | ] 18 | }, 19 | { 20 | "name": "getWallet", 21 | "inputs": [ 22 | ], 23 | "outputs": [ 24 | { 25 | "name": "value0", 26 | "type": "address" 27 | } 28 | ] 29 | }, 30 | { 31 | "name": "getSubscription", 32 | "inputs": [ 33 | { 34 | "name": "subscriptionId", 35 | "type": "uint256" 36 | } 37 | ], 38 | "outputs": [ 39 | { 40 | "components": [ 41 | { 42 | "name": "pubkey", 43 | "type": "uint256" 44 | }, 45 | { 46 | "name": "to", 47 | "type": "address" 48 | }, 49 | { 50 | "name": "value", 51 | "type": "uint64" 52 | }, 53 | { 54 | "name": "period", 55 | "type": "uint32" 56 | }, 57 | { 58 | "name": "start", 59 | "type": "uint32" 60 | }, 61 | { 62 | "name": "status", 63 | "type": "uint8" 64 | } 65 | ], 66 | "name": "value0", 67 | "type": "tuple" 68 | } 69 | ] 70 | }, 71 | { 72 | "name": "subscribe", 73 | "inputs": [ 74 | { 75 | "name": "subscriptionId", 76 | "type": "uint256" 77 | }, 78 | { 79 | "name": "pubkey", 80 | "type": "uint256" 81 | }, 82 | { 83 | "name": "to", 84 | "type": "address" 85 | }, 86 | { 87 | "name": "value", 88 | "type": "uint64" 89 | }, 90 | { 91 | "name": "period", 92 | "type": "uint32" 93 | } 94 | ], 95 | "outputs": [ 96 | ] 97 | }, 98 | { 99 | "name": "cancel", 100 | "inputs": [ 101 | { 102 | "name": "subscriptionId", 103 | "type": "uint256" 104 | } 105 | ], 106 | "outputs": [ 107 | ] 108 | }, 109 | { 110 | "name": "executeSubscription", 111 | "inputs": [ 112 | { 113 | "name": "subscriptionId", 114 | "type": "uint256" 115 | } 116 | ], 117 | "outputs": [ 118 | ] 119 | }, 120 | { 121 | "name": "sendAllMoney", 122 | "inputs": [ 123 | { 124 | "name": "dest_addr", 125 | "type": "address" 126 | } 127 | ], 128 | "outputs": [ 129 | ] 130 | } 131 | ], 132 | "events": [ 133 | ] 134 | } 135 | -------------------------------------------------------------------------------- /tests/Integration/Data/Subscription.tvc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/Subscription.tvc -------------------------------------------------------------------------------- /tests/Integration/Data/aes.iv.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/aes.iv.bin -------------------------------------------------------------------------------- /tests/Integration/Data/aes.plaintext.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/aes.plaintext.bin -------------------------------------------------------------------------------- /tests/Integration/Data/aes.plaintext.for.padding.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/aes.plaintext.for.padding.bin -------------------------------------------------------------------------------- /tests/Integration/Data/aes128.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/aes128.key.bin -------------------------------------------------------------------------------- /tests/Integration/Data/aes256.key.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/aes256.key.bin -------------------------------------------------------------------------------- /tests/Integration/Data/cbc-aes128.ciphertext.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/cbc-aes128.ciphertext.bin -------------------------------------------------------------------------------- /tests/Integration/Data/cbc-aes256.ciphertext.padded.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/Data/cbc-aes256.ciphertext.padded.bin -------------------------------------------------------------------------------- /tests/Integration/TonClientTest.php: -------------------------------------------------------------------------------- 1 | '1.22.0' 26 | ] 27 | ) 28 | ); 29 | 30 | self::assertEquals($expected, $this->tonClient->version()); 31 | } 32 | 33 | /** 34 | * @covers ::buildInfo 35 | */ 36 | public function testBuildInfo(): void 37 | { 38 | $resultOfBuildInfo = $this->tonClient->buildInfo(); 39 | 40 | self::assertGreaterThanOrEqual(0, $resultOfBuildInfo->getBuildNumber()); 41 | self::assertCount(0, $resultOfBuildInfo->getDependencies()); 42 | } 43 | 44 | /** 45 | * @covers ::getApiReference 46 | */ 47 | public function testGetApiReference(): void 48 | { 49 | $resultOfGetApiReference = $this->tonClient->getApiReference(); 50 | 51 | self::assertEquals('1.22.0', $resultOfGetApiReference->getApi()['version']); 52 | self::assertCount(9, $resultOfGetApiReference->getApi()['modules']); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Integration/artifacts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/extraton/php-ton-client/18e1b75cd427a43c9d55287b7baa61d35e13a24b/tests/Integration/artifacts/.gitkeep -------------------------------------------------------------------------------- /tests/Unit/AbstractModuleTest.php: -------------------------------------------------------------------------------- 1 | mockTonClient = $this->getMockBuilder(TonClient::class) 26 | ->disableOriginalConstructor() 27 | ->onlyMethods( 28 | [ 29 | 'request' 30 | ] 31 | ) 32 | ->getMock(); 33 | 34 | $this->mockPromise = $this->getMockBuilder(Promise::class) 35 | ->disableOriginalConstructor() 36 | ->onlyMethods( 37 | [ 38 | 'wait' 39 | ] 40 | ) 41 | ->getMock(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Unit/Entity/ResultOfConvertAddressTest.php: -------------------------------------------------------------------------------- 1 | $address = uniqid(microtime(), true), 26 | ]; 27 | 28 | $result = new ResultOfConvertAddress(new Response($data)); 29 | 30 | self::assertEquals( 31 | $address, 32 | $result->getAddress() 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Unit/TonClientTest.php: -------------------------------------------------------------------------------- 1 | mockTonClient = $this->getMockBuilder(TonClient::class) 35 | ->disableOriginalConstructor() 36 | ->onlyMethods( 37 | [ 38 | 'request' 39 | ] 40 | ) 41 | ->getMock(); 42 | 43 | $this->mockPromise = $this->getMockBuilder(Promise::class) 44 | ->disableOriginalConstructor() 45 | ->onlyMethods( 46 | [ 47 | 'wait' 48 | ] 49 | ) 50 | ->getMock(); 51 | } 52 | 53 | /** 54 | * @covers ::version 55 | */ 56 | public function testVersion(): void 57 | { 58 | $response = new Response( 59 | [ 60 | uniqid(microtime(), true) 61 | ] 62 | ); 63 | 64 | $this->mockPromise->expects(self::once()) 65 | ->method('wait') 66 | ->with() 67 | ->willReturn($response); 68 | 69 | $this->mockTonClient->expects(self::once()) 70 | ->method('request') 71 | ->with('client.version', []) 72 | ->willReturn($this->mockPromise); 73 | 74 | $expected = new ResultOfVersion($response); 75 | 76 | self::assertEquals($expected, $this->mockTonClient->version()); 77 | } 78 | 79 | /** 80 | * @covers ::buildInfo 81 | */ 82 | public function testBuildInfo(): void 83 | { 84 | $response = new Response( 85 | [ 86 | uniqid(microtime(), true) 87 | ] 88 | ); 89 | 90 | $this->mockPromise->expects(self::once()) 91 | ->method('wait') 92 | ->with() 93 | ->willReturn($response); 94 | 95 | $this->mockTonClient->expects(self::once()) 96 | ->method('request') 97 | ->with('client.build_info', []) 98 | ->willReturn($this->mockPromise); 99 | 100 | $expected = new ResultOfBuildInfo($response); 101 | 102 | self::assertEquals($expected, $this->mockTonClient->buildInfo()); 103 | } 104 | 105 | /** 106 | * @covers ::getApiReference 107 | */ 108 | public function testGetApiReference(): void 109 | { 110 | $response = new Response( 111 | [ 112 | uniqid(microtime(), true) 113 | ] 114 | ); 115 | 116 | $this->mockPromise->expects(self::once()) 117 | ->method('wait') 118 | ->with() 119 | ->willReturn($response); 120 | 121 | $this->mockTonClient->expects(self::once()) 122 | ->method('request') 123 | ->with('client.get_api_reference', []) 124 | ->willReturn($this->mockPromise); 125 | 126 | $expected = new ResultOfGetApiReference($response); 127 | 128 | self::assertEquals($expected, $this->mockTonClient->getApiReference()); 129 | } 130 | } 131 | --------------------------------------------------------------------------------