-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcommon.php
63 lines (52 loc) · 2.2 KB
/
common.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php /** @noinspection PhpUnhandledExceptionInspection */
declare(strict_types=1);
use Http\Client\Common\HttpMethodsClient;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Olifanton\Mnemonic\TonMnemonic;
use Olifanton\Ton\Transports\Toncenter\ClientOptions;
use Olifanton\Ton\Transports\Toncenter\ToncenterHttpV2Client;
use Olifanton\Ton\Transports\Toncenter\ToncenterTransport;
use Psr\Log\AbstractLogger;
define("ROOT_DIR", dirname(__DIR__));
require ROOT_DIR . "/vendor/autoload.php";
$dotenv = Dotenv\Dotenv::createMutable(ROOT_DIR);
$dotenv->load();
$httpClient = new HttpMethodsClient(
Psr18ClientDiscovery::find(),
Psr17FactoryDiscovery::findRequestFactory(),
Psr17FactoryDiscovery::findStreamFactory(),
);
$isMainnet = (defined("MAIN_NET") && MAIN_NET); // @phpstan-ignore-line
$toncenter = new ToncenterHttpV2Client(
$httpClient,
new ClientOptions(
$isMainnet ? ClientOptions::MAIN_BASE_URL : ClientOptions::TEST_BASE_URL,
$isMainnet ? $_ENV["TONCENTER_API_KEY_MAINNET"] : $_ENV["TONCENTER_API_KEY"],
),
);
$transport = new ToncenterTransport($toncenter);
$words = explode(" ", trim($_ENV["TEST_V3R2_WALLET_WORDS"]));
$kp = TonMnemonic::mnemonicToKeyPair($words);
$logger = new class extends AbstractLogger
{
public function log($level, Stringable | string $message, array $context = []): void
{
$renderContextRow = static function (string $ctxKey, $ctxValue) {
$strVal = $ctxValue instanceof \Throwable
? ($ctxValue->getMessage() . "; (" . $ctxValue->getCode() . "); file: " . $ctxValue->getFile() . ":" . $ctxValue->getLine())
: (is_scalar($ctxValue) ? $ctxValue : gettype($ctxValue));
return "\t\t[$ctxKey] => " . $strVal;
};
echo sprintf(
"[%s] (%s) %s%s%s",
(new DateTimeImmutable())->format(DATE_RFC3339),
$level,
$message,
empty($context)
? ""
: PHP_EOL . "\tContext:" . PHP_EOL . implode(PHP_EOL, array_map($renderContextRow, array_keys($context), array_values($context))) . PHP_EOL . "\t" . str_repeat("=", 20) . PHP_EOL,
PHP_EOL,
);
}
};