multiple times password entering
This commit is contained in:
123
wallet.py
123
wallet.py
@@ -48,7 +48,7 @@ def connect_to_network():
|
||||
if web3.is_connected():
|
||||
print("[green1]Подключено![/]")
|
||||
else:
|
||||
print("[red]Ошибка подключения к сети![/]")
|
||||
print("[red1]Ошибка подключения к сети![/]")
|
||||
web3 = None
|
||||
|
||||
|
||||
@@ -57,6 +57,10 @@ def create_wallet():
|
||||
acct = Account.create()
|
||||
save_wallet(acct)
|
||||
|
||||
show_private_key = Prompt.ask("[bold cyan]Показать приватный ключ?", choices=["y", "n"], default="y")
|
||||
if show_private_key == 'y':
|
||||
print(f"[orange1]{acct.key.hex()}")
|
||||
|
||||
|
||||
def import_wallet():
|
||||
print("[bold cyan]Введите приватный ключ: [/]", end='')
|
||||
@@ -65,13 +69,35 @@ def import_wallet():
|
||||
save_wallet(account)
|
||||
|
||||
|
||||
def check_password():
|
||||
return get_private_key() is not None
|
||||
|
||||
|
||||
def get_private_key():
|
||||
print("[bold cyan]Введите пароль от кошелька: [/]", end='')
|
||||
password = getpass.getpass(prompt="")
|
||||
|
||||
private_key = None
|
||||
|
||||
try:
|
||||
private_key = decrypt_wallet(selected_wallet['data'], password)
|
||||
del password
|
||||
except:
|
||||
print("[red1]Неверный пароль![/]")
|
||||
|
||||
return private_key
|
||||
|
||||
|
||||
def delete_wallet():
|
||||
global selected_wallet
|
||||
|
||||
while not check_password():
|
||||
pass
|
||||
|
||||
address = Prompt.ask("[red1]При удалении кошелька доступ к средствам будет потерян, введите номер кошелька для подтверждения операции")
|
||||
|
||||
if address != selected_wallet['address']:
|
||||
print("[red]Операция отменена")
|
||||
print("[red1]Операция отменена")
|
||||
return
|
||||
|
||||
file_path = os.path.join(WALLETS_DIR, selected_wallet['address']+'.json')
|
||||
@@ -99,7 +125,7 @@ def select_wallet():
|
||||
global selected_wallet
|
||||
files = os.listdir(WALLETS_DIR)
|
||||
if not files:
|
||||
print("[red]Нет доступных кошельков.[/]")
|
||||
print("[red1]Нет доступных кошельков.[/]")
|
||||
return
|
||||
|
||||
for i, fname in enumerate(files):
|
||||
@@ -108,7 +134,7 @@ def select_wallet():
|
||||
try:
|
||||
choice = int(Prompt.ask("[bold cyan]Выберите номер кошелька[/]"))
|
||||
except:
|
||||
print("[red]Неверный номер.[/]")
|
||||
print("[red1]Неверный номер.[/]")
|
||||
return
|
||||
|
||||
with open(os.path.join(WALLETS_DIR, files[choice-1])) as f:
|
||||
@@ -117,7 +143,7 @@ def select_wallet():
|
||||
|
||||
def get_balance():
|
||||
if not selected_wallet:
|
||||
print("[red]Кошелек не выбран.[/]")
|
||||
print("[red1]Кошелек не выбран.[/]")
|
||||
return
|
||||
balance = web3.eth.get_balance(selected_wallet['address'])
|
||||
print(f"[orange1]Баланс: {web3.from_wei(balance, 'ether')} ETH")
|
||||
@@ -148,15 +174,9 @@ def send_transaction():
|
||||
'maxPriorityFeePerGas': max_priority_fee
|
||||
}
|
||||
|
||||
print("[bold cyan]Введите пароль от кошелька: [/]", end='')
|
||||
password = getpass.getpass(prompt="")
|
||||
|
||||
try:
|
||||
private_key = decrypt_wallet(selected_wallet['data'], password)
|
||||
del password
|
||||
except:
|
||||
print("[red1]Неверный пароль![/]")
|
||||
return
|
||||
private_key = None
|
||||
while not private_key:
|
||||
private_key = get_private_key()
|
||||
|
||||
try:
|
||||
signed = web3.eth.account.sign_transaction(tx, private_key)
|
||||
@@ -170,7 +190,7 @@ def send_transaction():
|
||||
|
||||
|
||||
def main():
|
||||
print("""
|
||||
menu = """
|
||||
[bold blue]Меню:[/]
|
||||
a. Подключение к сети Ethereum
|
||||
c. Создание кошелька
|
||||
@@ -180,38 +200,53 @@ def main():
|
||||
i. Импорт существующего кошелька
|
||||
d. Удаление кошелька
|
||||
q. Выход
|
||||
""")
|
||||
"""
|
||||
|
||||
print(menu)
|
||||
|
||||
while True:
|
||||
choice = Prompt.ask("[slate_blue1]Выберите действие[/]").lower()
|
||||
if choice == 'a':
|
||||
connect_to_network()
|
||||
elif choice == 'c':
|
||||
create_wallet()
|
||||
elif choice == 'w':
|
||||
select_wallet()
|
||||
elif choice == 'b':
|
||||
if web3 and selected_wallet:
|
||||
get_balance()
|
||||
else:
|
||||
print("[red1]Необходимо подключиться к сети и выбрать кошелек[/]")
|
||||
elif choice == 's':
|
||||
if web3 and selected_wallet:
|
||||
send_transaction()
|
||||
else:
|
||||
print("[red1]Необходимо подключиться к сети и выбрать кошелек[/]")
|
||||
elif choice == 'i':
|
||||
import_wallet()
|
||||
elif choice == 'd':
|
||||
if not selected_wallet:
|
||||
select_wallet()
|
||||
try:
|
||||
choice = Prompt.ask("[slate_blue1]Выберите действие[/]").lower()
|
||||
|
||||
if selected_wallet:
|
||||
delete_wallet()
|
||||
else:
|
||||
print("[red1]Необходимо выбрать кошелек[/]")
|
||||
elif choice == 'q':
|
||||
break
|
||||
if choice == 'a':
|
||||
connect_to_network()
|
||||
elif choice == 'c':
|
||||
create_wallet()
|
||||
elif choice == 'w':
|
||||
select_wallet()
|
||||
elif choice == 'b':
|
||||
if web3 and selected_wallet:
|
||||
get_balance()
|
||||
else:
|
||||
print("[red1]Необходимо подключиться к сети и выбрать кошелек[/]")
|
||||
elif choice == 's':
|
||||
if web3 and selected_wallet:
|
||||
send_transaction()
|
||||
else:
|
||||
print("[red1]Необходимо подключиться к сети и выбрать кошелек[/]")
|
||||
elif choice == 'i':
|
||||
import_wallet()
|
||||
elif choice == 'd':
|
||||
if not selected_wallet:
|
||||
select_wallet()
|
||||
|
||||
if selected_wallet:
|
||||
delete_wallet()
|
||||
else:
|
||||
print("[red1]Необходимо выбрать кошелек[/]")
|
||||
elif choice == 'q':
|
||||
break
|
||||
# system commands
|
||||
elif choice == "clear":
|
||||
if os.name == 'nt':
|
||||
_ = os.system('cls')
|
||||
else:
|
||||
_ = os.system('clear')
|
||||
print(menu)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print()
|
||||
continue
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user