mirror of
https://github.com/openvk/openvk
synced 2024-11-14 02:59:12 +03:00
commit
305bd7b02f
8 changed files with 166 additions and 1 deletions
103
CLI/FetchToncoinTransactions.php
Executable file
103
CLI/FetchToncoinTransactions.php
Executable file
|
@ -0,0 +1,103 @@
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
namespace openvk\CLI;
|
||||||
|
use Chandler\Database\DatabaseConnection;
|
||||||
|
use openvk\Web\Models\Repositories\Users;
|
||||||
|
use openvk\Web\Models\Entities\Notifications\CoinsTransferNotification;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Nette\Utils\ImageException;
|
||||||
|
|
||||||
|
define("NANOTON", 1000000000);
|
||||||
|
|
||||||
|
class FetchToncoinTransactions extends Command
|
||||||
|
{
|
||||||
|
private $images;
|
||||||
|
|
||||||
|
protected static $defaultName = "fetch-ton";
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -455,6 +455,18 @@ final class UserPresenter extends OpenVKPresenter
|
||||||
"main", "privacy", "finance", "finance.top-up", "interface"
|
"main", "privacy", "finance", "finance.top-up", "interface"
|
||||||
]) ? $this->queryParam("act")
|
]) ? $this->queryParam("act")
|
||||||
: "main";
|
: "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->user = $user;
|
||||||
$this->template->themes = Themepacks::i()->getThemeList();
|
$this->template->themes = Themepacks::i()->getThemeList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,10 @@
|
||||||
{_on_your_account}
|
{_on_your_account}
|
||||||
<div style="width: 100%; height: 60px; font-weight: 100;" id="balance">{$thisUser->getCoins()}</div>
|
<div style="width: 100%; height: 60px; font-weight: 100;" id="balance">{$thisUser->getCoins()}</div>
|
||||||
{_points_count}<br/>
|
{_points_count}<br/>
|
||||||
<small><a href="?act=finance.top-up">[{_have_voucher}?]</a></small>
|
<small><a href="?act=finance.top-up">[{_have_voucher}?]</a></small><br>
|
||||||
|
<small n:if="OPENVK_ROOT_CONF['openvk']['preferences']['ton']['enabled']">
|
||||||
|
<a href="javascript:showCoinsTopUpTroughTon()">[{_transfer_trough_ton}]</a>
|
||||||
|
</small>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -393,6 +396,28 @@
|
||||||
|
|
||||||
balance.style.width = Math.ceil(balance.parentNode.getBoundingClientRect().width) + "px";
|
balance.style.width = Math.ceil(balance.parentNode.getBoundingClientRect().width) + "px";
|
||||||
textFit(balance, { alignVert: true });
|
textFit(balance, { alignVert: true });
|
||||||
|
|
||||||
|
function convertCurrency(coin) {
|
||||||
|
var currencyTON = {php echo OPENVK_ROOT_CONF['openvk']['preferences']['ton']['rate']};
|
||||||
|
u(".coins_dialog_conv").nodes[0].innerHTML = tr("transfer_ton_currency_per_ton", coin * currencyTON);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCoinsTopUpTroughTon() {
|
||||||
|
MessageBox(tr("transfer_trough_ton"), `
|
||||||
|
<div class="messagebox-content-header">
|
||||||
|
${tr("transfer_ton_contents")}
|
||||||
|
</div>
|
||||||
|
<div style="margin-top: 30px">` +
|
||||||
|
{tr("transfer_ton_address", OPENVK_ROOT_CONF['openvk']['preferences']['ton']['address'], str_replace("$1", $thisUser->getId(), OPENVK_ROOT_CONF["openvk"]["preferences"]["ton"]["hint"]))} +
|
||||||
|
`<div style="text-align: center;">
|
||||||
|
<img width="225" height="225" src="data:` + {$qrCodeType} + `;base64,` + {$qrCodeData} + `"><br>
|
||||||
|
<input oninput="convertCurrency(this.value)"> = <span class="coins_dialog_conv">0 TON</span>
|
||||||
|
</div>
|
||||||
|
</div>`
|
||||||
|
, [tr("close")], [
|
||||||
|
Function.noop
|
||||||
|
]);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{elseif $isFinanceTU}
|
{elseif $isFinanceTU}
|
||||||
|
|
6
install/sqls/00024-toncoin-fetching.sql
Normal file
6
install/sqls/00024-toncoin-fetching.sql
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
CREATE TABLE `cryptotransactions` (
|
||||||
|
`id` bigint(20) NOT NULL AUTO_INCREMENT,
|
||||||
|
`hash` varchar(45) COLLATE utf8mb4_general_nopad_ci NOT NULL,
|
||||||
|
`lt` bigint(20) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_nopad_ci;
|
|
@ -603,6 +603,11 @@
|
||||||
|
|
||||||
"transferred_to_you" = "transferred to you";
|
"transferred_to_you" = "transferred to you";
|
||||||
|
|
||||||
|
"transfer_trough_ton" = "Top up with TON";
|
||||||
|
"transfer_ton_contents" = "You can top up your balance with TON cryptocurrency. It's just enough to scan the QR-code with the Tonkeeper app, or manually send TON according to the requisites. Within a few minutes you will receive a certain amount of votes.";
|
||||||
|
"transfer_ton_address" = "<b>Wallet address:</b> $1<br/><b>Message content:</b> $2";
|
||||||
|
"transfer_ton_currency_per_ton" = "$1 TON";
|
||||||
|
|
||||||
"receiver_address" = "Receiver address";
|
"receiver_address" = "Receiver address";
|
||||||
"coins_count" = "Number of votes";
|
"coins_count" = "Number of votes";
|
||||||
"message" = "Message";
|
"message" = "Message";
|
||||||
|
|
|
@ -639,6 +639,11 @@
|
||||||
|
|
||||||
"transferred_to_you" = "передал вам";
|
"transferred_to_you" = "передал вам";
|
||||||
|
|
||||||
|
"transfer_trough_ton" = "Пополнить с помощью TON";
|
||||||
|
"transfer_ton_contents" = "Вы можете пополнить ваш баланс с помощью криптовалюты TON. Достаточно отсканировать QR-code приложением Tonkeeper, или вручную отправить TON по реквизитам. В течении нескольких минут вам придут определенное количество голосов.";
|
||||||
|
"transfer_ton_address" = "<b>Адрес кошелька:</b> $1<br/><b>Содержание сообщения:</b> $2";
|
||||||
|
"transfer_ton_currency_per_ton" = "$1 TON";
|
||||||
|
|
||||||
"receiver_address" = "Адрес получателя";
|
"receiver_address" = "Адрес получателя";
|
||||||
"coins_count" = "Количество голосов";
|
"coins_count" = "Количество голосов";
|
||||||
"message" = "Сообщение";
|
"message" = "Сообщение";
|
||||||
|
|
|
@ -53,6 +53,14 @@ openvk:
|
||||||
processingLimit: 3000
|
processingLimit: 3000
|
||||||
emojiProcessingLimit: 1000
|
emojiProcessingLimit: 1000
|
||||||
commerce: false
|
commerce: false
|
||||||
|
ton:
|
||||||
|
enabled: false
|
||||||
|
address: "🅿"
|
||||||
|
testnet: false # Only for testing purposes.
|
||||||
|
rate: 0.02 # TONs per 1 coin
|
||||||
|
regex: "ovk=([0-9]+)"
|
||||||
|
hint: "ovk=$1"
|
||||||
|
# Please read docs to understand how to turn on automatic checking for new translations
|
||||||
menu:
|
menu:
|
||||||
links:
|
links:
|
||||||
- name: "@left_menu_donate"
|
- name: "@left_menu_donate"
|
||||||
|
|
|
@ -9,5 +9,6 @@ $bootstrap->ignite(true);
|
||||||
|
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
$application->add(new CLI\RebuildImagesCommand);
|
$application->add(new CLI\RebuildImagesCommand);
|
||||||
|
$application->add(new CLI\FetchToncoinTransactions);
|
||||||
|
|
||||||
$application->run();
|
$application->run();
|
Loading…
Reference in a new issue