Skip to content

Commit

Permalink
WalletV5R1 renamed to WalletV5Beta
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzaycev committed Jul 22, 2024
1 parent b2c4049 commit 87e3492
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/jettons/usdt-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
),
Expand Down
4 changes: 2 additions & 2 deletions examples/wallets/w5-mass-transfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
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;

require dirname(__DIR__) . "/common.php";

global $kp, $transport, $logger;

$wallet = new WalletV5R1(
$wallet = new WalletV5Beta(
new WalletV5Options(
$kp->publicKey,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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);
}
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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");
}
Expand All @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions src/Olifanton/Ton/Contracts/Wallets/V5/WalletV5Beta.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Olifanton\Ton\Contracts\Wallets\V5;

class WalletV5Beta extends WalletV5
{
protected static function getHexCodeString(): string
{
return "b5ee9c7201010101002300084202e4cf3b2f4c6d6a61ea0f2b5447d266785b26af3637db2deee6bcd1aa826f3412"; // O ma G!
}

public static function getName(): string
{
return "v5_beta";
}
}
6 changes: 3 additions & 3 deletions src/Olifanton/Ton/Reflection/Wallets.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public static function extractPublicData(StateInit $stateInit): AddressPubkeyPai
$instance = new $walletClass($options);
break;

case WalletsSmc\V5\WalletV5R1::class:
case WalletsSmc\V5\WalletV5Beta::class:
$slice->skipBits(33); // seqno
$network = $slice->loadInt(32)->toInt();
$wc = $slice->loadInt(8)->toInt();
Expand All @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
),
Expand All @@ -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,
),
Expand Down
4 changes: 2 additions & 2 deletions tests/Olifanton/Ton/Tests/Reflection/WalletsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down

0 comments on commit 87e3492

Please sign in to comment.