From b6dfff0ea3066cfb35dc1ba152141e29dc60e721 Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 19 Mar 2024 14:38:41 +0700 Subject: [PATCH 1/4] change GetStake --- mytoncore/mytoncore.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index aff64285..48f8647a 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -1316,7 +1316,6 @@ def GetStake(self, account, args=None): # Limit stake to maximum available amount minus 10 (for transaction fees) if stake > account.balance - 10: stake = account.balance - 10 - #end if pool_version = self.GetVersionFromCodeHash(account.codeHash) is_single_nominator = pool_version is not None and 'spool' in pool_version @@ -1331,9 +1330,10 @@ def GetStake(self, account, args=None): self.local.add_log("Wrong stakePercent value. Using default stake.", "warning") elif len(vconfig.validators) == 0: stake = int(account.balance*sp/2) + if stake < config17["minStake"]: # not enough funds to divide them by 2 + stake = int(account.balance*sp) elif len(vconfig.validators) > 0: stake = int(account.balance*sp) - #end if # Check if we have enough coins if stake > config17["maxStake"]: @@ -1348,10 +1348,8 @@ def GetStake(self, account, args=None): text = "Don't have enough coins. stake: {stake}, account balance: {balance}".format(stake=stake, balance=account.balance) # self.local.add_log(text, "error") raise Exception(text) - #end if return stake - #end define def GetMaxFactor(self): # Either use defined maxFactor, or set maximal allowed by config17 From 92eb83b0a505eafe260c67302ae78a08e1dc088c Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 19 Mar 2024 19:37:02 +0700 Subject: [PATCH 2/4] check user before launch --- mytonctrl/mytonctrl.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 6628a5a9..0adf7a3c 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -176,13 +176,27 @@ def inject_globals(func): local.db.config.logLevel = "debug" if console.debug else "info" local.db.config.isLocaldbSaving = False local.run() -#end define + + +def check_installer_user(): + args = ["whoami"] + process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) + username = process.stdout.decode("utf-8").strip() + + args = ["ls", "-lh", "/var/ton-work/keys/"] + process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3) + output = process.stdout.decode("utf-8") + actual_user = output.split('\n')[1].split()[2] + + if username != actual_user: + raise Exception(f'mytonctrl was installed by another user. Probably you need to launch mtc with `{actual_user}` user.') + def PreUp(local, ton): CheckMytonctrlUpdate(local) + check_installer_user() check_vport(local, ton) # CheckTonUpdate() -#end define def Installer(args): # args = ["python3", "/usr/src/mytonctrl/mytoninstaller.py"] @@ -208,7 +222,7 @@ def GetAuthorRepoBranchFromArgs(args): if arg2: data["branch"] = arg2 return data -#end define + def check_vport(local, ton): try: @@ -222,7 +236,6 @@ def check_vport(local, ton): result = client_socket.connect_ex((ip, addr.port)) if result != 0: color_print(local.translate("vport_error")) -#end define def fix_git_config(git_path: str): From 8951d924e14523ffa9a2dff319a59ba5d5910952 Mon Sep 17 00:00:00 2001 From: yungwine Date: Wed, 20 Mar 2024 22:25:55 +0800 Subject: [PATCH 3/4] return comments --- mytonctrl/mytonctrl.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 0adf7a3c..e087225d 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -190,6 +190,7 @@ def check_installer_user(): if username != actual_user: raise Exception(f'mytonctrl was installed by another user. Probably you need to launch mtc with `{actual_user}` user.') +#end define def PreUp(local, ton): @@ -197,6 +198,8 @@ def PreUp(local, ton): check_installer_user() check_vport(local, ton) # CheckTonUpdate() +#end define + def Installer(args): # args = ["python3", "/usr/src/mytonctrl/mytoninstaller.py"] @@ -204,6 +207,7 @@ def Installer(args): subprocess.run(args) #end define + def GetAuthorRepoBranchFromArgs(args): data = dict() arg1 = GetItemFromList(args, 0) @@ -222,6 +226,7 @@ def GetAuthorRepoBranchFromArgs(args): if arg2: data["branch"] = arg2 return data +#end define def check_vport(local, ton): @@ -236,6 +241,7 @@ def check_vport(local, ton): result = client_socket.connect_ex((ip, addr.port)) if result != 0: color_print(local.translate("vport_error")) +#end define def fix_git_config(git_path: str): From 506c4cc0edf2bad5c266d890eb70831ea48f3876 Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 21 Mar 2024 14:43:57 +0800 Subject: [PATCH 4/4] change default branch --- mytonctrl/mytonctrl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index e087225d..4a8c0f92 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -264,7 +264,8 @@ def check_git(input_args, default_repo, text): git_path = f"{src_dir}/{default_repo}" fix_git_config(git_path) default_author = "ton-blockchain" - default_branch = "master" + # default_branch = "master" + default_branch = "mytonctrl2" # Get author, repo, branch local_author, local_repo = get_git_author_and_repo(git_path)