From 2c01cc8697aeb4119659fcea1cd8e4823f96f6d4 Mon Sep 17 00:00:00 2001 From: ice-charon Date: Tue, 18 Feb 2025 12:45:17 +0200 Subject: [PATCH 1/3] Do not try to cast NoneType to int Signed-off-by: ice-charon --- mytoncore/mytoncore.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 22d42bd7..c2b24136 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -874,10 +874,10 @@ def GetConfig32(self): self.local.add_log("start GetConfig32 function", "debug") config32 = Dict() result = self.liteClient.Run("getconfig 32") - config32["totalValidators"] = int(parse(result, "total:", ' ')) - config32["mainValidators"] = int(parse(result, "main:", ' ')) - config32["startWorkTime"] = int(parse(result, "utime_since:", ' ')) - config32["endWorkTime"] = int(parse(result, "utime_until:", ' ')) + config32["totalValidators"] = int(parse(result, "total:", ' ') or 0) + config32["mainValidators"] = int(parse(result, "main:", ' ') or 0) + config32["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) + config32["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) lines = result.split('\n') validators = list() for line in lines: @@ -885,9 +885,9 @@ def GetConfig32(self): validatorAdnlAddr = parse(line, "adnl_addr:x", ')') pubkey = parse(line, "pubkey:x", ')') try: - validatorWeight = int(parse(line, "weight:", ' ')) + validatorWeight = int(parse(line, "weight:", ' ') or 0) except ValueError: - validatorWeight = int(parse(line, "weight:", ')')) + validatorWeight = int(parse(line, "weight:", ')') or 0) buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -911,11 +911,11 @@ def GetConfig34(self): self.local.add_log("start GetConfig34 function", "debug") config34 = Dict() result = self.liteClient.Run("getconfig 34") - config34["totalValidators"] = int(parse(result, "total:", ' ')) - config34["mainValidators"] = int(parse(result, "main:", ' ')) - config34["startWorkTime"] = int(parse(result, "utime_since:", ' ')) - config34["endWorkTime"] = int(parse(result, "utime_until:", ' ')) - config34["totalWeight"] = int(parse(result, "total_weight:", ' ')) + config34["totalValidators"] = int(parse(result, "total:", ' ') or 0) + config34["mainValidators"] = int(parse(result, "main:", ' ') or 0) + config34["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) + config34["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) + config34["totalWeight"] = int(parse(result, "total_weight:", ' ') or 0) lines = result.split('\n') validators = list() for line in lines: @@ -923,9 +923,9 @@ def GetConfig34(self): validatorAdnlAddr = parse(line, "adnl_addr:x", ')') pubkey = parse(line, "pubkey:x", ')') try: - validatorWeight = int(parse(line, "weight:", ' ')) + validatorWeight = int(parse(line, "weight:", ' ') or 0) except ValueError: - validatorWeight = int(parse(line, "weight:", ')')) + validatorWeight = int(parse(line, "weight:", ')') or 0) buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -950,9 +950,9 @@ def GetConfig36(self): config36 = dict() try: result = self.liteClient.Run("getconfig 36") - config36["totalValidators"] = int(parse(result, "total:", ' ')) - config36["startWorkTime"] = int(parse(result, "utime_since:", ' ')) - config36["endWorkTime"] = int(parse(result, "utime_until:", ' ')) + config36["totalValidators"] = int(parse(result, "total:", ' ') or 0) + config36["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) + config36["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) lines = result.split('\n') validators = list() for line in lines: From d16be576682d2f488bc4a59341fe096211e71a04 Mon Sep 17 00:00:00 2001 From: ice-charon Date: Tue, 18 Feb 2025 12:55:26 +0200 Subject: [PATCH 2/3] Respect process error code when run fift Signed-off-by: ice-charon --- mytoncore/fift.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mytoncore/fift.py b/mytoncore/fift.py index 291b3707..6326e22b 100644 --- a/mytoncore/fift.py +++ b/mytoncore/fift.py @@ -19,7 +19,7 @@ def Run(self, args, **kwargs): process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout) output = process.stdout.decode("utf-8") err = process.stderr.decode("utf-8") - if len(err) > 0: + if process.returncode != 0 and len(err) > 0: self.local.add_log("args: {args}".format(args=args), "error") raise Exception("Fift error: {err}".format(err=err)) return output From 9a7e43111a485e1aa393b18b1f10f3f0abd47771 Mon Sep 17 00:00:00 2001 From: Maksim Kurbatov <94808996+yungwine@users.noreply.github.com> Date: Sat, 19 Apr 2025 20:40:24 +0100 Subject: [PATCH 3/3] Revert "Do not try to cast NoneType to int" --- mytoncore/mytoncore.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 8f66bc3b..00b1a7b2 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -903,10 +903,10 @@ def GetConfig32(self): self.local.add_log("start GetConfig32 function", "debug") config32 = Dict() result = self.liteClient.Run("getconfig 32") - config32["totalValidators"] = int(parse(result, "total:", ' ') or 0) - config32["mainValidators"] = int(parse(result, "main:", ' ') or 0) - config32["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) - config32["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) + config32["totalValidators"] = int(parse(result, "total:", ' ')) + config32["mainValidators"] = int(parse(result, "main:", ' ')) + config32["startWorkTime"] = int(parse(result, "utime_since:", ' ')) + config32["endWorkTime"] = int(parse(result, "utime_until:", ' ')) lines = result.split('\n') validators = list() for line in lines: @@ -914,9 +914,9 @@ def GetConfig32(self): validatorAdnlAddr = parse(line, "adnl_addr:x", ')') pubkey = parse(line, "pubkey:x", ')') try: - validatorWeight = int(parse(line, "weight:", ' ') or 0) + validatorWeight = int(parse(line, "weight:", ' ')) except ValueError: - validatorWeight = int(parse(line, "weight:", ')') or 0) + validatorWeight = int(parse(line, "weight:", ')')) buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -940,11 +940,11 @@ def GetConfig34(self): self.local.add_log("start GetConfig34 function", "debug") config34 = Dict() result = self.liteClient.Run("getconfig 34") - config34["totalValidators"] = int(parse(result, "total:", ' ') or 0) - config34["mainValidators"] = int(parse(result, "main:", ' ') or 0) - config34["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) - config34["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) - config34["totalWeight"] = int(parse(result, "total_weight:", ' ') or 0) + config34["totalValidators"] = int(parse(result, "total:", ' ')) + config34["mainValidators"] = int(parse(result, "main:", ' ')) + config34["startWorkTime"] = int(parse(result, "utime_since:", ' ')) + config34["endWorkTime"] = int(parse(result, "utime_until:", ' ')) + config34["totalWeight"] = int(parse(result, "total_weight:", ' ')) lines = result.split('\n') validators = list() for line in lines: @@ -952,9 +952,9 @@ def GetConfig34(self): validatorAdnlAddr = parse(line, "adnl_addr:x", ')') pubkey = parse(line, "pubkey:x", ')') try: - validatorWeight = int(parse(line, "weight:", ' ') or 0) + validatorWeight = int(parse(line, "weight:", ' ')) except ValueError: - validatorWeight = int(parse(line, "weight:", ')') or 0) + validatorWeight = int(parse(line, "weight:", ')')) buff = Dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -979,9 +979,9 @@ def GetConfig36(self): config36 = dict() try: result = self.liteClient.Run("getconfig 36") - config36["totalValidators"] = int(parse(result, "total:", ' ') or 0) - config36["startWorkTime"] = int(parse(result, "utime_since:", ' ') or 0) - config36["endWorkTime"] = int(parse(result, "utime_until:", ' ') or 0) + config36["totalValidators"] = int(parse(result, "total:", ' ')) + config36["startWorkTime"] = int(parse(result, "utime_since:", ' ')) + config36["endWorkTime"] = int(parse(result, "utime_until:", ' ')) lines = result.split('\n') validators = list() for line in lines: