Skip to content

Commit

Permalink
Highload wallet V2 with state initialization feature
Browse files Browse the repository at this point in the history
  • Loading branch information
romanzaycev committed Mar 10, 2024
1 parent 3f4575e commit fe82270
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
5 changes: 0 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@
"http-interop/http-factory-guzzle": "^1.2",
"php-http/guzzle7-adapter": "^1.0"
},
"replace": {
"symfony/polyfill-mbstring": "*",
"symfony/polyfill-php80": "*",
"symfony/polyfill-ctype": "*"
},
"scripts": {
"test:unit": "XDEBUG_MODE=coverage phpunit --testsuite unit",
"test:cr": "XDEBUG_MODE=coverage phpunit --coverage-html build/coverage-all",
Expand Down
52 changes: 52 additions & 0 deletions examples/wallets/highload-wallet-stateinit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php /** @noinspection PhpUnhandledExceptionInspection */

declare(strict_types=1);

use Olifanton\Interop\Address;
use Olifanton\Interop\Bytes;
use Olifanton\Interop\KeyPair;
use Olifanton\Interop\Units;
use Olifanton\Ton\AddressState;
use Olifanton\Ton\Contracts\Wallets\Highload\HighloadV2Options;
use Olifanton\Ton\Contracts\Wallets\Highload\HighloadWalletV2;
use Olifanton\Ton\Contracts\Wallets\Transfer;
use Olifanton\Ton\Contracts\Wallets\TransferOptions;
use Olifanton\Ton\SendMode;

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

global $transport, $logger;

// HL wallet instance
$hlWalletKp = KeyPair::fromSecretKey(Bytes::base64ToBytes(" KEY HERE ")); // <- Paste here your secret key for HL wallet in Base64 format
$hlWallet = new HighloadWalletV2(
new HighloadV2Options(
$hlWalletKp->publicKey,
),
);

$logger->info("HL wallet address: " . $hlWallet->getAddress()->toString(true));

// Get state of HL wallet contract
$state = $transport->getState($hlWallet->getAddress());

// Transfers list
$extMsg = $hlWallet->createTransferMessage(
[
new Transfer(
dest: new Address("UQAoqXsjSOtWhZo9t0Fiss9BIiV34qHo5eU6mx0SL0zQ5do-"),
amount: Units::toNano("0.011"),
sendMode: SendMode::IGNORE_ERRORS->combine(SendMode::PAY_GAS_SEPARATELY),
),
new Transfer(
dest: new Address("EQCrrSblmeNMAw27AXbchzG6MUja9iac7PHjyK3Xn8EMeqbG"),
amount: Units::toNano("0.012"),
sendMode: SendMode::IGNORE_ERRORS->combine(SendMode::PAY_GAS_SEPARATELY),
),
],
new TransferOptions(
seqno: $state === AddressState::UNINITIALIZED ? 0 : 1, // Set `0` for autodeploy
)
);

$transport->sendMessage($extMsg, $hlWalletKp->secretKey);
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function createTransferMessage(array $transfers, ?TransferOptions $option
),
new MessageData(
$signingMessage->cell(),
$options->seqno === 0 ? $this->getStateInit()->cell() : null,
)
);
// @codeCoverageIgnoreStart
Expand Down

0 comments on commit fe82270

Please sign in to comment.