Skip to content

Commit 23f7f72

Browse files
authored
Merge branch 'dev' into bot
2 parents 8b916ad + 3425a5e commit 23f7f72

18 files changed

+186
-66
lines changed

modules/alert_bot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def __init__(self, ton, local, *args, **kwargs):
8484
self.inited = False
8585
self.hostname = None
8686
self.ip = None
87-
self.token = self.ton.local.db.get("BotToken")
88-
self.chat_id = self.ton.local.db.get("ChatId")
89-
self.last_db_check = None
87+
self.token = None
88+
self.chat_id = None
89+
self.last_db_check = 0
9090

9191
def send_message(self, text: str):
9292
if self.token is None:
@@ -135,6 +135,8 @@ def set_global_vars(self):
135135
def init(self):
136136
if not self.ton.get_mode_value('alert-bot'):
137137
return
138+
self.token = self.ton.local.db.get("BotToken")
139+
self.chat_id = self.ton.local.db.get("ChatId")
138140
if self.token is None or self.chat_id is None:
139141
raise Exception("BotToken or ChatId is not set")
140142
from modules.validator import ValidatorModule

modules/nominator_pool.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,45 @@ def update_validator_set(self, args):
8787
self.ton.PoolUpdateValidatorSet(pool_addr, wallet)
8888
color_print("UpdateValidatorSet - {green}OK{endc}")
8989

90+
def do_deposit_to_pool(self, pool_addr, amount):
91+
wallet = self.ton.GetValidatorWallet()
92+
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
93+
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
94+
args = [fiftScript, bocPath]
95+
result = self.ton.fift.Run(args)
96+
resultFilePath = self.ton.SignBocWithWallet(wallet, bocPath, pool_addr, amount)
97+
self.ton.SendFile(resultFilePath, wallet)
98+
99+
def deposit_to_pool(self, args):
100+
try:
101+
poll_addr = args[0]
102+
amount = float(args[1])
103+
except:
104+
color_print("{red}Bad args. Usage:{endc} deposit_to_pool <pool-addr> <amount>")
105+
return
106+
self.do_deposit_to_pool(poll_addr, amount)
107+
color_print("DepositToPool - {green}OK{endc}")
108+
109+
def do_withdraw_from_pool(self, pool_addr, amount):
110+
pool_data = self.ton.GetPoolData(pool_addr)
111+
if pool_data["state"] == 0:
112+
self.ton.WithdrawFromPoolProcess(pool_addr, amount)
113+
else:
114+
self.ton.PendWithdrawFromPool(pool_addr, amount)
115+
116+
def withdraw_from_pool(self, args):
117+
try:
118+
pool_addr = args[0]
119+
amount = float(args[1])
120+
except:
121+
color_print("{red}Bad args. Usage:{endc} withdraw_from_pool <pool-addr> <amount>")
122+
return
123+
self.do_withdraw_from_pool(pool_addr, amount)
124+
color_print("WithdrawFromPool - {green}OK{endc}")
125+
90126
def add_console_commands(self, console):
91127
console.AddItem("new_pool", self.new_pool, self.local.translate("new_pool_cmd"))
92128
console.AddItem("activate_pool", self.activate_pool, self.local.translate("activate_pool_cmd"))
93129
console.AddItem("update_validator_set", self.update_validator_set, self.local.translate("update_validator_set_cmd"))
130+
console.AddItem("withdraw_from_pool", self.withdraw_from_pool, self.local.translate("withdraw_from_pool_cmd"))
131+
console.AddItem("deposit_to_pool", self.deposit_to_pool, self.local.translate("deposit_to_pool_cmd"))

modules/pool.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,45 +58,7 @@ def check_download_pool_contract_scripts(self):
5858
if not os.path.isdir(contract_path):
5959
self.ton.DownloadContract("https://github.com/ton-blockchain/nominator-pool")
6060

