-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyg_TonWalletGenerator.py
99 lines (82 loc) · 4.85 KB
/
yg_TonWalletGenerator.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
__version__ = (1, 4, 8, 8)
# This file is a part of Hikka Userbot
# Code is NOT licensed under CC-BY-NC-ND 4.0 unless otherwise specified.
# 🌐 https://github.com/hikariatama/Hikka
# You CAN edit this file without direct permission from the author.
# You can redistribute this file with any modifications.
# meta developer: @yg_modules
# scope: hikka_only
# scope: hikka_min 1.6.3
# █▄█ █░█ █▀▄▀█ █▀▄▀█ █▄█ █▀▄▀█ █▀█ █▀▄ █▀
# ░█░ █▄█ █░▀░█ █░▀░█ ░█░ █░▀░█ █▄█ █▄▀ ▄█
import logging
from tonsdk.contract.wallet import Wallets, WalletVersionEnum
from .. import loader, utils
@loader.tds
class TonWalletGenerator(loader.Module):
"""Генератор TON кошельков"""
strings = {"name": "yg_TonWalletGenerator"}
async def client_ready(self, client, db):
self.client = client
async def gencmd(self, message):
"""<count> генерирует один или несколько TON кошельков"""
try:
args = utils.get_args_raw(message).strip()
if args:
try:
count = int(args)
chozabretto = self.gcd(count)
tmp = await message.edit(f"<emoji document_id=5431449001532594346>⚡️</emoji> <b>Генерирую {count} {chozabretto}...</b>")
if count < 2 or count > 200:
raise ValueError
except ValueError:
await message.edit("<emoji document_id=5465665476971471368>❌</emoji> <b>Некорректное количество кошельков. Допустимый диапазон: от 2 до 200.</b>\n\n<emoji document_id=5472164874886846699>✨</emoji> <i>Если вы хотите сгенерировать один кошелек то просто напишите</i> <code>.gen</code>")
return
else:
kok = await message.edit("<emoji document_id=5431449001532594346>⚡️</emoji> <b>Генерирую...</b>")
count = 1
wallets_info = []
for _ in range(count):
mnemonics, pub_k, priv_k, wallet = Wallets.create(WalletVersionEnum.v4r2, workchain=0)
wallet_address = wallet.address.to_string(True, True, False)
wallets_info.append((wallet_address, ' '.join(mnemonics)))
if count == 1:
half = len(wallets_info[0][1].split()) // 2
first_half = wallets_info[0][1].split()[:half]
second_half = wallets_info[0][1].split()[half:]
max_len = max(len(word) for word in wallets_info[0][1].split()) + 2
mnemonics_str = ''
for i in range(half):
first_index = i + 1
second_index = half + i + 1
if first_index < 10:
mnemonics_str += f"{first_index}. {first_half[i].ljust(max_len)} {second_index}. {second_half[i]}\n"
else:
mnemonics_str += f"{first_index}. {first_half[i].ljust(max_len)}{second_index}. {second_half[i]}\n"
response = (
f"<b>Адрес:</b>\n<code>{wallets_info[0][0]}</code>\n\n"
f"<b>Сид-фраза:</b>\n<pre>{mnemonics_str}</pre>\n"
f"\n<b>Скопировать:</b> <code>{wallets_info[0][1]}</code>"
)
await kok.edit(response)
else:
wallet_info = "\n\n".join(f"{i+1}. Адрес: {addr}\n Сид-фраза: {seed}" for i, (addr, seed) in enumerate(wallets_info))
with open("wallets.txt", "w", encoding="utf-8") as f:
f.write(wallet_info)
chozabretto = self.gcd(count)
caption = f"<emoji document_id=5370869711888194012>👾</emoji> <b>Сгенерировано {count} {chozabretto}</b>"
await self.client.send_file(message.peer_id, "wallets.txt", caption=caption)
await tmp.delete()
except Exception as e:
logging.exception("Ошибка при генерации кошелька")
await message.edit("<emoji document_id=5465665476971471368>❌</emoji> <b>Ошибка при генерации кошелька. Попробуйте еще раз</b>")
def gcd(self, count):
if 11 <= count % 100 <= 14:
return "кошельков"
last_digit = count % 10
if last_digit == 1:
return "кошелек"
elif 2 <= last_digit <= 4:
return "кошелька"
else:
return "кошельков"