Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jobs:
run: |
pip install -U .

- name: Run Pyright
run: |
pip install pyright
pyright mypylib mypyconsole mytoncore/models.py mytoncore/utils.py # wip support whole project

- name: Run pytest
run: |
pytest --import-mode=append # to test built package
14 changes: 10 additions & 4 deletions modules/alert_bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dataclasses
import time
from typing import Optional

import requests

from modules.module import MtcModule
Expand Down Expand Up @@ -196,6 +198,7 @@ def __init__(self, ton, local, *args, **kwargs):
self.chat_id = None
self.last_db_check = 0
self.initial_sync = None
self.wallet: Optional[str] = None

def send_message(self, text: str, silent: bool = False, disable_web_page_preview: bool = False):
if self.token is None:
Expand Down Expand Up @@ -237,7 +240,7 @@ def send_alert(self, alert_name: str, *args, track_active: bool = True, **kwargs
ADNL: <code>{self.adnl}</code>'''

if self.ton.using_validator():
text += f"\nWallet: <code>{self.wallet}</code>"
text += f"\nWallet: <code>{self.wallet or 'n/a'}</code>"

text += f'''
Time: <code>{time_}</code> (<code>{int(time.time())}</code>)
Expand All @@ -250,7 +253,7 @@ def send_alert(self, alert_name: str, *args, track_active: bool = True, **kwargs
if track_active:
self._set_alert_active(alert_name, True)

def resolve_alert(self, alert_name: str, ok_alert_name: str = None, **kwargs):
def resolve_alert(self, alert_name: str, ok_alert_name: Optional[str] = None, **kwargs):
if not self._is_alert_active(alert_name):
return
ok_alert_name = ok_alert_name or f"{alert_name}_ok"
Expand Down Expand Up @@ -292,7 +295,8 @@ def init(self):
self.hostname = get_hostname()
adnl = self.ton.GetAdnlAddr()
self.adnl = adnl
self.wallet = self.ton.GetValidatorWallet().addrB64
w = self.ton.GetValidatorWallet()
self.wallet = w.addrB64 if w else None
self.ip = self.ton.get_node_ip()
self.set_global_vars()
self.initial_sync = self.ton.in_initial_sync()
Expand Down Expand Up @@ -415,6 +419,7 @@ def check_validator_wallet_balance(self):
if not validator_status.is_working or validator_status.out_of_sync >= 20:
return
validator_wallet = self.ton.GetValidatorWallet()
assert validator_wallet is not None, "Could not get validator wallet"
validator_account = self.ton.GetAccount(validator_wallet.addrB64)
if validator_account.status != "empty" and validator_account.balance < 10:
self.send_alert("low_wallet_balance", wallet=validator_wallet.addrB64, balance=validator_account.balance)
Expand All @@ -424,6 +429,7 @@ def check_validator_wallet_balance(self):
def check_efficiency(self):
if not self.ton.using_validator():
return
assert self.validator_module is not None, "Validator module is not initialized"
validator = self.validator_module.find_myself(self.ton.GetValidatorsList())
if validator is None or validator.efficiency is None:
return
Expand Down Expand Up @@ -526,7 +532,7 @@ def check_stake_returned(self):
trs = self.ton.GetAccountHistory(self.ton.GetAccount(res["walletAddr"]), limit=10)

for tr in trs:
if tr.time >= config['endWorkTime'] + FREEZE_PERIOD and tr.srcAddr == '3333333333333333333333333333333333333333333333333333333333333333' and tr.body.startswith('F96F7324'): # Elector Recover Stake Response
if tr.time >= config['endWorkTime'] + FREEZE_PERIOD and tr.src_addr == '3333333333333333333333333333333333333333333333333333333333333333' and tr.body.startswith('F96F7324'): # Elector Recover Stake Response
self.send_alert("stake_returned", stake=round(tr.value), address=res["walletAddr"], reward=round(tr.value - res.get('stake', 0), 2))
return
self.send_alert("stake_not_returned", address=res["walletAddr"])
Expand Down
4 changes: 2 additions & 2 deletions modules/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_backup(self, args):
if not check_usage_args_min_max_len("create_backup", args, 0, 3):
return
tmp_dir = self.create_tmp_ton_dir()
command_args = ["-m", self.ton.local.buffer.my_work_dir, "-t", tmp_dir]
command_args = ["-m", self.ton.local.my_work_dir, "-t", tmp_dir]
user = pop_user_from_args(args)
if len(args) == 1:
command_args += ["-d", args[0]]
Expand Down Expand Up @@ -84,7 +84,7 @@ def restore_backup(self, args):
color_print(f"{{red}}Could not create backup: {e}{{endc}}")

ip = str(ip2int(get_own_ip()))
command_args = ["-m", self.ton.local.buffer.my_work_dir, "-n", args[0], "-i", ip]
command_args = ["-m", self.ton.local.my_work_dir, "-n", args[0], "-i", ip]

if self.run_restore_backup(command_args, user=user) == 0:
self.ton.local.load_db()
Expand Down
2 changes: 1 addition & 1 deletion modules/btc_teleport.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class BtcTeleportModule(MtcModule):

def __init__(self, ton, local, *args, **kwargs):
super().__init__(ton, local, *args, **kwargs)
self.keystore_path = self.ton.local.buffer.my_work_dir + '/btc_oracle_keystore'
self.keystore_path = self.ton.local.my_work_dir + '/btc_oracle_keystore'
self.repo_name = 'ton-teleport-btc-periphery'
self.src_dir = f"/usr/src/{self.repo_name}"
self.bin_dir = self.src_dir + '/out'
Expand Down
6 changes: 3 additions & 3 deletions modules/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def do_check_liquid_pool(self):
history = self.ton.GetAccountHistory(account, 5000)
addrs_list = list()
for message in history:
if message.srcAddr is None or message.value is None:
if message.src_addr is None or message.value is None:
continue
src_addr_full = f"{message.srcWorkchain}:{message.srcAddr}"
dest_add_full = f"{message.destWorkchain}:{message.destAddr}"
src_addr_full = f"{message.src_workchain}:{message.src_addr}"
dest_add_full = f"{message.dest_workchain}:{message.dest_addr}"
if src_addr_full == account.addrFull:
fromto = dest_add_full
else:
Expand Down
2 changes: 1 addition & 1 deletion modules/nominator_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def update_validator_set(self, args):

def do_deposit_to_pool(self, pool_addr, amount):
wallet = self.ton.GetValidatorWallet()
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
bocPath = self.ton.local.my_temp_dir + wallet.name + "validator-deposit-query.boc"
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
args = [fiftScript, bocPath]
self.ton.fift.Run(args)
Expand Down
6 changes: 3 additions & 3 deletions modules/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def get_history_table(self, addr, limit):
typeText = color_text("{red}{bold}{endc}")
table += [["Time", typeText, "Coins", "From/To"]]
for message in history:
if message.srcAddr is None:
if message.src_addr is None:
continue
srcAddrFull = f"{message.srcWorkchain}:{message.srcAddr}"
destAddFull = f"{message.destWorkchain}:{message.destAddr}"
srcAddrFull = f"{message.src_workchain}:{message.src_addr}"
destAddFull = f"{message.dest_workchain}:{message.dest_addr}"
if srcAddrFull == account.addrFull:
type = color_text("{red}{bold}>>>{endc}")
fromto = destAddFull
Expand Down
5 changes: 3 additions & 2 deletions modules/validator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations
import json
import time

from modules.btc_teleport import BtcTeleportModule
from mypylib.mypylib import color_print, get_timestamp
from mypylib.mypylib import Dict, color_print, get_timestamp
from modules.module import MtcModule
from mytoncore.utils import hex_shard_to_int, hex2b64
from mytonctrl.console_cmd import check_usage_two_args, add_command, check_usage_args_min_max_len
Expand Down Expand Up @@ -46,7 +47,7 @@ def vote_complaint(self, args):
self.ton.VoteComplaint(election_id, complaint_hash)
color_print("VoteComplaint - {green}OK{endc}")

def find_myself(self, validators: list) -> dict:
def find_myself(self, validators: list) -> Dict | None:
adnl_addr = self.ton.GetAdnlAddr()
for validator in validators:
if validator.get("adnlAddr") == adnl_addr:
Expand Down
9 changes: 6 additions & 3 deletions mypyconsole/mypyconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import readline
from collections import deque

from mypylib import MyPyClass


class MyPyConsoleItem():
def __init__(self, cmd: str, func, desc: str, usage: str = ''):
self.cmd = cmd
Expand All @@ -15,12 +18,12 @@ def __init__(self, cmd: str, func, desc: str, usage: str = ''):
#end define
#end class

class MyPyConsole():
class MyPyConsole:
RED = '\033[31m'
GREEN = '\033[92m'
ENDC = '\033[0m'

def __init__(self):
def __init__(self, local: MyPyClass):
self.debug = False
self.name = "console"
self.color = self.GREEN
Expand All @@ -30,7 +33,7 @@ def __init__(self):
self.start_function = None
self.menu_items = list()
self.history = deque(maxlen=100)
self.local = None
self.local: MyPyClass = local
self.add_item("help", self.help, "Print help text")
self.add_item("clear", self.clear, "Clear console")
self.add_item("history", self.print_history, "Print last commands")
Expand Down
2 changes: 0 additions & 2 deletions mypylib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"Dict",
"MyPyClass",
"parse",
"ping",
"get_request",
"dir",
"b2mb",
"search_file_in_dir",
"search_dir_in_dir",
Expand Down
Loading
Loading