61-
def do_deposit_to_pool(self, pool_addr, amount):
62-
wallet = self.ton.GetValidatorWallet()
63-
bocPath = self.ton.local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc"
64-
fiftScript = self.ton.contractsDir + "nominator-pool/func/validator-deposit.fif"
65-
args = [fiftScript, bocPath]
66-
result = self.ton.fift.Run(args)
67-
resultFilePath = self.ton.SignBocWithWallet(wallet, bocPath, pool_addr, amount)
68-
self.ton.SendFile(resultFilePath, wallet)
69-
70-
def deposit_to_pool(self, args):
71-
try:
72-
poll_addr = args[0]
73-
amount = float(args[1])
74-
except:
75-
color_print("{red}Bad args. Usage:{endc} deposit_to_pool <pool-addr> <amount>")
76-
return
77-
self.do_deposit_to_pool(poll_addr, amount)
78-
color_print("DepositToPool - {green}OK{endc}")
79-
80-
def do_withdraw_from_pool(self, pool_addr, amount):
81-
pool_data = self.ton.GetPoolData(pool_addr)
82-
if pool_data["state"] == 0:
83-
self.ton.WithdrawFromPoolProcess(pool_addr, amount)
84-
else:
85-
self.ton.PendWithdrawFromPool(pool_addr, amount)
86-
87-
def withdraw_from_pool(self, args):
88-
try:
89-
pool_addr = args[0]
90-
amount = float(args[1])
91-
except:
92-
color_print("{red}Bad args. Usage:{endc} withdraw_from_pool <pool-addr> <amount>")
93-
return
94-
self.do_withdraw_from_pool(pool_addr, amount)
95-
color_print("WithdrawFromPool - {green}OK{endc}")
96-
9761
def add_console_commands(self, console):
9862
console.AddItem("pools_list", self.print_pools_list, self.local.translate("pools_list_cmd"))
9963
console.AddItem("delete_pool", self.delete_pool, self.local.translate("delete_pool_cmd"))
10064
console.AddItem("import_pool", self.import_pool, self.local.translate("import_pool_cmd"))
101-
console.AddItem("deposit_to_pool", self.deposit_to_pool, self.local.translate("deposit_to_pool_cmd"))
102-
console.AddItem("withdraw_from_pool", self.withdraw_from_pool, self.local.translate("withdraw_from_pool_cmd"))

modules/utilities.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,14 @@ def print_validator_list(self, args):
313313
print(text)
314314
else:
315315
table = list()
316-
table += [["id", "ADNL", "Pubkey", "Wallet", "Efficiency", "Online"]]
316+
table += [["id", "ADNL", "Pubkey", "Wallet", "Stake", "Efficiency", "Online"]]
317317
for i, item in enumerate(data):
318318
adnl = item.get("adnlAddr")
319319
pubkey = item.get("pubkey")
320320
walletAddr = item.get("walletAddr")
321321
efficiency = item.get("efficiency")
322322
online = item.get("online")
323+
stake = item.get("stake")
323324
if "adnl" not in args:
324325
adnl = self.reduct(adnl)
325326
if "pubkey" not in args:
@@ -332,7 +333,7 @@ def print_validator_list(self, args):
332333
online = bcolors.green_text("true")
333334
if not online:
334335
online = bcolors.red_text("false")
335-
table += [[str(i), adnl, pubkey, walletAddr, efficiency, online]]
336+
table += [[str(i), adnl, pubkey, walletAddr, stake, efficiency, online]]
336337
print_table(table)
337338
# end define
338339

mytoncore/mytoncore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def CheckConfigFile(self, fift, liteClient):
115115
self.local.add_log("Restoring the configuration file", "info")
116116
args = ["cp", backup_path, mconfig_path]
117117
subprocess.run(args)
118+
self.dbFile = mconfig_path
118119
self.Refresh()
119120
elif os.path.isfile(backup_path) == False:
120121
self.local.add_log("Create backup config file", "info")
@@ -2490,6 +2491,7 @@ def GetValidatorsList(self, past=False, fast=False, start=None, end=None):
24902491
validator["efficiency"] = round(validator["wr"] * 100, 2)
24912492
if saveElectionEntries and adnlAddr in saveElectionEntries:
24922493
validator["walletAddr"] = saveElectionEntries[adnlAddr]["walletAddr"]
2494+
validator["stake"] = saveElectionEntries[adnlAddr].get("stake")
24932495
#end for
24942496

24952497
# Set buffer

mytonctrl/mytonctrl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ def mode_status(ton, args):
527527
table = [["Name", "Status", "Description"]]
528528
for mode_name in modes:
529529
mode = get_mode(mode_name)
530+
if mode is None:
531+
color_print(f"{{red}}Mode {mode_name} not found{{endc}}")
532+
continue
530533
status = color_text('{green}enabled{endc}' if modes[mode_name] else '{red}disabled{endc}')
531534
table.append([mode_name, status, mode.description])
532535
print_table(table)
@@ -941,7 +944,7 @@ def create_backup(local, ton, args):
941944
color_print("{red}Bad args. Usage:{endc} create_backup [path_to_archive] [-y]")
942945
return
943946
if '-y' not in args:
944-
res = input(f'Node and Mytoncore services will be stopped for few seconds while backup is created, Proceed [y/n]?')
947+
res = input(f'Mytoncore service will be stopped for few seconds while backup is created, Proceed [y/n]?')
945948
if res.lower() != 'y':
946949
print('aborted.')
947950
return

