Skip to content

Commit

Permalink
Fix #2 Close #3
Browse files Browse the repository at this point in the history
- Enable `phpstan` checks for examples
- Fixed ContractOptions in custom contract constructor
- Autodeploy wallet in Deployer
  • Loading branch information
romanzaycev committed May 13, 2023
1 parent 1a36412 commit e68575a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TONCENTER_API_KEY=%TONCENTER_API_KEY%
TONCENTER_API_KEY_MAINNET=%TONCENTER_API_KEY_MAINNET%
TEST_V3R2_WALLET_WORDS="%TEST_V3R2_WALLET_WORDS%"
JSONBIN_API_KEY=%JSONBIN_API_KEY%
5 changes: 3 additions & 2 deletions examples/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
Psr17FactoryDiscovery::findStreamFactory(),
);

$isMainnet = (defined("MAIN_NET") && MAIN_NET); // @phpstan-ignore-line
$toncenter = new ToncenterHttpV2Client(
$httpClient,
new ClientOptions(
(defined("MAIN_NET") && MAIN_NET) ? "https://toncenter.com/api/v2" : "https://testnet.toncenter.com/api/v2",
$_ENV["TONCENTER_API_KEY"],
$isMainnet ? "https://toncenter.com/api/v2" : "https://testnet.toncenter.com/api/v2",
$isMainnet ? $_ENV["TONCENTER_API_KEY_MAINNET"] : $_ENV["TONCENTER_API_KEY"],
),
);
$transport = new ToncenterTransport($toncenter);
Expand Down
3 changes: 1 addition & 2 deletions examples/deployer/deploy-custom-contract.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
)
);

$exampleContractPk = \Olifanton\Ton\Helpers\KeyPair::random();
$exampleContract = new class(new ContractOptions(publicKey: $exampleContractPk->publicKey)) extends AbstractContract
$exampleContract = new class(new ContractOptions()) extends AbstractContract
{
protected function createCode(): Cell
{
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ parameters:
paths:
- src
- tests
- examples
tmpDir: build
ignoreErrors:
- message: '#has an uninitialized readonly property#'
Expand Down
3 changes: 3 additions & 0 deletions src/Olifanton/Ton/Contracts/Wallets/TransferOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class TransferOptions
{
/**
* @param int|null $seqno Seqno. Set `0` to initialize wallet when making transfers
*/
public function __construct(
public readonly ?int $seqno = null,
public readonly int $timeout = 60,
Expand Down
3 changes: 2 additions & 1 deletion src/Olifanton/Ton/Contracts/Wallets/Wallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use Olifanton\Interop\Boc\Cell;
use Olifanton\Ton\Contract;
use Olifanton\Ton\Contracts\Interfaces\Deployable;
use Olifanton\Ton\Contracts\Messages\ExternalMessage;
use Olifanton\Ton\Contracts\Wallets\Exceptions\WalletException;
use Olifanton\Ton\Transport;
use Olifanton\TypedArrays\Uint8Array;

interface Wallet extends Contract
interface Wallet extends Contract, Deployable
{
/**
* @param Transfer[] $transfers
Expand Down
5 changes: 4 additions & 1 deletion src/Olifanton/Ton/Deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function deploy(DeployOptions $options, Deployable $deployable): void
$externalMessage = $this->createExternal(
$options,
$deployable,
$options->deployerWallet->seqno($this->transport),
(int)$options->deployerWallet->seqno($this->transport),
);
} catch (MessageException | ContractException | BitStringException $e) {
$this
Expand Down Expand Up @@ -182,6 +182,9 @@ private function createExternal(DeployOptions $options, Deployable $deployable,
),
new MessageData(
$sm,
$seqno === 0
? $options->deployerWallet->getStateInit()->cell()
: null,
)
);
}
Expand Down

0 comments on commit e68575a

Please sign in to comment.