From 87e3492c09aea4cb9a84bed675d91f07556a0cf7 Mon Sep 17 00:00:00 2001 From: Roman Zaycev Date: Mon, 22 Jul 2024 21:59:11 +0700 Subject: [PATCH] `WalletV5R1` renamed to `WalletV5Beta` --- composer.json | 2 +- examples/jettons/usdt-transfer.php | 4 ++-- examples/wallets/w5-mass-transfer.php | 4 ++-- .../V5/{WalletV5R1.php => WalletV5.php} | 22 +++++-------------- .../Ton/Contracts/Wallets/V5/WalletV5Beta.php | 16 ++++++++++++++ src/Olifanton/Ton/Reflection/Wallets.php | 6 ++--- ...alletV5R1Test.php => WalletV5BetaTest.php} | 8 +++---- .../Ton/Tests/Reflection/WalletsTest.php | 4 ++-- 8 files changed, 36 insertions(+), 30 deletions(-) rename src/Olifanton/Ton/Contracts/Wallets/V5/{WalletV5R1.php => WalletV5.php} (91%) create mode 100644 src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5Beta.php rename tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/{WalletV5R1Test.php => WalletV5BetaTest.php} (92%) diff --git a/composer.json b/composer.json index 39ce646..1df3d0f 100644 --- a/composer.json +++ b/composer.json @@ -52,7 +52,7 @@ "http-interop/http-factory-guzzle": "^1.2", "jetbrains/phpstorm-attributes": "^1.0", "mockery/mockery": "^1.5", - "overtrue/phplint": "^9.0", + "overtrue/phplint": "9.3.1", "php-http/guzzle7-adapter": "^1.0", "phpstan/phpstan": "^1.9", "phpunit/phpunit": "^9.5", diff --git a/examples/jettons/usdt-transfer.php b/examples/jettons/usdt-transfer.php index 3c8cfbd..d6fd1d9 100644 --- a/examples/jettons/usdt-transfer.php +++ b/examples/jettons/usdt-transfer.php @@ -13,7 +13,7 @@ use Olifanton\Ton\Contracts\Wallets\Transfer; use Olifanton\Ton\Contracts\Wallets\TransferOptions; use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Options; -use Olifanton\Ton\Contracts\Wallets\V5\WalletV5R1; +use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Beta; use Olifanton\Ton\SendMode; define("MAIN_NET", true); @@ -27,7 +27,7 @@ $usdtAmount = "0.1"; define("USDT_JETTON_MINTER_ADDR", "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"); // https://tonviewer.com/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs -$wallet = new WalletV5R1( // W5, why not? :] +$wallet = new WalletV5Beta( // W5, why not? :] new WalletV5Options( publicKey: $kp->publicKey, ), diff --git a/examples/wallets/w5-mass-transfer.php b/examples/wallets/w5-mass-transfer.php index be6429c..f038d24 100644 --- a/examples/wallets/w5-mass-transfer.php +++ b/examples/wallets/w5-mass-transfer.php @@ -6,7 +6,7 @@ use Olifanton\Interop\Units; use Olifanton\Ton\Contracts\Wallets\Transfer; use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Options; -use Olifanton\Ton\Contracts\Wallets\V5\WalletV5R1; +use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Beta; use Olifanton\Ton\Contracts\Wallets\V5\WalletV5TransferOptions; use Olifanton\Ton\SendMode; @@ -14,7 +14,7 @@ global $kp, $transport, $logger; -$wallet = new WalletV5R1( +$wallet = new WalletV5Beta( new WalletV5Options( $kp->publicKey, ), diff --git a/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5R1.php b/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5.php similarity index 91% rename from src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5R1.php rename to src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5.php index 73a0499..c4d8e9c 100644 --- a/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5R1.php +++ b/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5.php @@ -21,7 +21,7 @@ use Olifanton\Ton\Contracts\Wallets\Wallet; use Olifanton\Ton\Contracts\Wallets\WalletId; -class WalletV5R1 extends AbstractWallet implements Wallet +abstract class WalletV5 extends AbstractWallet implements Wallet { protected WalletId $walletId; @@ -41,16 +41,6 @@ public function __construct(protected readonly WalletV5Options $options) } } - protected static function getHexCodeString(): string - { - return "b5ee9c7241010101002300084202e4cf3b2f4c6d6a61ea0f2b5447d266785b26af3637db2deee6bcd1aa826f34120dcd8e11"; // O ma G! - } - - public static function getName(): string - { - return "v5r1"; - } - protected function createData(): Cell { try { @@ -62,7 +52,7 @@ protected function createData(): Cell ->writeBit(0); // Empty plugins dict return $b->cell(); - // @codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } catch (BitStringException | CellException $e) { throw new WalletException("Wallet data creation error: " . $e->getMessage(), $e->getCode(), $e); } @@ -122,7 +112,7 @@ public function createTransferMessage(array $transfers, TransferOptions|WalletV5 ->writeRef( (new Builder())->writeSlice($this->createTransfersCell($transfers))->cell(), ); - // @codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } catch (\Throwable $e) { throw new WalletException( "Signing message construction error: " . $e->getMessage(), @@ -146,7 +136,7 @@ public function createTransferMessage(array $transfers, TransferOptions|WalletV5 $seqno === 0 ? $this->getStateInit()->cell() : null, ), ))->tailSigned(true); - // @codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } catch (MessageException|ContractException $e) { throw new WalletException( $e->getMessage(), @@ -157,7 +147,7 @@ public function createTransferMessage(array $transfers, TransferOptions|WalletV5 // @codeCoverageIgnoreEnd } - public function createSigningMessage(int $seqno, ): Cell + public function createSigningMessage(int $seqno): Cell { throw new \DomainException("Not applicable"); } @@ -170,7 +160,7 @@ public function createSigningMessage(int $seqno, ): Cell * @throws ContractException * @throws MessageException */ - private function createTransfersCell(array $transfers): Slice + protected function createTransfersCell(array $transfers): Slice { return array_reduce($transfers, function (Cell $cell, Transfer $transfer) { $body = is_string($transfer->payload) diff --git a/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5Beta.php b/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5Beta.php new file mode 100644 index 0000000..3c05418 --- /dev/null +++ b/src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5Beta.php @@ -0,0 +1,16 @@ +skipBits(33); // seqno $network = $slice->loadInt(32)->toInt(); $wc = $slice->loadInt(8)->toInt(); @@ -113,7 +113,7 @@ public static function extractPublicData(StateInit $stateInit): AddressPubkeyPai walletId: new WalletsSmc\WalletId( networkId: Network::from($network), subwalletId: $subwalletId, - walletVersion: array_flip(WalletsSmc\V5\WalletV5R1::WALLET_VERSIONS_MAP)[$walletVersionId] ?? "v5", + walletVersion: array_flip(WalletsSmc\V5\WalletV5Beta::WALLET_VERSIONS_MAP)[$walletVersionId] ?? "v5", workchain: $wc, ), workchain: $wc, @@ -156,7 +156,7 @@ protected static function ensureHashes(): array WalletsSmc\V4\WalletV4R1::class, WalletsSmc\V4\WalletV4R2::class, - WalletsSmc\V5\WalletV5R1::class, + WalletsSmc\V5\WalletV5Beta::class, ]; foreach ($wallets as $walletClass) { diff --git a/tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5R1Test.php b/tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5BetaTest.php similarity index 92% rename from tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5R1Test.php rename to tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5BetaTest.php index f5f0ad7..3007092 100644 --- a/tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5R1Test.php +++ b/tests/Olifanton/Ton/Tests/Contracts/Wallets/V5/WalletV5BetaTest.php @@ -7,14 +7,14 @@ use Olifanton\Mnemonic\TonMnemonic; use Olifanton\Ton\Contracts\Wallets\Transfer; use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Options; -use Olifanton\Ton\Contracts\Wallets\V5\WalletV5R1; +use Olifanton\Ton\Contracts\Wallets\V5\WalletV5Beta; use Olifanton\Ton\Contracts\Wallets\V5\WalletV5TransferOptions; use Olifanton\Ton\Helpers\KeyPair; use Olifanton\Ton\SendMode; use Olifanton\Ton\Transports\NullTransport\NullTransport; use PHPUnit\Framework\TestCase; -class WalletV5R1Test extends TestCase +class WalletV5BetaTest extends TestCase { /** * @throws \Throwable @@ -25,7 +25,7 @@ public function testGetAddress(): void $words = "point august abandon hamster pilot cousin rug bargain century rate rule armed host rate balcony ordinary advance forward unknown border tip art luxury return"; $kp = TonMnemonic::mnemonicToKeyPair(explode(" ", $words)); - $instance = new WalletV5R1( + $instance = new WalletV5Beta( new WalletV5Options( publicKey: $kp->publicKey, ), @@ -43,7 +43,7 @@ public function testGetAddress(): void public function testCreateTransferMessage(): void { $kp = KeyPair::random(); - $instance = new WalletV5R1( + $instance = new WalletV5Beta( new WalletV5Options( publicKey: $kp->publicKey, ), diff --git a/tests/Olifanton/Ton/Tests/Reflection/WalletsTest.php b/tests/Olifanton/Ton/Tests/Reflection/WalletsTest.php index 2939b3e..de7e5f5 100644 --- a/tests/Olifanton/Ton/Tests/Reflection/WalletsTest.php +++ b/tests/Olifanton/Ton/Tests/Reflection/WalletsTest.php @@ -176,9 +176,9 @@ private function getSyntheticCases(\Olifanton\Interop\KeyPair $kp): array }, ], - WalletsSmc\V5\WalletV5R1::class => [ + WalletsSmc\V5\WalletV5Beta::class => [ "factory" => static function () use ($kp): StateInit { - return (new WalletsSmc\V5\WalletV5R1( + return (new WalletsSmc\V5\WalletV5Beta( new WalletsSmc\V5\WalletV5Options( publicKey: $kp->publicKey, ),