mytonctrl/scripts/create_backup.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,28 @@ done
1616
COLOR='\033[92m'
1717
ENDC='\033[0m'
1818

19-
systemctl stop validator
2019
systemctl stop mytoncore
2120

22-
echo -e "${COLOR}[1/4]${ENDC} Stopped validator and mytoncore"
21+
echo -e "${COLOR}[1/4]${ENDC} Stopped mytoncore service"
2322

2423

2524
tmp_dir="/tmp/mytoncore/backup"
2625
rm -rf $tmp_dir
2726
mkdir $tmp_dir
27+
mkdir $tmp_dir/db
2828

29-
cp /var/ton-work/db/config.json ${tmp_dir}
30-
cp -r /var/ton-work/db/keyring ${tmp_dir}
29+
cp /var/ton-work/db/config.json ${tmp_dir}/db
30+
cp -r /var/ton-work/db/keyring ${tmp_dir}/db
3131
cp -r /var/ton-work/keys ${tmp_dir}
3232
cp -r $mtc_dir $tmp_dir
3333

34-
echo -e "${COLOR}[2/4]${ENDC} Copied files to ${tmp_dir}"
34+
python3 -c "import json;f=open('${tmp_dir}/db/config.json');json.load(f);f.close()" || exit 1 # Check if config.json is copied correctly
3535

36+
echo -e "${COLOR}[2/4]${ENDC} Copied files to ${tmp_dir}"
3637

37-
systemctl start validator
3838
systemctl start mytoncore
3939

40-
echo -e "${COLOR}[3/4]${ENDC} Started validator and mytoncore"
40+
echo -e "${COLOR}[3/4]${ENDC} Started mytoncore service"
4141

4242
tar -zcf $dest -C $tmp_dir .
4343

mytonctrl/scripts/restore_backup.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ rm -rf $tmp_dir
2929
mkdir $tmp_dir
3030
tar -xvzf $name -C $tmp_dir
3131

32+
if [ ! -d ${tmp_dir}/db ]; then
33+
echo "Old version of backup detected"
34+
mkdir ${tmp_dir}/db
35+
mv ${tmp_dir}/config.json ${tmp_dir}/db
36+
mv ${tmp_dir}/keyring ${tmp_dir}/db
37+
38+
fi
39+
3240
rm -rf /var/ton-work/db/keyring
33-
cp -f ${tmp_dir}/config.json /var/ton-work/db/
34-
cp -rf ${tmp_dir}/keyring /var/ton-work/db/
41+
cp -rf ${tmp_dir}/db /var/ton-work
3542
cp -rf ${tmp_dir}/keys /var/ton-work
3643
cp -rfT ${tmp_dir}/mytoncore $mtc_dir
3744

mytonctrl/scripts/upgrade.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ COLOR='\033[92m'
2929
ENDC='\033[0m'
3030

3131
# Установить дополнительные зависимости
32-
apt-get install -y libsecp256k1-dev libsodium-dev ninja-build fio rocksdb-tools liblz4-dev libjemalloc-dev
32+
apt-get install -y libsecp256k1-dev libsodium-dev ninja-build fio rocksdb-tools liblz4-dev libjemalloc-dev automake libtool
3333

3434
# bugfix if the files are in the wrong place
3535
wget "https://ton-blockchain.github.io/global.config.json" -O global.config.json
@@ -67,6 +67,10 @@ ls -A1 | xargs rm -rf
6767
echo "https://github.com/${author}/${repo}.git -> ${branch}"
6868
git clone --recursive https://github.com/${author}/${repo}.git .
6969
git checkout ${branch}
70+
71+
git submodule sync --recursive
72+
git submodule update
73+
7074
export CC=/usr/bin/clang
7175
export CXX=/usr/bin/clang++
7276
export CCACHE_DISABLE=1

mytoninstaller/mytoninstaller.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def PrintLiteServerConfig(local, args):
194194
def CreateLocalConfigFile(local, args):
195195
initBlock = GetInitBlock()
196196
initBlock_b64 = dict2b64(initBlock)
197-
user = local.buffer["user"]
198197
args = ["python3", "-m", "mytoninstaller", "-u", local.buffer.user, "-e", "clc", "-i", initBlock_b64]
199198
run_as_root(args)
200199
#end define

0 commit comments

Comments
 (0)