diff --git a/CLI/FetchToncoinTransactions.php b/CLI/FetchToncoinTransactions.php new file mode 100755 index 00000000..f6a2fb56 --- /dev/null +++ b/CLI/FetchToncoinTransactions.php @@ -0,0 +1,103 @@ +transactions = DatabaseConnection::i()->getContext()->table("cryptotransactions"); + + parent::__construct(); + } + + protected function configure(): void + { + $this->setDescription("Fetches TON transactions to top up the users' balance") + ->setHelp("This command checks for new transactions on TON Wallet and then top up the balance of specified users"); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $header = $output->section(); + + $header->writeln([ + "TONCOIN Fetcher", + "=====================", + "", + ]); + + if(!OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["enabled"]) { + $header->writeln("Sorry, but you handn't enabled the TON support in your config file yet."); + + return Command::FAILURE; + } + + $testnetSubdomain = OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["testnet"] ? "testnet." : ""; + $url = "https://" . $testnetSubdomain . "toncenter.com/api/v2/getTransactions?"; + + $opts = [ + "http" => [ + "method" => "GET", + "header" => "Accept: application/json" + ] + ]; + + $selection = $this->transactions->select('hash, lt')->order("id DESC")->limit(1)->fetch(); + $trHash = $selection->hash ?? NULL; + $trLt = $selection->lt ?? NULL; + + $data = http_build_query([ + "address" => OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["address"], + "limit" => 100, + "hash" => $trHash, + "to_lt" => $trLt + ]); + + $response = file_get_contents($url . $data, false, stream_context_create($opts)); + $response = json_decode($response, true); + + $header->writeln("Gonna up the balance of users"); + foreach($response["result"] as $transfer) { + $outputArray; + preg_match('/' . OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["regex"] . '/', $transfer["in_msg"]["message"], $outputArray); + $userId = ctype_digit($outputArray[1]) ? intval($outputArray[1]) : NULL; + if(is_null($userId)) { + $header->writeln("Well, that's a donation. Thanks! XD"); + } else { + $user = (new Users)->get($userId); + if(!$user) { + $header->writeln("Well, that's a donation. Thanks! XD"); + } else { + $value = ($transfer["in_msg"]["value"] / NANOTON) / OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["rate"]; + $user->setCoins($user->getCoins() + $value); + $user->save(); + (new CoinsTransferNotification($user, (new Users)->get(OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]), 0, "Via TON cryptocurrency"))->emit(); + $header->writeln($value . " coins are added to " . $user->getId() . " user id"); + $this->transactions->insert([ + "id" => NULL, + "hash" => $transfer["transaction_id"]["hash"], + "lt" => $transfer["transaction_id"]["lt"] + ]); + } + } + } + + $header->writeln("Processing finished :3"); + + return Command::SUCCESS; + } +} \ No newline at end of file diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index e2f26d59..e27caf68 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -455,6 +455,18 @@ final class UserPresenter extends OpenVKPresenter "main", "privacy", "finance", "finance.top-up", "interface" ]) ? $this->queryParam("act") : "main"; + + if($this->template->mode == "finance") { + $address = OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["address"]; + $text = str_replace("$1", $this->user->identity->getId(), OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["hint"]); + $qrCode = explode("base64,", (new QRCode(new QROptions([ + "imageTransparent" => false + ])))->render("ton://transfer/$address?text=$text")); + + $this->template->qrCodeType = substr($qrCode[0], 5); + $this->template->qrCodeData = $qrCode[1]; + } + $this->template->user = $user; $this->template->themes = Themepacks::i()->getThemeList(); } diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index 1437d1a3..68faae60 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -383,7 +383,10 @@ {_on_your_account}