From efbf35cfeb681d23a3fdccd87cd3df633ad27668 Mon Sep 17 00:00:00 2001 From: Igroman787 <27614297+igroman787@users.noreply.github.com> Date: Fri, 30 Jun 2023 00:05:50 +0300 Subject: [PATCH 1/4] update `mypylib` --- mypyconsole | 2 +- mypylib | 2 +- mytoncore.py | 813 +++++++++++++++------------------------- mytonctrl.py | 560 +++++++++++++-------------- mytoninstaller.py | 98 ++--- scripts/toninstaller.sh | 2 + translate.json | 8 +- 7 files changed, 655 insertions(+), 830 deletions(-) diff --git a/mypyconsole b/mypyconsole index 3538607e..a8e8969a 160000 --- a/mypyconsole +++ b/mypyconsole @@ -1 +1 @@ -Subproject commit 3538607e412598cace37232c5941673bcdc56ded +Subproject commit a8e8969a6cac6bf96a34655504278d273adad98a diff --git a/mypylib b/mypylib index 8727d55f..01a9219e 160000 --- a/mypylib +++ b/mypylib @@ -1 +1 @@ -Subproject commit 8727d55f87c56e70ff7d71e293f219136aef5f7c +Subproject commit 01a9219eee82d45ae9db56130058b1d762a61e44 diff --git a/mytoncore.py b/mytoncore.py index 01cf614e..a971fd8c 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -22,7 +22,8 @@ def __init__(self): def Run(self, cmd, **kwargs): index = kwargs.get("index") - timeout = kwargs.get("timeout", 3) + liteclient_timeout = local.db.liteclient_timeout if local.db.liteclient_timeout else 3 + timeout = kwargs.get("timeout", liteclient_timeout) useLocalLiteServer = kwargs.get("useLocalLiteServer", True) validatorStatus = self.ton.GetValidatorStatus() validatorOutOfSync = validatorStatus.get("outOfSync") @@ -44,7 +45,7 @@ def Run(self, cmd, **kwargs): output = process.stdout.decode("utf-8") err = process.stderr.decode("utf-8") if len(err) > 0: - local.AddLog("args: {args}".format(args=args), "error") + local.add_log("args: {args}".format(args=args), "error") raise Exception("LiteClient error: {err}".format(err=err)) return output #end define @@ -59,7 +60,8 @@ def __init__(self): #end define def Run(self, cmd, **kwargs): - timeout = kwargs.get("timeout", 3) + console_timeout = local.db.console_timeout if local.db.console_timeout else 3 + timeout = kwargs.get("timeout", console_timeout) if self.appPath is None or self.privKeyPath is None or self.pubKeyPath is None: raise Exception("ValidatorConsole error: Validator console is not settings") args = [self.appPath, "-k", self.privKeyPath, "-p", self.pubKeyPath, "-a", self.addr, "-v", "0", "--cmd", cmd] @@ -67,7 +69,7 @@ def Run(self, cmd, **kwargs): output = process.stdout.decode("utf-8") err = process.stderr.decode("utf-8") if len(err) > 0: - local.AddLog("args: {args}".format(args=args), "error") + local.add_log("args: {args}".format(args=args), "error") raise Exception("ValidatorConsole error: {err}".format(err=err)) return output #end define @@ -81,7 +83,8 @@ def __init__(self): #end define def Run(self, args, **kwargs): - timeout = kwargs.get("timeout", 3) + fift_timeout = local.db.fift_timeout if local.db.fift_timeout else 3 + timeout = kwargs.get("timeout", fift_timeout) for i in range(len(args)): args[i] = str(args[i]) includePath = self.libsPath + ':' + self.smartcontsPath @@ -90,7 +93,7 @@ def Run(self, args, **kwargs): output = process.stdout.decode("utf-8") err = process.stderr.decode("utf-8") if len(err) > 0: - local.AddLog("args: {args}".format(args=args), "error") + local.add_log("args: {args}".format(args=args), "error") raise Exception("Fift error: {err}".format(err=err)) return output #end define @@ -289,16 +292,16 @@ def Init(self): #end define def Refresh(self): - if self.dbFile: - local.dbLoad(self.dbFile) - else: - local.dbLoad() + #if self.dbFile: + # local.load_db(self.dbFile) + #else: + # local.load_db() if not self.walletsDir: - self.walletsDir = local.buffer.get("myWorkDir") + "wallets/" - self.contractsDir = local.buffer.get("myWorkDir") + "contracts/" - self.poolsDir = local.buffer.get("myWorkDir") + "pools/" - self.tempDir = local.buffer.get("myTempDir") + self.walletsDir = local.buffer.my_work_dir + "wallets/" + self.contractsDir = local.buffer.my_work_dir + "contracts/" + self.poolsDir = local.buffer.my_work_dir + "pools/" + self.tempDir = local.buffer.my_temp_dir self.nodeName = local.db.get("nodeName") if self.nodeName is None: @@ -333,22 +336,23 @@ def Refresh(self): #end if # Check config file - self.CheckConfigFile(fift, liteClient) + #self.CheckConfigFile(fift, liteClient) #end define def CheckConfigFile(self, fift, liteClient): - mconfigPath = local.buffer.get("localdbFileName") - backupPath = mconfigPath + ".backup" + mconfig_path = local.buffer.db_path + backup_path = mconfig_path + ".backup" if fift is None or liteClient is None: - local.AddLog("The config file is broken", "warning") - if os.path.isfile(backupPath): - local.AddLog("Restoring the configuration file", "info") - args = ["cp", backupPath, mconfigPath] + local.add_log("The config file is broken", "warning") + print(f"local.db: {local.db}") + if os.path.isfile(backup_path): + local.add_log("Restoring the configuration file", "info") + args = ["cp", backup_path, mconfig_path] subprocess.run(args) self.Refresh() - elif os.path.isfile(backupPath) == False: - local.AddLog("Create backup config file", "info") - args = ["cp", mconfigPath, backupPath] + elif os.path.isfile(backup_path) == False: + local.add_log("Create backup config file", "info") + args = ["cp", mconfig_path, backup_path] subprocess.run(args) #end define @@ -384,7 +388,7 @@ def GetVarFromWorkerOutput(self, text, search): #end define def GetSeqno(self, wallet): - local.AddLog("start GetSeqno function", "debug") + local.add_log("start GetSeqno function", "debug") cmd = "runmethodfull {addr} seqno".format(addr=wallet.addrB64) result = self.liteClient.Run(cmd) if "cannot run any methods" in result: @@ -393,13 +397,13 @@ def GetSeqno(self, wallet): return 0 seqno = self.GetVarFromWorkerOutput(result, "result") seqno = seqno.replace(' ', '') - seqno = Pars(seqno, '[', ']') + seqno = parse(seqno, '[', ']') seqno = int(seqno) return seqno #end define def GetAccount(self, inputAddr): - #local.AddLog("start GetAccount function", "debug") + #local.add_log("start GetAccount function", "debug") workchain, addr = self.ParseInputAddr(inputAddr) account = Account(workchain, addr) cmd = "getaccount {inputAddr}".format(inputAddr=inputAddr) @@ -422,15 +426,15 @@ def GetAccount(self, inputAddr): code = self.GetBody(code) data = self.GetBody(data) codeHash = self.GetCodeHash(code) - status = Pars(state, "account_", '\n') + status = parse(state, "account_", '\n') account.workchain = int(workchain) account.addr = xhex2hex(address) account.addrB64 = self.AddrFull2AddrB64(addrFull) account.addrFull = addrFull account.status = status account.balance = ng2g(value) - account.lt = Pars(result, "lt = ", ' ') - account.hash = Pars(result, "hash = ", '\n') + account.lt = parse(result, "lt = ", ' ') + account.hash = parse(result, "hash = ", '\n') account.codeHash = codeHash return account #end define @@ -444,7 +448,7 @@ def GetCodeHash(self, code): #end define def GetAccountHistory(self, account, limit): - local.AddLog("start GetAccountHistory function", "debug") + local.add_log("start GetAccountHistory function", "debug") addr = f"{account.workchain}:{account.addr}" lt = account.lt transHash = account.hash @@ -467,7 +471,7 @@ def LastTransDump(self, addr, lt, transHash, count=10): for key, item in data.items(): if "transaction #" not in key: continue - block_str = Pars(key, "from block ", ' ') + block_str = parse(key, "from block ", ' ') description = self.GetKeyFromDict(item, "description") type = self.GetVar(description, "trans_") time = self.GetVarFromDict(item, "time") @@ -574,7 +578,7 @@ def GetBody(self, buff): for item in arr: if "x{" not in item: continue - buff = Pars(item, '{', '}') + buff = parse(item, '{', '}') buff = buff.replace('_', '') if len(buff)%2 == 1: buff = "0" + buff @@ -592,7 +596,7 @@ def GetBodyFromDict(self, buff): for item in buff: if "x{" not in item: continue - buff = Pars(item, '{', '}') + buff = parse(item, '{', '}') buff = buff.replace('_', '') if len(buff)%2 == 1: buff = "0" + buff @@ -624,7 +628,7 @@ def GetDomainAddr(self, domainName): result = self.liteClient.Run(cmd) if "not found" in result: raise Exception("GetDomainAddr error: domain \"{domainName}\" not found".format(domainName=domainName)) - resolver = Pars(result, "next resolver", '\n') + resolver = parse(result, "next resolver", '\n') buff = resolver.replace(' ', '') buffList = buff.split('=') fullHexAddr = buffList[0] @@ -633,7 +637,7 @@ def GetDomainAddr(self, domainName): #end define def GetDomainEndTime(self, domainName): - local.AddLog("start GetDomainEndTime function", "debug") + local.add_log("start GetDomainEndTime function", "debug") buff = domainName.split('.') subdomain = buff.pop(0) dnsDomain = ".".join(buff) @@ -641,28 +645,28 @@ def GetDomainEndTime(self, domainName): cmd = "runmethodfull {addr} getexpiration \"{subdomain}\"".format(addr=dnsAddr, subdomain=subdomain) result = self.liteClient.Run(cmd) - result = Pars(result, "result:", '\n') - result = Pars(result, "[", "]") + result = parse(result, "result:", '\n') + result = parse(result, "[", "]") result = result.replace(' ', '') result = int(result) return result #end define def GetDomainAdnlAddr(self, domainName): - local.AddLog("start GetDomainAdnlAddr function", "debug") + local.add_log("start GetDomainAdnlAddr function", "debug") cmd = "dnsresolve {domainName} 1".format(domainName=domainName) result = self.liteClient.Run(cmd) lines = result.split('\n') for line in lines: if "adnl address" in line: - adnlAddr = Pars(line, "=", "\n") + adnlAddr = parse(line, "=", "\n") adnlAddr = adnlAddr.replace(' ', '') adnlAddr = adnlAddr return adnlAddr #end define def GetLocalWallet(self, walletName, version=None, subwallet=None): - local.AddLog("start GetLocalWallet function", "debug") + local.add_log("start GetLocalWallet function", "debug") if walletName is None: return None walletPath = self.walletsDir + walletName @@ -674,7 +678,7 @@ def GetLocalWallet(self, walletName, version=None, subwallet=None): #end define def GetWalletFromFile(self, filePath, version): - local.AddLog("start GetWalletFromFile function", "debug") + local.add_log("start GetWalletFromFile function", "debug") # Check input args if (".addr" in filePath): filePath = filePath.replace(".addr", '') @@ -693,7 +697,7 @@ def GetWalletFromFile(self, filePath, version): #end define def GetHighWalletFromFile(self, filePath, subwallet, version): - local.AddLog("start GetHighWalletFromFile function", "debug") + local.add_log("start GetHighWalletFromFile function", "debug") # Check input args if (".addr" in filePath): filePath = filePath.replace(".addr", '') @@ -725,7 +729,7 @@ def AddrFile2Object(self, object): #end define def WalletVersion2Wallet(self, wallet): - local.AddLog("start WalletVersion2Wallet function", "debug") + local.add_log("start WalletVersion2Wallet function", "debug") if wallet.version is not None: return walletsVersionList = self.GetWalletsVersionList() @@ -734,7 +738,7 @@ def WalletVersion2Wallet(self, wallet): if version is None: version = self.GetWalletVersionFromHash(account.codeHash) if version is None: - local.AddLog("Wallet version not found: " + wallet.addrB64, "warning") + local.add_log("Wallet version not found: " + wallet.addrB64, "warning") return #end if @@ -745,11 +749,11 @@ def WalletVersion2Wallet(self, wallet): def SetWalletVersion(self, addrB64, version): walletsVersionList = self.GetWalletsVersionList() walletsVersionList[addrB64] = version - local.dbSave() + #local.save_db() #end define def GetWalletVersionFromHash(self, inputHash): - local.AddLog("start GetWalletVersionFromHash function", "debug") + local.add_log("start GetWalletVersionFromHash function", "debug") arr = dict() arr["v1r1"] = "d670136510daff4fee1889b8872c4c1e89872ffa1fe58a23a5f5d99cef8edf32" arr["v1r2"] = "2705a31a7ac162295c8aed0761cc6e031ab65521dd7b4a14631099e02de99e18" @@ -783,7 +787,7 @@ def GetFullConfigAddr(self): return buff #end if - local.AddLog("start GetFullConfigAddr function", "debug") + local.add_log("start GetFullConfigAddr function", "debug") result = self.liteClient.Run("getconfig 0") configAddr_hex = self.GetVarFromWorkerOutput(result, "config_addr:x") fullConfigAddr = "-1:{configAddr_hex}".format(configAddr_hex=configAddr_hex) @@ -802,7 +806,7 @@ def GetFullElectorAddr(self): #end if # Get data - local.AddLog("start GetFullElectorAddr function", "debug") + local.add_log("start GetFullElectorAddr function", "debug") result = self.liteClient.Run("getconfig 1") electorAddr_hex = self.GetVarFromWorkerOutput(result, "elector_addr:x") fullElectorAddr = "-1:{electorAddr_hex}".format(electorAddr_hex=electorAddr_hex) @@ -820,7 +824,7 @@ def GetFullMinterAddr(self): return buff #end if - local.AddLog("start GetFullMinterAddr function", "debug") + local.add_log("start GetFullMinterAddr function", "debug") result = self.liteClient.Run("getconfig 2") minterAddr_hex = self.GetVarFromWorkerOutput(result, "minter_addr:x") fullMinterAddr = "-1:{minterAddr_hex}".format(minterAddr_hex=minterAddr_hex) @@ -838,7 +842,7 @@ def GetFullDnsRootAddr(self): return buff #end if - local.AddLog("start GetFullDnsRootAddr function", "debug") + local.add_log("start GetFullDnsRootAddr function", "debug") result = self.liteClient.Run("getconfig 4") dnsRootAddr_hex = self.GetVarFromWorkerOutput(result, "dns_root_addr:x") fullDnsRootAddr = "-1:{dnsRootAddr_hex}".format(dnsRootAddr_hex=dnsRootAddr_hex) @@ -856,12 +860,12 @@ def GetActiveElectionId(self, fullElectorAddr): return buff #end if - local.AddLog("start GetActiveElectionId function", "debug") + local.add_log("start GetActiveElectionId function", "debug") cmd = "runmethodfull {fullElectorAddr} active_election_id".format(fullElectorAddr=fullElectorAddr) result = self.liteClient.Run(cmd) activeElectionId = self.GetVarFromWorkerOutput(result, "result") activeElectionId = activeElectionId.replace(' ', '') - activeElectionId = Pars(activeElectionId, '[', ']') + activeElectionId = parse(activeElectionId, '[', ']') activeElectionId = int(activeElectionId) # Set buffer @@ -870,26 +874,26 @@ def GetActiveElectionId(self, fullElectorAddr): #end define def GetValidatorsElectedFor(self): - local.AddLog("start GetValidatorsElectedFor function", "debug") + local.add_log("start GetValidatorsElectedFor function", "debug") config15 = self.GetConfig15() return config15["validatorsElectedFor"] #end define def GetMinStake(self): - local.AddLog("start GetMinStake function", "debug") + local.add_log("start GetMinStake function", "debug") config17 = self.GetConfig17() return config17["minStake"] #end define def GetRootWorkchainEnabledTime(self): - local.AddLog("start GetRootWorkchainEnabledTime function", "debug") + local.add_log("start GetRootWorkchainEnabledTime function", "debug") config12 = self.GetConfig(12) enabledTime = config12["workchains"]["root"]["node"]["value"]["enabled_since"] return enabledTime #end define def GetTotalValidators(self): - local.AddLog("start GetTotalValidators function", "debug") + local.add_log("start GetTotalValidators function", "debug") config34 = self.GetConfig34() result = config34["totalValidators"] return result @@ -912,7 +916,7 @@ def GetInitBlock_new(self): #block = self.GetLastBlock() #cmd = f"gethead {block}" #result = self.liteClient.Run(cmd) - #seqno = Pars(result, "prev_key_block_seqno=", '\n') + #seqno = parse(result, "prev_key_block_seqno=", '\n') statesDir = "/var/ton-work/db/archive/states" os.chdir(statesDir) files = filter(os.path.isfile, os.listdir(statesDir)) @@ -933,7 +937,7 @@ def GetInitBlock(self): block = self.GetLastBlock() cmd = f"gethead {block}" result = self.liteClient.Run(cmd) - seqno = Pars(result, "prev_key_block_seqno=", '\n') + seqno = parse(result, "prev_key_block_seqno=", '\n') data = self.GetBlockHead(-1, 8000000000000000, seqno) return data #end define @@ -951,7 +955,7 @@ def GetBlock(self, workchain, shardchain, seqno): cmd = "byseqno {workchain}:{shardchain} {seqno}" cmd = cmd.format(workchain=workchain, shardchain=shardchain, seqno=seqno) result = self.liteClient.Run(cmd) - block_str = Pars(result, "block header of ", ' ') + block_str = parse(result, "block header of ", ' ') block = Block(block_str) return block #end define @@ -1033,30 +1037,30 @@ def GetValidatorStatus(self): return buff #end if - # local.AddLog("start GetValidatorStatus function", "debug") + # local.add_log("start GetValidatorStatus function", "debug") validatorStatus = dict() try: validatorStatus["isWorking"] = True result = self.validatorConsole.Run("getstats") - validatorStatus["unixtime"] = int(Pars(result, "unixtime", '\n')) - validatorStatus["masterchainblocktime"] = int(Pars(result, "masterchainblocktime", '\n')) - validatorStatus["stateserializermasterchainseqno"] = int(Pars(result, "stateserializermasterchainseqno", '\n')) - validatorStatus["shardclientmasterchainseqno"] = int(Pars(result, "shardclientmasterchainseqno", '\n')) - buff = Pars(result, "masterchainblock", '\n') + validatorStatus["unixtime"] = int(parse(result, "unixtime", '\n')) + validatorStatus["masterchainblocktime"] = int(parse(result, "masterchainblocktime", '\n')) + validatorStatus["stateserializermasterchainseqno"] = int(parse(result, "stateserializermasterchainseqno", '\n')) + validatorStatus["shardclientmasterchainseqno"] = int(parse(result, "shardclientmasterchainseqno", '\n')) + buff = parse(result, "masterchainblock", '\n') validatorStatus["masterchainblock"] = self.GVS_GetItemFromBuff(buff) - buff = Pars(result, "gcmasterchainblock", '\n') + buff = parse(result, "gcmasterchainblock", '\n') validatorStatus["gcmasterchainblock"] = self.GVS_GetItemFromBuff(buff) - buff = Pars(result, "keymasterchainblock", '\n') + buff = parse(result, "keymasterchainblock", '\n') validatorStatus["keymasterchainblock"] = self.GVS_GetItemFromBuff(buff) - buff = Pars(result, "rotatemasterchainblock", '\n') + buff = parse(result, "rotatemasterchainblock", '\n') validatorStatus["rotatemasterchainblock"] = self.GVS_GetItemFromBuff(buff) validatorStatus["transNum"] = local.buffer.get("transNum", -1) validatorStatus["blocksNum"] = local.buffer.get("blocksNum", -1) validatorStatus["masterBlocksNum"] = local.buffer.get("masterBlocksNum", -1) except Exception as ex: - local.AddLog(f"GetValidatorStatus warning: {ex}", "warning") + local.add_log(f"GetValidatorStatus warning: {ex}", "warning") validatorStatus["isWorking"] = False - validatorStatus["unixtime"] = GetTimestamp() + validatorStatus["unixtime"] = get_timestamp() validatorStatus["masterchainblocktime"] = 0 validatorStatus["outOfSync"] = validatorStatus["unixtime"] - validatorStatus["masterchainblocktime"] @@ -1086,7 +1090,7 @@ def GetConfig(self, configId): #end if text = "start GetConfig function ({})".format(configId) - local.AddLog(text, "debug") + local.add_log(text, "debug") cmd = "getconfig {configId}".format(configId=configId) result = self.liteClient.Run(cmd) start = result.find("ConfigParam") @@ -1125,22 +1129,22 @@ def GetConfig32(self): return buff #end if - local.AddLog("start GetConfig32 function", "debug") + local.add_log("start GetConfig32 function", "debug") config32 = dict() result = self.liteClient.Run("getconfig 32") - config32["totalValidators"] = int(Pars(result, "total:", ' ')) - config32["startWorkTime"] = int(Pars(result, "utime_since:", ' ')) - config32["endWorkTime"] = int(Pars(result, "utime_until:", ' ')) + config32["totalValidators"] = int(parse(result, "total:", ' ')) + config32["startWorkTime"] = int(parse(result, "utime_since:", ' ')) + config32["endWorkTime"] = int(parse(result, "utime_until:", ' ')) lines = result.split('\n') validators = list() for line in lines: if "public_key:" in line: - validatorAdnlAddr = Pars(line, "adnl_addr:x", ')') - pubkey = Pars(line, "pubkey:x", ')') + validatorAdnlAddr = parse(line, "adnl_addr:x", ')') + pubkey = parse(line, "pubkey:x", ')') if config32["totalValidators"] > 1: - validatorWeight = int(Pars(line, "weight:", ' ')) + validatorWeight = int(parse(line, "weight:", ' ')) else: - validatorWeight = int(Pars(line, "weight:", ')')) + validatorWeight = int(parse(line, "weight:", ')')) buff = dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -1161,23 +1165,23 @@ def GetConfig34(self): return buff #end if - local.AddLog("start GetConfig34 function", "debug") + local.add_log("start GetConfig34 function", "debug") config34 = dict() result = self.liteClient.Run("getconfig 34") - config34["totalValidators"] = int(Pars(result, "total:", ' ')) - config34["startWorkTime"] = int(Pars(result, "utime_since:", ' ')) - config34["endWorkTime"] = int(Pars(result, "utime_until:", ' ')) - config34["totalWeight"] = int(Pars(result, "total_weight:", ' ')) + config34["totalValidators"] = int(parse(result, "total:", ' ')) + 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: if "public_key:" in line: - validatorAdnlAddr = Pars(line, "adnl_addr:x", ')') - pubkey = Pars(line, "pubkey:x", ')') + validatorAdnlAddr = parse(line, "adnl_addr:x", ')') + pubkey = parse(line, "pubkey:x", ')') if config34["totalValidators"] > 1: - validatorWeight = int(Pars(line, "weight:", ' ')) + validatorWeight = int(parse(line, "weight:", ' ')) else: - validatorWeight = int(Pars(line, "weight:", ')')) + validatorWeight = int(parse(line, "weight:", ')')) buff = dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -1198,20 +1202,20 @@ def GetConfig36(self): return buff #end if - local.AddLog("start GetConfig36 function", "debug") + local.add_log("start GetConfig36 function", "debug") config36 = dict() try: result = self.liteClient.Run("getconfig 36") - config36["totalValidators"] = int(Pars(result, "total:", ' ')) - config36["startWorkTime"] = int(Pars(result, "utime_since:", ' ')) - config36["endWorkTime"] = int(Pars(result, "utime_until:", ' ')) + 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: if "public_key:" in line: - validatorAdnlAddr = Pars(line, "adnl_addr:x", ')') - pubkey = Pars(line, "pubkey:x", ')') - validatorWeight = Pars(line, "weight:", ' ') + validatorAdnlAddr = parse(line, "adnl_addr:x", ')') + pubkey = parse(line, "pubkey:x", ')') + validatorWeight = parse(line, "weight:", ' ') buff = dict() buff["adnlAddr"] = validatorAdnlAddr buff["pubkey"] = pubkey @@ -1228,21 +1232,21 @@ def GetConfig36(self): #end define def CreateNewKey(self): - local.AddLog("start CreateNewKey function", "debug") + local.add_log("start CreateNewKey function", "debug") result = self.validatorConsole.Run("newkey") - key = Pars(result, "created new key ", '\n') + key = parse(result, "created new key ", '\n') return key #end define def GetPubKeyBase64(self, key): - local.AddLog("start GetPubKeyBase64 function", "debug") + local.add_log("start GetPubKeyBase64 function", "debug") result = self.validatorConsole.Run("exportpub " + key) - validatorPubkey_b64 = Pars(result, "got public key: ", '\n') + validatorPubkey_b64 = parse(result, "got public key: ", '\n') return validatorPubkey_b64 #end define def GetPubKey(self, key): - local.AddLog("start GetPubKey function", "debug") + local.add_log("start GetPubKey function", "debug") pubkey_b64 = self.GetPubKeyBase64(key) buff = pubkey_b64.encode("utf-8") buff = base64.b64decode(buff) @@ -1253,7 +1257,7 @@ def GetPubKey(self, key): #end define def AddKeyToValidator(self, key, startWorkTime, endWorkTime): - local.AddLog("start AddKeyToValidator function", "debug") + local.add_log("start AddKeyToValidator function", "debug") output = False cmd = "addpermkey {key} {startWorkTime} {endWorkTime}".format(key=key, startWorkTime=startWorkTime, endWorkTime=endWorkTime) result = self.validatorConsole.Run(cmd) @@ -1263,7 +1267,7 @@ def AddKeyToValidator(self, key, startWorkTime, endWorkTime): #end define def AddKeyToTemp(self, key, endWorkTime): - local.AddLog("start AddKeyToTemp function", "debug") + local.add_log("start AddKeyToTemp function", "debug") output = False result = self.validatorConsole.Run("addtempkey {key} {key} {endWorkTime}".format(key=key, endWorkTime=endWorkTime)) if ("success" in result): @@ -1272,7 +1276,7 @@ def AddKeyToTemp(self, key, endWorkTime): #end define def AddAdnlAddrToValidator(self, adnlAddr): - local.AddLog("start AddAdnlAddrToValidator function", "debug") + local.add_log("start AddAdnlAddrToValidator function", "debug") output = False result = self.validatorConsole.Run("addadnl {adnlAddr} 0".format(adnlAddr=adnlAddr)) if ("success" in result): @@ -1286,7 +1290,7 @@ def GetAdnlAddr(self): #end define def AttachAdnlAddrToValidator(self, adnlAddr, key, endWorkTime): - local.AddLog("start AttachAdnlAddrToValidator function", "debug") + local.add_log("start AttachAdnlAddrToValidator function", "debug") output = False result = self.validatorConsole.Run("addvalidatoraddr {key} {adnlAddr} {endWorkTime}".format(adnlAddr=adnlAddr, key=key, endWorkTime=endWorkTime)) if ("success" in result): @@ -1295,11 +1299,11 @@ def AttachAdnlAddrToValidator(self, adnlAddr, key, endWorkTime): #end define def CreateConfigProposalRequest(self, offerHash, validatorIndex): - local.AddLog("start CreateConfigProposalRequest function", "debug") + local.add_log("start CreateConfigProposalRequest function", "debug") fileName = self.tempDir + self.nodeName + "proposal_validator-to-sign.req" args = ["config-proposal-vote-req.fif", "-i", validatorIndex, offerHash, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", '\n') + fileName = parse(result, "Saved to file ", '\n') resultList = result.split('\n') i = 0 start_index = 0 @@ -1313,11 +1317,11 @@ def CreateConfigProposalRequest(self, offerHash, validatorIndex): #end define def CreateComplaintRequest(self, electionId , complaintHash, validatorIndex): - local.AddLog("start CreateComplaintRequest function", "debug") + local.add_log("start CreateComplaintRequest function", "debug") fileName = self.tempDir + "complaint_validator-to-sign.req" args = ["complaint-vote-req.fif", validatorIndex, electionId, complaintHash, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", '\n') + fileName = parse(result, "Saved to file ", '\n') resultList = result.split('\n') i = 0 start_index = 0 @@ -1331,20 +1335,20 @@ def CreateComplaintRequest(self, electionId , complaintHash, validatorIndex): #end define def PrepareComplaint(self, electionId, inputFileName): - local.AddLog("start PrepareComplaint function", "debug") + local.add_log("start PrepareComplaint function", "debug") fileName = self.tempDir + "complaint-msg-body.boc" args = ["envelope-complaint.fif", electionId, inputFileName, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", ')') + fileName = parse(result, "Saved to file ", ')') return fileName #end define def CreateElectionRequest(self, wallet, startWorkTime, adnlAddr, maxFactor): - local.AddLog("start CreateElectionRequest function", "debug") + local.add_log("start CreateElectionRequest function", "debug") fileName = self.tempDir + self.nodeName + str(startWorkTime) + "_validator-to-sign.bin" args = ["validator-elect-req.fif", wallet.addrB64, startWorkTime, maxFactor, adnlAddr, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", '\n') + fileName = parse(result, "Saved to file ", '\n') resultList = result.split('\n') i = 0 start_index = 0 @@ -1358,25 +1362,25 @@ def CreateElectionRequest(self, wallet, startWorkTime, adnlAddr, maxFactor): #end define def GetValidatorSignature(self, validatorKey, var1): - local.AddLog("start GetValidatorSignature function", "debug") + local.add_log("start GetValidatorSignature function", "debug") cmd = "sign {validatorKey} {var1}".format(validatorKey=validatorKey, var1=var1) result = self.validatorConsole.Run(cmd) - validatorSignature = Pars(result, "got signature ", '\n') + validatorSignature = parse(result, "got signature ", '\n') return validatorSignature #end define def SignElectionRequestWithValidator(self, wallet, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor): - local.AddLog("start SignElectionRequestWithValidator function", "debug") + local.add_log("start SignElectionRequestWithValidator function", "debug") fileName = self.tempDir + self.nodeName + str(startWorkTime) + "_validator-query.boc" args = ["validator-elect-signed.fif", wallet.addrB64, startWorkTime, maxFactor, adnlAddr, validatorPubkey_b64, validatorSignature, fileName] result = self.fift.Run(args) - pubkey = Pars(result, "validator public key ", '\n') - fileName = Pars(result, "Saved to file ", '\n') + pubkey = parse(result, "validator public key ", '\n') + fileName = parse(result, "Saved to file ", '\n') return pubkey, fileName #end define def SignBocWithWallet(self, wallet, bocPath, dest, coins, **kwargs): - local.AddLog("start SignBocWithWallet function", "debug") + local.add_log("start SignBocWithWallet function", "debug") flags = kwargs.get("flags", list()) subwalletDefault = 698983191 + wallet.workchain # 0x29A9A317 + workchain subwallet = kwargs.get("subwallet", subwalletDefault) @@ -1393,7 +1397,7 @@ def SignBocWithWallet(self, wallet, bocPath, dest, coins, **kwargs): if bounceable == False and destAccount.status == "active": flags += ["-b"] text = "Find non-bounceable flag, but destination account already active. Using bounceable flag" - local.AddLog(text, "warning") + local.add_log(text, "warning") elif "-n" not in flags and bounceable == True and destAccount.status != "active": raise Exception("Find bounceable flag, but destination account is not active. Use non-bounceable address or flag -n") #end if @@ -1412,12 +1416,12 @@ def SignBocWithWallet(self, wallet, bocPath, dest, coins, **kwargs): if flags: args += flags result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", ")") + resultFilePath = parse(result, "Saved to file ", ")") return resultFilePath #end define def SendFile(self, filePath, wallet=None, **kwargs): - local.AddLog("start SendFile function: " + filePath, "debug") + local.add_log("start SendFile function: " + filePath, "debug") timeout = kwargs.get("timeout", 30) remove = kwargs.get("remove", True) duplicateSendfile = local.db.get("duplicateSendfile", True) @@ -1436,7 +1440,7 @@ def SendFile(self, filePath, wallet=None, **kwargs): #end define def WaitTransaction(self, wallet, timeout=30): - local.AddLog("start WaitTransaction function", "debug") + local.add_log("start WaitTransaction function", "debug") timesleep = 3 steps = timeout // timesleep for i in range(steps): @@ -1448,23 +1452,23 @@ def WaitTransaction(self, wallet, timeout=30): #end define def GetReturnedStake(self, fullElectorAddr, inputAddr): - local.AddLog("start GetReturnedStake function", "debug") + local.add_log("start GetReturnedStake function", "debug") workchain, addr = self.ParseInputAddr(inputAddr) cmd = f"runmethodfull {fullElectorAddr} compute_returned_stake 0x{addr}" result = self.liteClient.Run(cmd) returnedStake = self.GetVarFromWorkerOutput(result, "result") returnedStake = returnedStake.replace(' ', '') - returnedStake = Pars(returnedStake, '[', ']') + returnedStake = parse(returnedStake, '[', ']') returnedStake = ng2g(returnedStake) return returnedStake #end define def ProcessRecoverStake(self): - local.AddLog("start ProcessRecoverStake function", "debug") + local.add_log("start ProcessRecoverStake function", "debug") resultFilePath = self.tempDir + self.nodeName + "recover-query" args = ["recover-stake.fif", resultFilePath] result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", '\n') + resultFilePath = parse(result, "Saved to file ", '\n') return resultFilePath #end define @@ -1473,7 +1477,6 @@ def GetStake(self, account, args=None): usePool = local.db.get("usePool") stakePercent = local.db.get("stakePercent", 99) vconfig = self.GetValidatorConfig() - validators = vconfig.get("validators") config17 = self.GetConfig17() # Check if optional arguments have been passed to us @@ -1487,7 +1490,7 @@ def GetStake(self, account, args=None): # Stake was a number stake = int(desiredStake) else: - local.AddLog("Specified stake must be a percentage or whole number", "error") + local.add_log("Specified stake must be a percentage or whole number", "error") return # Limit stake to maximum available amount minus 10 (for transaction fees) @@ -1500,25 +1503,25 @@ def GetStake(self, account, args=None): if stake is None: sp = stakePercent / 100 if sp > 1 or sp < 0: - local.AddLog("Wrong stakePercent value. Using default stake.", "warning") - elif len(validators) == 0: + local.add_log("Wrong stakePercent value. Using default stake.", "warning") + elif len(vconfig.validators) == 0: stake = int(account.balance*sp/2) - elif len(validators) > 0: + elif len(vconfig.validators) > 0: stake = int(account.balance*sp) #end if # Check if we have enough coins if stake > config17["maxStake"]: text = "Stake is greater than the maximum value. Will be used the maximum stake." - local.AddLog(text, "warning") + local.add_log(text, "warning") stake = config17["maxStake"] if config17["minStake"] > stake: text = "Stake less than the minimum stake. Minimum stake: {minStake}".format(minStake=config17["minStake"]) - #local.AddLog(text, "error") + #local.add_log(text, "error") raise Exception(text) if stake > account.balance: text = "Don't have enough coins. stake: {stake}, account balance: {balance}".format(stake=stake, balance=account.balance) - #local.AddLog(text, "error") + #local.add_log(text, "error") raise Exception(text) #end if @@ -1536,7 +1539,7 @@ def GetMaxFactor(self): #end define def GetValidatorWallet(self, mode="stake"): - local.AddLog("start GetValidatorWallet function", "debug") + local.add_log("start GetValidatorWallet function", "debug") walletName = local.db.get("validatorWalletName") wallet = self.GetLocalWallet(walletName) return wallet @@ -1555,12 +1558,12 @@ def ElectionEntry(self, args=None): addrB64 = pool.addrB64 #end if - local.AddLog("start ElectionEntry function", "debug") + local.add_log("start ElectionEntry function", "debug") # Check if validator is not synchronized validatorStatus = self.GetValidatorStatus() validatorOutOfSync = validatorStatus.get("outOfSync") if validatorOutOfSync > 60: - local.AddLog("Validator is not synchronized", "error") + local.add_log("Validator is not synchronized", "error") return #end if @@ -1570,7 +1573,7 @@ def ElectionEntry(self, args=None): # Check if elections started if (startWorkTime == 0): - local.AddLog("Elections have not yet begun", "info") + local.add_log("Elections have not yet begun", "info") return #end if @@ -1586,7 +1589,7 @@ def ElectionEntry(self, args=None): # Check if election entry already completed entries = self.GetElectionEntries() if adnlAddr in entries: - local.AddLog("Elections entry already completed", "info") + local.add_log("Elections entry already completed", "info") return #end if @@ -1630,15 +1633,14 @@ def ElectionEntry(self, args=None): # Save vars to json file self.SaveElectionVarsToJsonFile(wallet=wallet, account=account, stake=stake, maxFactor=maxFactor, fullElectorAddr=fullElectorAddr, startWorkTime=startWorkTime, validatorsElectedFor=validatorsElectedFor, endWorkTime=endWorkTime, validatorKey=validatorKey, validatorPubkey_b64=validatorPubkey_b64, adnlAddr=adnlAddr, var1=var1, validatorSignature=validatorSignature, validatorPubkey=validatorPubkey) - local.AddLog("ElectionEntry completed. Start work time: " + str(startWorkTime)) + local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime)) #end define def GetValidatorKeyByTime(self, startWorkTime, endWorkTime): - local.AddLog("start GetValidatorKeyByTime function", "debug") + local.add_log("start GetValidatorKeyByTime function", "debug") # Check temp key vconfig = self.GetValidatorConfig() - validators = vconfig.get("validators") - for item in validators: + for item in vconfig.validators: if item.get("election_date") == startWorkTime: validatorKey_b64 = item.get("id") validatorKey = base64.b64decode(validatorKey_b64).hex() @@ -1659,18 +1661,18 @@ def RecoverStake(self): raise Exception("Validator wallet not found") #end if - local.AddLog("start RecoverStake function", "debug") + local.add_log("start RecoverStake function", "debug") fullElectorAddr = self.GetFullElectorAddr() returnedStake = self.GetReturnedStake(fullElectorAddr, wallet.addrB64) if returnedStake == 0: - local.AddLog("You have nothing on the return stake", "debug") + local.add_log("You have nothing on the return stake", "debug") return #end if resultFilePath = self.ProcessRecoverStake() resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullElectorAddr, 1) self.SendFile(resultFilePath, wallet) - local.AddLog("RecoverStake completed") + local.add_log("RecoverStake completed") #end define def PoolRecoverStake(self, poolAddr): @@ -1679,15 +1681,15 @@ def PoolRecoverStake(self, poolAddr): raise Exception("Validator wallet not found") #end if - local.AddLog("start PoolRecoverStake function", "debug") + local.add_log("start PoolRecoverStake function", "debug") resultFilePath = self.PoolProcessRecoverStake() resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, poolAddr, 1.2) self.SendFile(resultFilePath, wallet) - local.AddLog("PoolRecoverStake completed") + local.add_log("PoolRecoverStake completed") #end define def PoolsUpdateValidatorSet(self): - local.AddLog("start PoolsUpdateValidatorSet function", "debug") + local.add_log("start PoolsUpdateValidatorSet function", "debug") wallet = self.GetValidatorWallet() pools = self.GetPools() for pool in pools: @@ -1695,7 +1697,7 @@ def PoolsUpdateValidatorSet(self): #end define def PoolUpdateValidatorSet(self, pool, wallet): - local.AddLog("start PoolUpdateValidatorSet function", "debug") + local.add_log("start PoolUpdateValidatorSet function", "debug") poolAddr = pool.addrB64 poolData = self.GetPoolData(poolAddr) if poolData is None: @@ -1726,32 +1728,32 @@ def PoolUpdateValidatorSet(self, pool, wallet): #end define def PoolProcessUpdateValidatorSet(self, poolAddr, wallet): - local.AddLog("start PoolProcessUpdateValidatorSet function", "debug") + local.add_log("start PoolProcessUpdateValidatorSet function", "debug") resultFilePath = self.tempDir + "pool-update-validator-set-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/update-validator-set.fif" args = [fiftScript, resultFilePath] result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", '\n') + resultFilePath = parse(result, "Saved to file ", '\n') resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, poolAddr, 1.1) self.SendFile(resultFilePath, wallet) - local.AddLog("PoolProcessUpdateValidatorSet completed") + local.add_log("PoolProcessUpdateValidatorSet completed") #end define def PoolWithdrawRequests(self, pool, wallet): - local.AddLog("start PoolWithdrawRequests function", "debug") + local.add_log("start PoolWithdrawRequests function", "debug") resultFilePath = self.PoolProcessWihtdrawRequests() resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, pool.addrB64, 10) self.SendFile(resultFilePath, wallet) - local.AddLog("PoolWithdrawRequests completed") + local.add_log("PoolWithdrawRequests completed") #end define def PoolProcessWihtdrawRequests(self): - local.AddLog("start PoolProcessWihtdrawRequests function", "debug") + local.add_log("start PoolProcessWihtdrawRequests function", "debug") resultFilePath = self.tempDir + "pool-withdraw-requests-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/process-withdraw-requests.fif" args = [fiftScript, resultFilePath] result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", '\n') + resultFilePath = parse(result, "Saved to file ", '\n') return resultFilePath #end define @@ -1767,7 +1769,7 @@ def HasPoolWithdrawRequests(self, pool): #end define def SaveElectionVarsToJsonFile(self, **kwargs): - local.AddLog("start SaveElectionVarsToJsonFile function", "debug") + local.add_log("start SaveElectionVarsToJsonFile function", "debug") fileName = self.tempDir + self.nodeName + str(kwargs.get("startWorkTime")) + "_ElectionEntry.json" wallet = kwargs.get("wallet") account = kwargs.get("account") @@ -1782,12 +1784,12 @@ def SaveElectionVarsToJsonFile(self, **kwargs): #ned define def CreateWallet(self, name, workchain=0, version="v1", **kwargs): - local.AddLog("start CreateWallet function", "debug") + local.add_log("start CreateWallet function", "debug") subwalletDefault = 698983191 + workchain # 0x29A9A317 + workchain subwallet = kwargs.get("subwallet", subwalletDefault) walletPath = self.walletsDir + name if os.path.isfile(walletPath + ".pk") and "v3" not in version: - local.AddLog("CreateWallet error: Wallet already exists: " + name, "warning") + local.add_log("CreateWallet error: Wallet already exists: " + name, "warning") else: if "v1" in version: fiftScript = "new-wallet.fif" @@ -1812,10 +1814,10 @@ def CreateHighWallet(self, name, **kwargs): subwalletDefault = 698983191 + workchain # 0x29A9A317 + workchain subwallet = kwargs.get("subwallet", subwalletDefault) version = kwargs.get("version", "hv1") - local.AddLog("start CreateHighWallet function", "debug") + local.add_log("start CreateHighWallet function", "debug") walletPath = self.walletsDir + name if os.path.isfile(walletPath + ".pk") and os.path.isfile(walletPath + str(subwallet) + ".addr"): - local.AddLog("CreateHighWallet error: Wallet already exists: " + name + str(subwallet), "warning") + local.add_log("CreateHighWallet error: Wallet already exists: " + name + str(subwallet), "warning") else: args = ["new-highload-wallet.fif", workchain, subwallet, walletPath] result = self.fift.Run(args) @@ -1828,12 +1830,12 @@ def CreateHighWallet(self, name, **kwargs): #end define def ActivateWallet(self, wallet): - local.AddLog("start ActivateWallet function", "debug") + local.add_log("start ActivateWallet function", "debug") account = self.GetAccount(wallet.addrB64) if account.status == "empty": raise Exception("ActivateWallet error: account status is empty") elif account.status == "active": - local.AddLog("ActivateWallet warning: account status is active", "warning") + local.add_log("ActivateWallet warning: account status is active", "warning") else: self.SendFile(wallet.bocFilePath, wallet, remove=False) #end define @@ -1869,7 +1871,7 @@ def ExportWallet(self, walletName): #end define def GetWalletsNameList(self): - local.AddLog("start GetWalletsNameList function", "debug") + local.add_log("start GetWalletsNameList function", "debug") walletsNameList = list() for fileName in os.listdir(self.walletsDir): if fileName.endswith(".addr"): @@ -1882,7 +1884,7 @@ def GetWalletsNameList(self): #end define def GetWallets(self): - local.AddLog("start GetWallets function", "debug") + local.add_log("start GetWallets function", "debug") wallets = list() walletsNameList = self.GetWalletsNameList() for walletName in walletsNameList: @@ -1892,7 +1894,7 @@ def GetWallets(self): #end define def GenerateWalletName(self): - local.AddLog("start GenerateWalletName function", "debug") + local.add_log("start GenerateWalletName function", "debug") index = 1 index_str = str(index).rjust(3, '0') walletPrefix = "wallet_" @@ -1914,7 +1916,7 @@ def GenerateWalletName(self): #end define def WalletsCheck(self): - local.AddLog("start WalletsCheck function", "debug") + local.add_log("start WalletsCheck function", "debug") wallets = self.GetWallets() for wallet in wallets: if os.path.isfile(wallet.bocFilePath): @@ -1924,16 +1926,16 @@ def WalletsCheck(self): #end define def GetValidatorConfig(self): - local.AddLog("start GetValidatorConfig function", "debug") + #local.add_log("start GetValidatorConfig function", "debug") result = self.validatorConsole.Run("getconfig") - text = Pars(result, "---------", "--------") + text = parse(result, "---------", "--------") vconfig = json.loads(text) - return vconfig + return Dict(vconfig) #end define def GetOverlaysStats(self): - local.AddLog("start GetOverlaysStats function", "debug") - resultFilePath = local.buffer.get("myTempDir") + "getoverlaysstats.json" + local.add_log("start GetOverlaysStats function", "debug") + resultFilePath = local.buffer.my_temp_dir + "getoverlaysstats.json" result = self.validatorConsole.Run(f"getoverlaysstatsjson {resultFilePath}") if "wrote stats" not in result: raise Exception(f"GetOverlaysStats error: {result}") @@ -1951,13 +1953,13 @@ def GetWalletId(self, wallet): result = self.GetVarFromWorkerOutput(result, "result") if result is None or "error" in result: return subwalletDefault - subwallet = Pars(result, '[', ']') + subwallet = parse(result, '[', ']') subwallet = int(subwallet) return subwallet #end define def MoveCoins(self, wallet, dest, coins, **kwargs): - local.AddLog("start MoveCoins function", "debug") + local.add_log("start MoveCoins function", "debug") flags = kwargs.get("flags", list()) timeout = kwargs.get("timeout", 30) subwallet = kwargs.get("subwallet") @@ -1988,13 +1990,13 @@ def MoveCoins(self, wallet, dest, coins, **kwargs): if bounceable == False and destAccount.status == "active": flags += ["-b"] text = "Find non-bounceable flag, but destination account already active. Using bounceable flag" - local.AddLog(text, "warning") + local.add_log(text, "warning") elif "-n" not in flags and bounceable == True and destAccount.status != "active": raise Exception("Find bounceable flag, but destination account is not active. Use non-bounceable address or flag -n") #end if seqno = self.GetSeqno(wallet) - resultFilePath = local.buffer.get("myTempDir") + wallet.name + "_wallet-query" + resultFilePath = local.buffer.my_temp_dir + wallet.name + "_wallet-query" if "v1" in wallet.version: fiftScript = "wallet.fif" args = [fiftScript, wallet.path, dest, seqno, coins, "-m", mode, resultFilePath] @@ -2007,12 +2009,12 @@ def MoveCoins(self, wallet, dest, coins, **kwargs): if flags: args += flags result = self.fift.Run(args) - savedFilePath = Pars(result, "Saved to file ", ")") + savedFilePath = parse(result, "Saved to file ", ")") self.SendFile(savedFilePath, wallet, timeout=timeout) #end define def MoveCoinsThroughProxy(self, wallet, dest, coins): - local.AddLog("start MoveCoinsThroughProxy function", "debug") + local.add_log("start MoveCoinsThroughProxy function", "debug") wallet1 = self.CreateWallet("proxy_wallet1", 0) wallet2 = self.CreateWallet("proxy_wallet2", 0) self.MoveCoins(wallet, wallet1.addrB64_init, coins) @@ -2025,16 +2027,16 @@ def MoveCoinsThroughProxy(self, wallet, dest, coins): #end define def MoveCoinsFromHW(self, wallet, destList, **kwargs): - local.AddLog("start MoveCoinsFromHW function", "debug") + local.add_log("start MoveCoinsFromHW function", "debug") flags = kwargs.get("flags") timeout = kwargs.get("timeout", 30) if len(destList) == 0: - local.AddLog("MoveCoinsFromHW warning: destList is empty, break function", "warning") + local.add_log("MoveCoinsFromHW warning: destList is empty, break function", "warning") return #end if - orderFilePath = local.buffer.get("myTempDir") + wallet.name + "_order.txt" + orderFilePath = local.buffer.my_temp_dir + wallet.name + "_order.txt" lines = list() for dest, coins in destList: lines.append("SEND {dest} {coins}".format(dest=dest, coins=coins)) @@ -2048,23 +2050,22 @@ def MoveCoinsFromHW(self, wallet, destList, **kwargs): elif "v2" in wallet.version: fiftScript = "highload-wallet-v2.fif" seqno = self.GetSeqno(wallet) - resultFilePath = local.buffer.get("myTempDir") + wallet.name + "_wallet-query" + resultFilePath = local.buffer.my_temp_dir + wallet.name + "_wallet-query" args = [fiftScript, wallet.path, wallet.subwallet, seqno, orderFilePath, resultFilePath] if flags: args += flags result = self.fift.Run(args) - savedFilePath = Pars(result, "Saved to file ", ")") + savedFilePath = parse(result, "Saved to file ", ")") self.SendFile(savedFilePath, wallet, timeout=timeout) #end define def GetValidatorKey(self): vconfig = self.GetValidatorConfig() - validators = vconfig["validators"] - for validator in validators: + for validator in vconfig.validators: validatorId = validator["id"] key_bytes = base64.b64decode(validatorId) validatorKey = key_bytes.hex().upper() - timestamp = GetTimestamp() + timestamp = get_timestamp() if timestamp > validator["election_date"]: return validatorKey raise Exception("GetValidatorKey error: validator key not found. Are you sure you are a validator?") @@ -2098,7 +2099,7 @@ def GetElectionEntries(self, past=False): #end if # Get raw data - local.AddLog("start GetElectionEntries function", "debug") + local.add_log("start GetElectionEntries function", "debug") cmd = "runmethodfull {fullElectorAddr} participant_list_extended".format(fullElectorAddr=fullElectorAddr) result = self.liteClient.Run(cmd) rawElectionEntries = self.Result2List(result) @@ -2139,7 +2140,7 @@ def GetElectionEntries(self, past=False): #end define def GetSaveElections(self): - timestamp = GetTimestamp() + timestamp = get_timestamp() saveElections = local.db.get("saveElections") if saveElections is None: saveElections = dict() @@ -2160,7 +2161,7 @@ def GetSaveElectionEntries(self, electionId): #end define def GetOffers(self): - local.AddLog("start GetOffers function", "debug") + local.add_log("start GetOffers function", "debug") fullConfigAddr = self.GetFullConfigAddr() # Get raw data cmd = "runmethodfull {fullConfigAddr} list_proposals".format(fullConfigAddr=fullConfigAddr) @@ -2212,7 +2213,7 @@ def GetOffers(self): #end define def GetOfferDiff(self, offerHash): - local.AddLog("start GetOfferDiff function", "debug") + local.add_log("start GetOfferDiff function", "debug") offer = self.GetOffer(offerHash) configId = offer["config"]["id"] configValue = offer["config"]["value"] @@ -2309,7 +2310,7 @@ def GetComplaints(self, electionId=None, past=False): #end if # Get raw data - local.AddLog("start GetComplaints function", "debug") + local.add_log("start GetComplaints function", "debug") cmd = "runmethodfull {fullElectorAddr} list_complaints {electionId}".format(fullElectorAddr=fullElectorAddr, electionId=electionId) result = self.liteClient.Run(cmd) rawComplaints = self.Result2List(result) @@ -2376,7 +2377,7 @@ def GetComplaints(self, electionId=None, past=False): #end define def GetSaveComplaints(self): - timestamp = GetTimestamp() + timestamp = get_timestamp() saveComplaints = local.db.get("saveComplaints") if type(saveComplaints) is not dict: saveComplaints = dict() @@ -2400,7 +2401,7 @@ def GetAdnlFromPubkey(self, inputPubkey): #end define def GetComplaintsNumber(self): - local.AddLog("start GetComplaintsNumber function", "debug") + local.add_log("start GetComplaintsNumber function", "debug") result = dict() complaints = self.GetComplaints() votedComplaints = self.GetVotedComplaints() @@ -2418,7 +2419,7 @@ def GetComplaintsNumber(self): #end define def GetComplaint(self, electionId, complaintHash): - local.AddLog("start GetComplaint function", "debug") + local.add_log("start GetComplaint function", "debug") complaints = self.GetComplaints(electionId) for key, item in complaints.items(): if complaintHash == item.get("hash"): @@ -2427,25 +2428,25 @@ def GetComplaint(self, electionId, complaintHash): #end define def SignProposalVoteRequestWithValidator(self, offerHash, validatorIndex, validatorPubkey_b64, validatorSignature): - local.AddLog("start SignProposalVoteRequestWithValidator function", "debug") + local.add_log("start SignProposalVoteRequestWithValidator function", "debug") fileName = self.tempDir + self.nodeName + "proposal_vote-msg-body.boc" args = ["config-proposal-vote-signed.fif", "-i", validatorIndex, offerHash, validatorPubkey_b64, validatorSignature, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", '\n') + fileName = parse(result, "Saved to file ", '\n') return fileName #end define def SignComplaintVoteRequestWithValidator(self, complaintHash, electionId, validatorIndex, validatorPubkey_b64, validatorSignature): - local.AddLog("start SignComplaintRequestWithValidator function", "debug") + local.add_log("start SignComplaintRequestWithValidator function", "debug") fileName = self.tempDir + "complaint_vote-msg-body.boc" args = ["complaint-vote-signed.fif", validatorIndex, electionId, complaintHash, validatorPubkey_b64, validatorSignature, fileName] result = self.fift.Run(args) - fileName = Pars(result, "Saved to file ", '\n') + fileName = parse(result, "Saved to file ", '\n') return fileName #end define def VoteOffer(self, offerHash): - local.AddLog("start VoteOffer function", "debug") + local.add_log("start VoteOffer function", "debug") fullConfigAddr = self.GetFullConfigAddr() wallet = self.GetValidatorWallet(mode="vote") validatorKey = self.GetValidatorKey() @@ -2453,7 +2454,7 @@ def VoteOffer(self, offerHash): validatorIndex = self.GetValidatorIndex() offer = self.GetOffer(offerHash) if validatorIndex in offer.get("votedValidators"): - local.AddLog("Proposal already has been voted", "debug") + local.add_log("Proposal already has been voted", "debug") return var1 = self.CreateConfigProposalRequest(offerHash, validatorIndex) validatorSignature = self.GetValidatorSignature(validatorKey, var1) @@ -2464,7 +2465,7 @@ def VoteOffer(self, offerHash): #end define def VoteComplaint(self, electionId, complaintHash): - local.AddLog("start VoteComplaint function", "debug") + local.add_log("start VoteComplaint function", "debug") complaintHash = int(complaintHash) fullElectorAddr = self.GetFullElectorAddr() wallet = self.GetValidatorWallet(mode="vote") @@ -2475,7 +2476,7 @@ def VoteComplaint(self, electionId, complaintHash): votedValidators = complaint.get("votedValidators") pubkey = complaint.get("pubkey") if validatorIndex in votedValidators: - local.AddLog("Complaint already has been voted", "info") + local.add_log("Complaint already has been voted", "info") return var1 = self.CreateComplaintRequest(electionId, complaintHash, validatorIndex) validatorSignature = self.GetValidatorSignature(validatorKey, var1) @@ -2486,7 +2487,7 @@ def VoteComplaint(self, electionId, complaintHash): #end define def SaveComplaints(self, electionId): - local.AddLog("start SaveComplaints function", "debug") + local.add_log("start SaveComplaints function", "debug") filePrefix = self.tempDir + "scheck_" cmd = "savecomplaints {electionId} {filePrefix}".format(electionId=electionId, filePrefix=filePrefix) result = self.liteClient.Run(cmd) @@ -2506,7 +2507,7 @@ def SaveComplaints(self, electionId): #end define def CheckComplaint(self, filePath): - local.AddLog("start CheckComplaint function", "debug") + local.add_log("start CheckComplaint function", "debug") cmd = "loadproofcheck {filePath}".format(filePath=filePath) result = self.liteClient.Run(cmd, timeout=30) lines = result.split('\n') @@ -2542,7 +2543,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False): #end if text = "start GetValidatorsLoad function ({}, {})".format(start, end) - local.AddLog(text, "debug") + local.add_log(text, "debug") if saveCompFiles is True: filePrefix = self.tempDir + f"checkload_{start}_{end}" else: @@ -2624,7 +2625,7 @@ def GetValidatorsList(self, past=False): return buff #end if - timestamp = GetTimestamp() + timestamp = get_timestamp() end = timestamp - 60 start = end - 2000 config = self.GetConfig34() @@ -2655,7 +2656,7 @@ def GetValidatorsList(self, past=False): #end define def CheckValidators(self, start, end): - local.AddLog("start CheckValidators function", "debug") + local.add_log("start CheckValidators function", "debug") electionId = start complaints = self.GetComplaints(electionId) data = self.GetValidatorsLoad(start, end, saveCompFiles=True) @@ -2682,11 +2683,11 @@ def CheckValidators(self, start, end): fileName = self.PrepareComplaint(electionId, fileName) fileName = self.SignBocWithWallet(wallet, fileName, fullElectorAddr, 300) self.SendFile(fileName, wallet) - local.AddLog("var1: {}, var2: {}, pubkey: {}, election_id: {}".format(var1, var2, pubkey, electionId), "debug") + local.add_log("var1: {}, var2: {}, pubkey: {}, election_id: {}".format(var1, var2, pubkey, electionId), "debug") #end define def GetOffer(self, offerHash): - local.AddLog("start GetOffer function", "debug") + local.add_log("start GetOffer function", "debug") offers = self.GetOffers() for offer in offers: if offerHash == offer.get("hash"): @@ -2695,7 +2696,7 @@ def GetOffer(self, offerHash): #end define def GetOffersNumber(self): - local.AddLog("start GetOffersNumber function", "debug") + local.add_log("start GetOffersNumber function", "debug") result = dict() offers = self.GetOffers() saveOffers = self.GetSaveOffers() @@ -2721,12 +2722,12 @@ def GetValidatorIndex(self, adnlAddr=None): if adnlAddr == searchAdnlAddr: return index index += 1 - local.AddLog("GetValidatorIndex warning: index not found.", "warning") + local.add_log("GetValidatorIndex warning: index not found.", "warning") return -1 #end define def GetValidatorEfficiency(self, adnlAddr=None): - local.AddLog("start GetValidatorEfficiency function", "debug") + local.add_log("start GetValidatorEfficiency function", "debug") validators = self.GetValidatorsList() if adnlAddr is None: adnlAddr = self.GetAdnlAddr() @@ -2735,7 +2736,7 @@ def GetValidatorEfficiency(self, adnlAddr=None): if adnlAddr == searchAdnlAddr: efficiency = validator.get("efficiency") return efficiency - local.AddLog("GetValidatorEfficiency warning: efficiency not found.", "warning") + local.add_log("GetValidatorEfficiency warning: efficiency not found.", "warning") #end define def GetDbUsage(self): @@ -2745,7 +2746,7 @@ def GetDbUsage(self): #end define def GetDbSize(self, exceptions="log"): - local.AddLog("start GetDbSize function", "debug") + local.add_log("start GetDbSize function", "debug") exceptions = exceptions.split() totalSize = 0 path = "/var/ton-work/" @@ -2762,7 +2763,7 @@ def GetDbSize(self, exceptions="log"): #end define def Result2List(self, text): - buff = Pars(text, "result:", "\n") + buff = parse(text, "result:", "\n") if buff is None or "error" in buff: return buff = buff.replace(')', ']') @@ -2897,7 +2898,7 @@ def GetItemFromDict(self, data, search): #end define def NewDomain(self, domain): - local.AddLog("start NewDomain function", "debug") + local.add_log("start NewDomain function", "debug") domainName = domain["name"] buff = domainName.split('.') subdomain = buff.pop(0) @@ -2916,7 +2917,7 @@ def NewDomain(self, domain): fileName = self.tempDir + "dns-msg-body.boc" args = ["auto-dns.fif", dnsAddr, "add", subdomain, expireInSec, "owner", wallet.addrB64, "cat", catId, "adnl", domain["adnlAddr"], "-o", fileName] result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", ')') + resultFilePath = parse(result, "Saved to file ", ')') resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, dnsAddr, 1.7) self.SendFile(resultFilePath, wallet) self.AddDomain(domain) @@ -2927,7 +2928,7 @@ def AddDomain(self, domain): local.db["domains"] = list() #end if local.db["domains"].append(domain) - local.dbSave() + #local.save_db() #end define def GetDomains(self): @@ -2951,7 +2952,7 @@ def DeleteDomain(self, domainName): for domain in domains: if (domainName == domain.get("name")): domains.remove(domain) - local.dbSave() + #local.save_db() return raise Exception("DeleteDomain error: Domain not found") #end define @@ -2967,7 +2968,7 @@ def GetAutoTransferRules(self): def AddAutoTransferRule(self, rule): autoTransferRules = self.GetAutoTransferRules() autoTransferRules.append(rule) - local.dbSave() + #local.save_db() #end define def AddBookmark(self, bookmark): @@ -2975,7 +2976,7 @@ def AddBookmark(self, bookmark): local.db["bookmarks"] = list() #end if local.db["bookmarks"].append(bookmark) - local.dbSave() + #local.save_db() #end define def GetBookmarks(self): @@ -3004,7 +3005,7 @@ def DeleteBookmark(self, name, type): bookmarkName = bookmark.get("name") if (type == bookmarkType and name == bookmarkName): bookmarks.remove(bookmark) - local.dbSave() + #local.save_db() return raise Exception("DeleteBookmark error: Bookmark not found") #end define @@ -3024,7 +3025,7 @@ def WriteBookmarkData(self, bookmark): if endTime == 0: data = "free" else: - data = Timestamp2Datetime(endTime, "%d.%m.%Y") + data = timestamp2datetime(endTime, "%d.%m.%Y") else: data = "null" bookmark["data"] = data @@ -3045,7 +3046,7 @@ def AddSaveOffer(self, offer): saveOffers = self.GetSaveOffers() if offerHash not in saveOffers: saveOffers[offerHash] = offerPseudohash - local.dbSave() + #local.save_db() #end define def GetVotedComplaints(self): @@ -3062,7 +3063,7 @@ def AddVotedComplaints(self, complaint): votedComplaints = self.GetVotedComplaints() if pseudohash not in votedComplaints: votedComplaints[pseudohash] = complaint - local.dbSave() + #local.save_db() #end define def GetDestinationAddr(self, destination): @@ -3128,7 +3129,7 @@ def ParseAddrB64(self, addrB64): networkTestnet = self.IsTestnet() if testnet != networkTestnet: text = f"ParseAddrB64 warning: testnet flag do not match. Addr: {testnet}, Network: {networkTestnet}" - local.AddLog(text, "warning") + local.add_log(text, "warning") #end if # get wc and addr @@ -3211,7 +3212,7 @@ def GetStatistics(self, name, statistics=None): #end define def GetSettings(self, name): - local.dbLoad() + #local.load_db() result = local.db.get(name) return result #end define @@ -3221,7 +3222,7 @@ def SetSettings(self, name, data): data = json.loads(data) except: pass local.db[name] = data - local.dbSave() + #local.save_db() #end define def Tlb2Json(self, text): @@ -3295,7 +3296,7 @@ def Tlb2Json(self, text): #end define def SignShardOverlayCert(self, adnl, pubkey): - local.AddLog("start SignShardOverlayCert function", "debug") + local.add_log("start SignShardOverlayCert function", "debug") fileName = self.tempDir + pubkey + ".cert" cmd = "signshardoverlaycert {workchain} {shardprefix} {pubkey} {expireat} {maxsize} {outfile}" cmd = cmd.format(workchain=-1, shardprefix=-9223372036854775808, pubkey=pubkey, expireat=172800, maxsize=8192, outfile=fileName) @@ -3317,7 +3318,7 @@ def SignShardOverlayCert(self, adnl, pubkey): #end define def ImportShardOverlayCert(self): - local.AddLog("start ImportShardOverlayCert function", "debug") + local.add_log("start ImportShardOverlayCert function", "debug") adnlAddr = self.GetAdnlAddr() pubkey = self.GetPubKey(adnlAddr) adnl = pubkey # adnl = adnlAddr @@ -3342,7 +3343,7 @@ def ImportShardOverlayCert(self): # Check certificate if cert is None: - local.AddLog("ImportShardOverlayCert warning: certificate not found", "warning") + local.add_log("ImportShardOverlayCert warning: certificate not found", "warning") return #end if @@ -3354,7 +3355,7 @@ def ImportShardOverlayCert(self): #end define def ImportCertificate(self, pubkey, fileName): - local.AddLog("start ImportCertificate function", "debug") + local.add_log("start ImportCertificate function", "debug") cmd = "importshardoverlaycert {workchain} {shardprefix} {pubkey} {certfile}" cmd = cmd.format(workchain=-1, shardprefix=-9223372036854775808, pubkey=pubkey, certfile=fileName) result = self.validatorConsole.Run(cmd) @@ -3370,7 +3371,7 @@ def GetValidatorsWalletsList(self): #end define def DownloadContract(self, url, branch=None): - local.AddLog("start DownloadContract function", "debug") + local.add_log("start DownloadContract function", "debug") buff = url.split('/') gitPath = self.contractsDir + buff[-1] + '/' @@ -3402,7 +3403,7 @@ def DownloadContract(self, url, branch=None): #end define def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, minValidatorStake, minNominatorStake): - local.AddLog("start CreatePool function", "debug") + local.add_log("start CreatePool function", "debug") validatorRewardShare = int(validatorRewardSharePercent * 100) contractPath = self.contractsDir + "nominator-pool/" if not os.path.isdir(contractPath): @@ -3411,7 +3412,7 @@ def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, filePath = self.poolsDir + poolName if os.path.isfile(filePath + ".addr"): - local.AddLog("CreatePool warning: Pool already exists: " + filePath, "warning") + local.add_log("CreatePool warning: Pool already exists: " + filePath, "warning") return #end if @@ -3433,7 +3434,7 @@ def CreatePool(self, poolName, validatorRewardSharePercent, maxNominatorsCount, #end define def ActivatePool(self, pool, ex=True): - local.AddLog("start ActivatePool function", "debug") + local.add_log("start ActivatePool function", "debug") for i in range(10): time.sleep(3) account = self.GetAccount(pool.addrB64) @@ -3446,7 +3447,7 @@ def ActivatePool(self, pool, ex=True): def DepositToPool(self, walletName, poolAddr, amount): wallet = self.GetLocalWallet(walletName) - bocPath = local.buffer.get("myTempDir") + wallet.name + "validator-deposit-query.boc" + bocPath = local.buffer.my_temp_dir + wallet.name + "validator-deposit-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/validator-deposit.fif" args = [fiftScript, bocPath] result = self.fift.Run(args) @@ -3463,9 +3464,9 @@ def WithdrawFromPool(self, walletName, poolAddr, amount): #end define def WithdrawFromPoolProcess(self, walletName, poolAddr, amount): - local.AddLog("start WithdrawFromPoolProcess function", "debug") + local.add_log("start WithdrawFromPoolProcess function", "debug") wallet = self.GetLocalWallet(walletName) - bocPath = local.buffer.get("myTempDir") + wallet.name + "validator-withdraw-query.boc" + bocPath = local.buffer.my_temp_dir + wallet.name + "validator-withdraw-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/validator-withdraw.fif" args = [fiftScript, amount, bocPath] result = self.fift.Run(args) @@ -3474,10 +3475,10 @@ def WithdrawFromPoolProcess(self, walletName, poolAddr, amount): #end define def PendWithdrawFromPool(self, walletName, poolAddr, amount): - local.AddLog("start PendWithdrawFromPool function", "debug") + local.add_log("start PendWithdrawFromPool function", "debug") pendingWithdraws = self.GetPendingWithdraws() pendingWithdraws[poolAddr] = (walletName, amount) - local.dbSave() + #local.save_db() #end define def HandlePendingWithdraw(self, pendingWithdraws, poolAddr): @@ -3496,28 +3497,28 @@ def GetPendingWithdraws(self): #end define def SignElectionRequestWithPoolWithValidator(self, pool, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor, stake): - local.AddLog("start SignElectionRequestWithPoolWithValidator function", "debug") + local.add_log("start SignElectionRequestWithPoolWithValidator function", "debug") fileName = self.tempDir + str(startWorkTime) + "_validator-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/validator-elect-signed.fif" args = [fiftScript, pool.addrB64, startWorkTime, maxFactor, adnlAddr, validatorPubkey_b64, validatorSignature, fileName, stake] result = self.fift.Run(args) - pubkey = Pars(result, "validator public key ", '\n') - fileName = Pars(result, "Saved to file ", '\n') + pubkey = parse(result, "validator public key ", '\n') + fileName = parse(result, "Saved to file ", '\n') return pubkey, fileName #end define def PoolProcessRecoverStake(self): - local.AddLog("start PoolProcessRecoverStake function", "debug") + local.add_log("start PoolProcessRecoverStake function", "debug") resultFilePath = self.tempDir + "recover-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/recover-stake.fif" args = [fiftScript, resultFilePath] result = self.fift.Run(args) - resultFilePath = Pars(result, "Saved to file ", '\n') + resultFilePath = parse(result, "Saved to file ", '\n') return resultFilePath #end define def GetLocalPool(self, poolName): - local.AddLog("start GetLocalPool function", "debug") + local.add_log("start GetLocalPool function", "debug") if poolName is None: return None filePath = self.poolsDir + poolName @@ -3533,7 +3534,7 @@ def GetLocalPool(self, poolName): #end define def GetPoolsNameList(self): - local.AddLog("start GetPoolsNameList function", "debug") + local.add_log("start GetPoolsNameList function", "debug") poolsNameList = list() for fileName in os.listdir(self.poolsDir): if fileName.endswith(".addr"): @@ -3544,7 +3545,7 @@ def GetPoolsNameList(self): #end define def GetPools(self): - local.AddLog("start GetPools function", "debug") + local.add_log("start GetPools function", "debug") pools = list() poolsNameList = self.GetPoolsNameList() for poolName in poolsNameList: @@ -3569,7 +3570,7 @@ def GetPoolLastSentStakeTime(self, addrB64): #end define def IsPoolReadyToStake(self, addrB64): - now = GetTimestamp() + now = get_timestamp() config15 = self.GetConfig15() lastSentStakeTime = self.GetPoolLastSentStakeTime(addrB64) stakeFreezeDelay = config15["validatorsElectedFor"] + config15["stakeHeldFor"] @@ -3585,7 +3586,7 @@ def IsPoolReadyToVote(self, addrB64): #end define def GetPoolData(self, addrB64): - local.AddLog("start GetPoolData function", "debug") + local.add_log("start GetPoolData function", "debug") cmd = f"runmethodfull {addrB64} get_pool_data" result = self.liteClient.Run(cmd) data = self.Result2List(result) @@ -3629,7 +3630,7 @@ def GetNetworkName(self): #end define def GetFunctionBuffer(self, name, timeout=10): - timestamp = GetTimestamp() + timestamp = get_timestamp() buff = local.buffer.get(name) if buff is None: return @@ -3643,7 +3644,7 @@ def GetFunctionBuffer(self, name, timeout=10): def SetFunctionBuffer(self, name, data): buff = dict() - buff["time"] = GetTimestamp() + buff["time"] = get_timestamp() buff["data"] = data local.buffer[name] = buff #end define @@ -3688,209 +3689,6 @@ def IsHash(self, inputHash): #end define #end class -class TonBlocksScanner(): - def __init__(self, ton, **kwargs): - self.ton = ton - self.prevMasterBlock = None - self.prevShardsBlock = dict() - self.blocksNum = 0 - self.transNum = 0 - self.nbr = kwargs.get("nbr") #NewBlockReaction - self.ntr = kwargs.get("ntr") #NewTransReaction - self.nmr = kwargs.get("nmr") #NewMessageReaction - self.local = kwargs.get("local") - self.sync = kwargs.get("sync", False) - self.delay = 0 - self.working = False - self.closing = False - #end define - - def Run(self): - self.StartThread(self.ScanBlocks, args=()) - self.StartThread(self.ThreadBalancing, args=()) - self.StartThread(self.StatusReading, args=()) - #end define - - def StartThread(self, func, args): - threading.Thread(target=func, args=args, name=func.__name__, daemon=True).start() - #end define - - def StartWithMode(self, func, args): - if self.sync: - func(*args) - else: - self.StartThread(func, args) - #end define - - def AddLog(self, text, type): - if self.local: - self.local.AddLog(text, type) - else: - print(text) - #end define - - def Try(self, func, **kwargs): - args = kwargs.get("args", tuple()) - for step in range(10): - time.sleep(step) - try: - result = func(*args) - return result - except Exception as ex: - err = ex - text = f"{func.__name__} step: {step}, error: {err}" - self.AddLog(text, "error") - raise Exception(err) - #end define - - def SetStartBlock(self, workchain, shardchain, seqno): - workchainType = type(workchain) - shardchainType = type(shardchain) - seqnoType = type(seqno) - if workchainType != int: - raise Exception(f"SetStartBlock error: workchain type mast be int, not {workchainType}") - if shardchainType != str: - raise Exception(f"SetStartBlock error: shardchain type mast be str, not {shardchainType}") - if seqnoType != int: - raise Exception(f"SetStartBlock error: seqno type mast be int, not {seqnoType}") - #end if - - block = Block() - block.workchain = workchain - block.shardchain = shardchain - block.seqno = seqno - if workchain == -1: - self.prevMasterBlock = block - else: - self.SetShardPrevBlock(block) - self.sync = True - #end define - - def ThreadBalancing(self): - while True: - tnum = threading.active_count() - if tnum > 100: - self.delay += 0.1 - elif tnum > 50: - self.delay += 0.01 - elif tnum < 50: - self.delay -= 0.1 - elif tnum < 100: - self.delay -= 0.01 - if self.delay < 0: - self.delay = 0 - if self.closing is True: - exit() - time.sleep(0.1) - #end define - - def StatusReading(self): - while True: - validatorStatus = self.ton.GetValidatorStatus() - validatorOutOfSync = validatorStatus.get("outOfSync") - if self.ton.liteClient.pubkeyPath is None: - self.working = False - self.closing = True - text = "TonBlocksScanner error: local liteserver is not configured, stop thread." - self.AddLog(text, "error") - exit() - if validatorOutOfSync > 20: - self.working = False - text = f"TonBlocksScanner warning: local liteserver is out of sync: {validatorOutOfSync}." - self.AddLog(text, "warning") - else: - self.working = True - time.sleep(10) - #end define - - def ScanBlocks(self): - while True: - if self.working is True: - self.ScanBlock() - if self.closing is True: - exit() - time.sleep(1) - #end define - - def ScanBlock(self): - block = self.Try(self.ton.GetLastBlock) - self.StartThread(self.SearchMissBlocks, args=(block, self.prevMasterBlock)) - if block != self.prevMasterBlock: - self.StartWithMode(self.ReadBlock, args=(block,)) - self.prevMasterBlock = block - #end define - - def ReadBlock(self, block): - self.StartWithMode(self.NewBlockReaction, args=(block,)) - shards = self.Try(self.ton.GetShards, args=(block,)) - for shard in shards: - self.StartThread(self.ReadShard, args=(shard,)) - #end define - - def ReadShard(self, shard): - block = shard.get("block") - prevBlock = self.GetShardPrevBlock(block.shardchain) - self.StartThread(self.SearchMissBlocks, args=(block, prevBlock)) - if block != prevBlock: - self.StartWithMode(self.NewBlockReaction, args=(block,)) - self.SetShardPrevBlock(block) - #end define - - def SearchMissBlocks(self, block, prevBlock): - if prevBlock is None: - return - diff = block.seqno - prevBlock.seqno - #for i in range(1, diff): - for i in range(diff-1, 0, -1): - workchain = block.workchain - shardchain = block.shardchain - seqno = block.seqno - i - self.StartWithMode(self.SearchBlock, args=(workchain, shardchain, seqno)) - #end define - - def SearchBlock(self, workchain, shardchain, seqno): - if self.delay != 0: - time.sleep(self.delay) - block = self.Try(self.ton.GetBlock, args=(workchain, shardchain, seqno)) - self.StartWithMode(self.NewBlockReaction, args=(block,)) - #end define - - def GetShardPrevBlock(self, shardchain): - prevBlock = self.prevShardsBlock.get(shardchain) - return prevBlock - #end define - - def SetShardPrevBlock(self, prevBlock): - self.prevShardsBlock[prevBlock.shardchain] = prevBlock - #end define - - def NewBlockReaction(self, block): - #print(f"{bcolors.green} block: {bcolors.endc} {block}") - self.blocksNum += 1 - if self.nbr: - self.StartThread(self.nbr, args=(block,)) - transactions = self.Try(self.ton.GetTransactions, args=(block,)) - for trans in transactions: - self.StartWithMode(self.NewTransReaction, args=(trans,)) - #end define - - def NewTransReaction(self, trans): - #print(f"{bcolors.magenta} trans: {bcolors.endc} {self.transNum}", "debug") - self.transNum += 1 - if self.ntr: - self.StartThread(self.ntr, args=(trans,)) - messageList = self.Try(self.ton.GetTrans, args=(trans,)) - for message in messageList: - self.NewMessageReaction(message) - #end define - - def NewMessageReaction(self, message): - if self.nmr: - self.StartThread(self.nmr, args=(message,)) - #print(f"{bcolors.yellow} message: {bcolors.endc} {message}") - #end define -#end class - def ng2g(ng): if ng is None: return @@ -3905,18 +3703,19 @@ def Init(): Event(eventName) #end if - local.Run() + local.run() # statistics - local.buffer["transData"] = dict() - local.buffer["network"] = [None]*15*6 - local.buffer["diskio"] = [None]*15*6 + local.buffer.blocksData = dict() + local.buffer.transData = dict() + local.buffer.network = [None]*15*6 + local.buffer.diskio = [None]*15*6 # scan blocks - local.buffer["masterBlocksList"] = list() - local.buffer["prevShardsBlock"] = dict() - local.buffer["blocksNum"] = 0 - local.buffer["transNum"] = 0 + local.buffer.masterBlocksList = list() + local.buffer.prevShardsBlock = dict() + local.buffer.blocksNum = 0 + local.buffer.transNum = 0 #end define def Event(eventName): @@ -3928,7 +3727,7 @@ def Event(eventName): #end define def EnableVcEvent(): - local.AddLog("start EnableVcEvent function", "debug") + local.add_log("start EnableVcEvent function", "debug") # Создать новый кошелек для валидатора ton = MyTonCore() wallet = ton.CreateWallet("validator_wallet_001", -1) @@ -3940,12 +3739,12 @@ def EnableVcEvent(): local.db["adnlAddr"] = adnlAddr # Сохранить - local.dbSave() + #local.save_db() #end define def ValidatorDownEvent(): - local.AddLog("start ValidatorDownEvent function", "debug") - local.AddLog("Validator is down", "error") + local.add_log("start ValidatorDownEvent function", "debug") + local.add_log("Validator is down", "error") #end define def Elections(ton): @@ -3969,7 +3768,7 @@ def Statistics(scanner): #end define def ReadDiskData(): - timestamp = GetTimestamp() + timestamp = get_timestamp() disks = GetDisksList() buff = psutil.disk_io_counters(perdisk=True) data = dict() @@ -3983,12 +3782,12 @@ def ReadDiskData(): data[name]["writeCount"] = buff[name].write_count #end for - local.buffer["diskio"].pop(0) - local.buffer["diskio"].append(data) + local.buffer.diskio.pop(0) + local.buffer.diskio.append(data) #end define def SaveDiskStatistics(): - data = local.buffer["diskio"] + data = local.buffer.diskio data = data[::-1] zerodata = data[0] buff1 = data[1*6-1] @@ -4058,8 +3857,8 @@ def GetDisksList(): #end define def ReadNetworkData(): - timestamp = GetTimestamp() - interfaceName = GetInternetInterfaceName() + timestamp = get_timestamp() + interfaceName = get_internet_interface_name() buff = psutil.net_io_counters(pernic=True) buff = buff[interfaceName] data = dict() @@ -4070,12 +3869,12 @@ def ReadNetworkData(): data["packetsSent"] = buff.packets_sent data["packetsRecv"] = buff.packets_recv - local.buffer["network"].pop(0) - local.buffer["network"].append(data) + local.buffer.network.pop(0) + local.buffer.network.append(data) #end define def SaveNetworkStatistics(): - data = local.buffer["network"] + data = local.buffer.network data = data[::-1] zerodata = data[0] buff1 = data[1*6-1] @@ -4120,7 +3919,7 @@ def CalculateNetworkStatistics(zerodata, data): #end define def ReadTransData(scanner): - transData = local.buffer.get("transData") + transData = local.buffer.transData SetToTimeData(transData, scanner.transNum) ShortTimeData(transData) #end define @@ -4175,13 +3974,13 @@ def GetItemFromTimeData(data, timeneed): def GetTps(timediff): - data = local.buffer["transData"] + data = local.buffer.transData tps = GetDataPerSecond(data, timediff) return tps #end define def GetBps(timediff): - data = local.buffer["blocksData"] + data = local.buffer.blocksData bps = GetDataPerSecond(data, timediff) return bps #end define @@ -4236,7 +4035,7 @@ def GetSwapInfo(): #end define def GetValidatorProcessInfo(): - pid = GetServicePid("validator") + pid = get_service_pid("validator") p = psutil.Process(pid) mem = p.memory_info() result = dict() @@ -4265,7 +4064,7 @@ def Telemetry(ton): data["adnlAddr"] = ton.GetAdnlAddr() data["validatorStatus"] = ton.GetValidatorStatus() data["cpuNumber"] = psutil.cpu_count() - data["cpuLoad"] = GetLoadAvg() + data["cpuLoad"] = get_load_avg() data["netLoad"] = ton.GetStatistics("netLoadAvg") data["tps"] = ton.GetStatistics("tpsAvg") data["disksLoad"] = ton.GetStatistics("disksLoadAvg") @@ -4277,15 +4076,19 @@ def Telemetry(ton): data["swap"] = GetSwapInfo() data["uname"] = GetUname() data["vprocess"] = GetValidatorProcessInfo() - elections = local.TryFunction(ton.GetElectionEntries) - complaints = local.TryFunction(ton.GetComplaints) + elections = local.try_function(ton.GetElectionEntries) + complaints = local.try_function(ton.GetComplaints) # Get git hashes gitHashes = dict() - gitHashes["mytonctrl"] = GetGitHash("/usr/src/mytonctrl") + gitHashes["mytonctrl"] = get_git_hash("/usr/src/mytonctrl") gitHashes["validator"] = GetBinGitHash("/usr/bin/ton/validator-engine/validator-engine") data["gitHashes"] = gitHashes data["stake"] = local.db.get("stake") + + # Get validator config + vconfig = self.GetValidatorConfig() + data["fullnode_adnl"] = vconfig.fullnode # Send data to toncenter server liteUrl_default = "https://telemetry.toncenter.com/report_status" @@ -4294,7 +4097,7 @@ def Telemetry(ton): resp = requests.post(liteUrl, data=output, timeout=3) #end define -def GetBinGitHash(path): +def GetBinGitHash(path, short=False): if not os.path.isfile(path): return args = [path, "--version"] @@ -4305,6 +4108,8 @@ def GetBinGitHash(path): buff = output.split(' ') start = buff.index("Commit:") + 1 result = buff[start].replace(',', '') + if short is True: + result = result[:7] return result #end define @@ -4351,15 +4156,15 @@ def Slashing(ton): #end if # Creating complaints - slashTime = local.buffer.get("slashTime") + slash_time = local.buffer.slash_time config32 = ton.GetConfig32() start = config32.get("startWorkTime") end = config32.get("endWorkTime") - local.AddLog("slashTime {}, start {}, end {}".format(slashTime, start, end), "debug") - if slashTime != start: + local.add_log("slash_time {}, start {}, end {}".format(slash_time, start, end), "debug") + if slash_time != start: end -= 60 ton.CheckValidators(start, end) - local.buffer["slashTime"] = start + local.buffer.slash_time = start #end define def ScanLiteServers(ton): @@ -4385,22 +4190,22 @@ def ScanLiteServers(ton): #end define def General(): - local.AddLog("start General function", "debug") + local.add_log("start General function", "debug") ton = MyTonCore() - scanner = TonBlocksScanner(ton, local=local) + scanner = Dict() #scanner.Run() # Запустить потоки - local.StartCycle(Elections, sec=600, args=(ton, )) - local.StartCycle(Statistics, sec=10, args=(scanner,)) - local.StartCycle(Offers, sec=600, args=(ton, )) - local.StartCycle(Complaints, sec=600, args=(ton, )) - local.StartCycle(Slashing, sec=600, args=(ton, )) - local.StartCycle(Domains, sec=600, args=(ton, )) - local.StartCycle(Telemetry, sec=60, args=(ton, )) - local.StartCycle(OverlayTelemetry, sec=7200, args=(ton, )) - local.StartCycle(ScanLiteServers, sec=60, args=(ton,)) - Sleep() + local.start_cycle(Elections, sec=600, args=(ton, )) + local.start_cycle(Statistics, sec=10, args=(scanner,)) + local.start_cycle(Offers, sec=600, args=(ton, )) + local.start_cycle(Complaints, sec=600, args=(ton, )) + local.start_cycle(Slashing, sec=600, args=(ton, )) + local.start_cycle(Domains, sec=600, args=(ton, )) + local.start_cycle(Telemetry, sec=60, args=(ton, )) + local.start_cycle(OverlayTelemetry, sec=7200, args=(ton, )) + local.start_cycle(ScanLiteServers, sec=60, args=(ton,)) + thr_sleep() #end define def Dec2HexAddr(dec): diff --git a/mytonctrl.py b/mytonctrl.py index 665755a7..ab90a066 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -12,63 +12,63 @@ def Init(argv): # Load translate table - local.InitTranslator(local.buffer.get("myDir") + "translate.json") + local.init_translator(local.buffer.my_dir + "translate.json") # Create user console console.name = "MyTonCtrl" console.startFunction = PreUp - console.AddItem("update", Update, local.Translate("update_cmd")) - console.AddItem("upgrade", Upgrade, local.Translate("upgrade_cmd")) - console.AddItem("installer", Installer, local.Translate("installer_cmd")) - console.AddItem("status", PrintStatus, local.Translate("status_cmd")) - console.AddItem("seqno", Seqno, local.Translate("seqno_cmd")) - console.AddItem("getconfig", GetConfig, local.Translate("getconfig_cmd")) - - console.AddItem("nw", CreatNewWallet, local.Translate("nw_cmd")) - console.AddItem("aw", ActivateWallet, local.Translate("aw_cmd")) - console.AddItem("wl", PrintWalletsList, local.Translate("wl_cmd")) - console.AddItem("iw", ImportWallet, local.Translate("iw_cmd")) - console.AddItem("swv", SetWalletVersion, local.Translate("swv_cmd")) - console.AddItem("ew", ExportWallet, local.Translate("ex_cmd")) - console.AddItem("dw", DeleteWallet, local.Translate("dw_cmd")) - - console.AddItem("vas", ViewAccountStatus, local.Translate("vas_cmd")) - console.AddItem("vah", ViewAccountHistory, local.Translate("vah_cmd")) - console.AddItem("mg", MoveCoins, local.Translate("mg_cmd")) - console.AddItem("mgtp", MoveCoinsThroughProxy, local.Translate("mgtp_cmd")) - - console.AddItem("nb", CreatNewBookmark, local.Translate("nb_cmd")) - console.AddItem("bl", PrintBookmarksList, local.Translate("bl_cmd")) - console.AddItem("db", DeleteBookmark, local.Translate("db_cmd")) - - console.AddItem("nd", NewDomain, local.Translate("nd_cmd")) - console.AddItem("dl", PrintDomainsList, local.Translate("dl_cmd")) - console.AddItem("vds", ViewDomainStatus, local.Translate("vds_cmd")) - console.AddItem("dd", DeleteDomain, local.Translate("dd_cmd")) - - console.AddItem("ol", PrintOffersList, local.Translate("ol_cmd")) - console.AddItem("vo", VoteOffer, local.Translate("vo_cmd")) - console.AddItem("od", OfferDiff, local.Translate("od_cmd")) - - console.AddItem("el", PrintElectionEntriesList, local.Translate("el_cmd")) - console.AddItem("ve", VoteElectionEntry, local.Translate("ve_cmd")) - console.AddItem("vl", PrintValidatorList, local.Translate("vl_cmd")) - console.AddItem("cl", PrintComplaintsList, local.Translate("cl_cmd")) - console.AddItem("vc", VoteComplaint, local.Translate("vc_cmd")) - - console.AddItem("get", GetSettings, local.Translate("get_cmd")) - console.AddItem("set", SetSettings, local.Translate("set_cmd")) - console.AddItem("xrestart", Xrestart, local.Translate("xrestart_cmd")) - console.AddItem("xlist", Xlist, local.Translate("xlist_cmd")) - - console.AddItem("new_pool", NewPool, local.Translate("new_pool_cmd")) - console.AddItem("pools_list", PrintPoolsList, local.Translate("pools_list_cmd")) - console.AddItem("get_pool_data", GetPoolData, local.Translate("get_pool_data_cmd")) - console.AddItem("activate_pool", ActivatePool, local.Translate("activate_pool_cmd")) - console.AddItem("deposit_to_pool", DepositToPool, local.Translate("deposit_to_pool_cmd")) - console.AddItem("withdraw_from_pool", WithdrawFromPool, local.Translate("withdraw_from_pool_cmd")) - console.AddItem("delete_pool", DeletePool, local.Translate("delete_pool_cmd")) + console.AddItem("update", Update, local.translate("update_cmd")) + console.AddItem("upgrade", Upgrade, local.translate("upgrade_cmd")) + console.AddItem("installer", Installer, local.translate("installer_cmd")) + console.AddItem("status", PrintStatus, local.translate("status_cmd")) + console.AddItem("seqno", Seqno, local.translate("seqno_cmd")) + console.AddItem("getconfig", GetConfig, local.translate("getconfig_cmd")) + + console.AddItem("nw", CreatNewWallet, local.translate("nw_cmd")) + console.AddItem("aw", ActivateWallet, local.translate("aw_cmd")) + console.AddItem("wl", PrintWalletsList, local.translate("wl_cmd")) + console.AddItem("iw", ImportWallet, local.translate("iw_cmd")) + console.AddItem("swv", SetWalletVersion, local.translate("swv_cmd")) + console.AddItem("ew", ExportWallet, local.translate("ex_cmd")) + console.AddItem("dw", DeleteWallet, local.translate("dw_cmd")) + + console.AddItem("vas", ViewAccountStatus, local.translate("vas_cmd")) + console.AddItem("vah", ViewAccountHistory, local.translate("vah_cmd")) + console.AddItem("mg", MoveCoins, local.translate("mg_cmd")) + console.AddItem("mgtp", MoveCoinsThroughProxy, local.translate("mgtp_cmd")) + + console.AddItem("nb", CreatNewBookmark, local.translate("nb_cmd")) + console.AddItem("bl", PrintBookmarksList, local.translate("bl_cmd")) + console.AddItem("db", DeleteBookmark, local.translate("db_cmd")) + + console.AddItem("nd", NewDomain, local.translate("nd_cmd")) + console.AddItem("dl", PrintDomainsList, local.translate("dl_cmd")) + console.AddItem("vds", ViewDomainStatus, local.translate("vds_cmd")) + console.AddItem("dd", DeleteDomain, local.translate("dd_cmd")) + + console.AddItem("ol", PrintOffersList, local.translate("ol_cmd")) + console.AddItem("vo", VoteOffer, local.translate("vo_cmd")) + console.AddItem("od", OfferDiff, local.translate("od_cmd")) + + console.AddItem("el", PrintElectionEntriesList, local.translate("el_cmd")) + console.AddItem("ve", VoteElectionEntry, local.translate("ve_cmd")) + console.AddItem("vl", PrintValidatorList, local.translate("vl_cmd")) + console.AddItem("cl", PrintComplaintsList, local.translate("cl_cmd")) + console.AddItem("vc", VoteComplaint, local.translate("vc_cmd")) + + console.AddItem("get", GetSettings, local.translate("get_cmd")) + console.AddItem("set", SetSettings, local.translate("set_cmd")) + console.AddItem("xrestart", Xrestart, local.translate("xrestart_cmd")) + console.AddItem("xlist", Xlist, local.translate("xlist_cmd")) + + console.AddItem("new_pool", NewPool, local.translate("new_pool_cmd")) + console.AddItem("pools_list", PrintPoolsList, local.translate("pools_list_cmd")) + console.AddItem("get_pool_data", GetPoolData, local.translate("get_pool_data_cmd")) + console.AddItem("activate_pool", ActivatePool, local.translate("activate_pool_cmd")) + console.AddItem("deposit_to_pool", DepositToPool, local.translate("deposit_to_pool_cmd")) + console.AddItem("withdraw_from_pool", WithdrawFromPool, local.translate("withdraw_from_pool_cmd")) + console.AddItem("delete_pool", DeletePool, local.translate("delete_pool_cmd")) # Process input parameters opts, args = getopt.getopt(argv,"hc:w:",["config=","wallets="]) @@ -95,13 +95,14 @@ def Init(argv): ton.walletsDir = wallets #end for - local.db["config"]["logLevel"] = "debug" - local.db["config"]["isLocaldbSaving"] = True - local.Run() + local.db.config.logLevel = "debug" + local.db.config.isLocaldbSaving = False + local.run() #end define def PreUp(): CheckMytonctrlUpdate() + check_vport() # CheckTonUpdate() #end define @@ -116,6 +117,52 @@ def GetItemFromList(data, index): except: pass #end define +def check_vport(): + vconfig = ton.GetValidatorConfig() + addr = vconfig.addrs.pop() + ip = int2ip(addr.ip) + with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client_socket: + result = client_socket.connect_ex((ip, addr.port)) + if result != 0: + color_print(local.translate("vport_error")) +#end define + +def check_git(input_args, default_repo): + src_dir = "/usr/src" + git_path = f"{src_dir}/{default_repo}" + default_author = "ton-blockchain" + default_branch = "master" + + # Get author, repo, branch + local_author, local_repo = get_git_author_and_repo(git_path) + local_branch = get_git_branch(git_path) + + # Set author, repo, branch + data = GetAuthorRepoBranchFromArgs(input_args) + need_author = data.get("author") + need_repo = data.get("repo") + need_branch = data.get("branch") + + # Check if remote repo is different from default + if ((need_author is None and local_author != default_author) or + (need_repo is None and local_repo != default_repo)): + remote_url = f"https://github.com/{local_author}/{local_repo}/tree/{need_branch if need_branch else local_branch}" + raise Exception(f"update error: You are on {remote_url} remote url, to update to the tip use `update {remote_url}` command") + elif need_branch is None and local_branch != default_branch: + raise Exception(f"update error: You are on {local_branch} branch, to update to the tip of {local_branch} branch use `update {local_branch}` command") + #end if + + if need_author is None: + need_author = local_author + if need_repo is None: + need_repo = local_repo + if need_branch is None: + need_branch = local_branch + #end if + + return need_author, need_repo, need_branch +#end define + def GetAuthorRepoBranchFromArgs(args): data = dict() arg1 = GetItemFromList(args, 0) @@ -137,76 +184,46 @@ def GetAuthorRepoBranchFromArgs(args): #end define def Update(args): - # add safe directory to git - gitPath = "/usr/src/mytonctrl" - subprocess.run(["git", "config", "--global", "--add", "safe.directory", gitPath]) - - # Get author, repo, branch - author, repo = GetGitAuthorAndRepo(gitPath) - branch = GetGitBranch(gitPath) - - # Set author, repo, branch - data = GetAuthorRepoBranchFromArgs(args) - author = data.get("author", author) - repo = data.get("repo", repo) - branch = data.get("branch", branch) + repo = "mytonctrl" + author, repo, branch = check_git(args, repo) # Run script runArgs = ["bash", "/usr/src/mytonctrl/scripts/update.sh", "-a", author, "-r", repo, "-b", branch] - exitCode = RunAsRoot(runArgs) + exitCode = run_as_root(runArgs) if exitCode == 0: text = "Update - {green}OK{endc}" else: text = "Update - {red}Error{endc}" - ColorPrint(text) - local.Exit() + color_print(text) + local.exit() #end define def Upgrade(args): - # add safe directory to git - gitPath = "/usr/src/ton" - subprocess.run(["git", "config", "--global", "--add", "safe.directory", gitPath]) - - # Get author, repo, branch - author, repo = GetGitAuthorAndRepo(gitPath) - branch = GetGitBranch(gitPath) - - # Set author, repo, branch - data = GetAuthorRepoBranchFromArgs(args) - author = data.get("author", author) - repo = data.get("repo", repo) - branch = data.get("branch", branch) + repo = "ton" + author, repo, branch = check_git(args, repo) # Run script runArgs = ["bash", "/usr/src/mytonctrl/scripts/upgrade.sh", "-a", author, "-r", repo, "-b", branch] - exitCode = RunAsRoot(runArgs) + exitCode = run_as_root(runArgs) if exitCode == 0: text = "Upgrade - {green}OK{endc}" else: text = "Upgrade - {red}Error{endc}" - ColorPrint(text) + color_print(text) #end define def CheckMytonctrlUpdate(): - gitPath = local.buffer.get("myDir") - result = CheckGitUpdate(gitPath) + git_path = local.buffer.my_dir + result = check_git_update(git_path) if result is True: - ColorPrint(local.Translate("mytonctrl_update_available")) + color_print(local.translate("mytonctrl_update_available")) #end define def CheckTonUpdate(): - gitPath = "/usr/src/ton" - result = CheckGitUpdate(gitPath) + git_path = "/usr/src/ton" + result = check_git_update(git_path) if result is True: - ColorPrint(local.Translate("ton_update_available")) -#end define - -def PrintTest(args): - print(json.dumps(local.buffer, indent=2)) -#end define - -def sl(args): - Slashing(ton) + color_print(local.translate("ton_update_available")) #end define def PrintStatus(args): @@ -267,28 +284,28 @@ def PrintTonStatus(startWorkTime, totalValidators, onlineValidators, shardsNumbe allOffers = offersNumber.get("all") newComplaints = complaintsNumber.get("new") allComplaints = complaintsNumber.get("all") - tps1_text = bcolors.Green(tps1) - tps5_text = bcolors.Green(tps5) - tps15_text = bcolors.Green(tps15) - tps_text = local.Translate("ton_status_tps").format(tps1_text, tps5_text, tps15_text) + tps1_text = bcolors.green_text(tps1) + tps5_text = bcolors.green_text(tps5) + tps15_text = bcolors.green_text(tps15) + tps_text = local.translate("ton_status_tps").format(tps1_text, tps5_text, tps15_text) onlineValidators_text = GetColorInt(onlineValidators, border=allValidators*2/3, logic="more") - allValidators_text = bcolors.Yellow(allValidators) - validators_text = local.Translate("ton_status_validators").format(onlineValidators_text, allValidators_text) - shards_text = local.Translate("ton_status_shards").format(bcolors.Green(shardsNumber)) - newOffers_text = bcolors.Green(newOffers) - allOffers_text = bcolors.Yellow(allOffers) - offers_text = local.Translate("ton_status_offers").format(newOffers_text, allOffers_text) - newComplaints_text = bcolors.Green(newComplaints) - allComplaints_text = bcolors.Yellow(allComplaints) - complaints_text = local.Translate("ton_status_complaints").format(newComplaints_text, allComplaints_text) + allValidators_text = bcolors.yellow_text(allValidators) + validators_text = local.translate("ton_status_validators").format(onlineValidators_text, allValidators_text) + shards_text = local.translate("ton_status_shards").format(bcolors.green_text(shardsNumber)) + newOffers_text = bcolors.green_text(newOffers) + allOffers_text = bcolors.yellow_text(allOffers) + offers_text = local.translate("ton_status_offers").format(newOffers_text, allOffers_text) + newComplaints_text = bcolors.green_text(newComplaints) + allComplaints_text = bcolors.yellow_text(allComplaints) + complaints_text = local.translate("ton_status_complaints").format(newComplaints_text, allComplaints_text) if startWorkTime == 0: - election_text = bcolors.Yellow("closed") + election_text = bcolors.yellow_text("closed") else: - election_text = bcolors.Green("open") - election_text = local.Translate("ton_status_election").format(election_text) + election_text = bcolors.green_text("open") + election_text = local.translate("ton_status_election").format(election_text) - ColorPrint(local.Translate("ton_status_head")) + color_print(local.translate("ton_status_head")) print(tps_text) print(validators_text) print(shards_text) @@ -304,7 +321,7 @@ def PrintLocalStatus(adnlAddr, validatorIndex, validatorEfficiency, validatorWal walletAddr = validatorWallet.addrB64 walletBalance = validatorAccount.balance cpuNumber = psutil.cpu_count() - loadavg = GetLoadAvg() + loadavg = get_load_avg() cpuLoad1 = loadavg[0] cpuLoad5 = loadavg[1] cpuLoad15 = loadavg[2] @@ -314,19 +331,19 @@ def PrintLocalStatus(adnlAddr, validatorIndex, validatorEfficiency, validatorWal validatorOutOfSync = validatorStatus.get("outOfSync") validatorIndex_text = GetColorInt(validatorIndex, 0, logic="more") - validatorIndex_text = local.Translate("local_status_validator_index").format(validatorIndex_text) + validatorIndex_text = local.translate("local_status_validator_index").format(validatorIndex_text) validatorEfficiency_text = GetColorInt(validatorEfficiency, 10, logic="more", ending=" %") - validatorEfficiency_text = local.Translate("local_status_validator_efficiency").format(validatorEfficiency_text) - adnlAddr_text = local.Translate("local_status_adnl_addr").format(bcolors.Yellow(adnlAddr)) - walletAddr_text = local.Translate("local_status_wallet_addr").format(bcolors.Yellow(walletAddr)) - walletBalance_text = local.Translate("local_status_wallet_balance").format(bcolors.Green(walletBalance)) + validatorEfficiency_text = local.translate("local_status_validator_efficiency").format(validatorEfficiency_text) + adnlAddr_text = local.translate("local_status_adnl_addr").format(bcolors.yellow_text(adnlAddr)) + walletAddr_text = local.translate("local_status_wallet_addr").format(bcolors.yellow_text(walletAddr)) + walletBalance_text = local.translate("local_status_wallet_balance").format(bcolors.green_text(walletBalance)) # CPU status - cpuNumber_text = bcolors.Yellow(cpuNumber) + cpuNumber_text = bcolors.yellow_text(cpuNumber) cpuLoad1_text = GetColorInt(cpuLoad1, cpuNumber, logic="less") cpuLoad5_text = GetColorInt(cpuLoad5, cpuNumber, logic="less") cpuLoad15_text = GetColorInt(cpuLoad15, cpuNumber, logic="less") - cpuLoad_text = local.Translate("local_status_cpu_load").format(cpuNumber_text, cpuLoad1_text, cpuLoad5_text, cpuLoad15_text) + cpuLoad_text = local.translate("local_status_cpu_load").format(cpuNumber_text, cpuLoad1_text, cpuLoad5_text, cpuLoad15_text) # Memory status ramUsage = memoryInfo.get("usage") @@ -341,20 +358,20 @@ def PrintLocalStatus(adnlAddr, validatorIndex, validatorEfficiency, validatorWal ramLoad_text = ramLoad_text.format(cyan=bcolors.cyan, default=bcolors.default, endc=bcolors.endc, data=ramUsage_text, percent=ramUsagePercent_text) swapLoad_text = "{cyan}swap:[{default}{data}, {percent}{cyan}]{endc}" swapLoad_text = swapLoad_text.format(cyan=bcolors.cyan, default=bcolors.default, endc=bcolors.endc, data=swapUsage_text, percent=swapUsagePercent_text) - memoryLoad_text = local.Translate("local_status_memory").format(ramLoad_text, swapLoad_text) + memoryLoad_text = local.translate("local_status_memory").format(ramLoad_text, swapLoad_text) # Network status netLoad1_text = GetColorInt(netLoad1, 300, logic="less") netLoad5_text = GetColorInt(netLoad5, 300, logic="less") netLoad15_text = GetColorInt(netLoad15, 300, logic="less") - netLoad_text = local.Translate("local_status_net_load").format(netLoad1_text, netLoad5_text, netLoad15_text) + netLoad_text = local.translate("local_status_net_load").format(netLoad1_text, netLoad5_text, netLoad15_text) # Disks status disksLoad_data = list() for key, item in disksLoadAvg.items(): - diskLoad1_text = bcolors.Green(item[0]) - diskLoad5_text = bcolors.Green(item[1]) - diskLoad15_text = bcolors.Green(item[2]) + diskLoad1_text = bcolors.green_text(item[0]) + diskLoad5_text = bcolors.green_text(item[1]) + diskLoad15_text = bcolors.green_text(item[2]) diskLoadPercent1_text = GetColorInt(disksLoadPercentAvg[key][0], 80, logic="less", ending="%") diskLoadPercent5_text = GetColorInt(disksLoadPercentAvg[key][1], 80, logic="less", ending="%") diskLoadPercent15_text = GetColorInt(disksLoadPercentAvg[key][2], 80, logic="less", ending="%") @@ -363,39 +380,40 @@ def PrintLocalStatus(adnlAddr, validatorIndex, validatorEfficiency, validatorWal disksLoad_buff = buff.format(diskLoad15_text, diskLoadPercent15_text) disksLoad_data.append(disksLoad_buff) disksLoad_data = ", ".join(disksLoad_data) - disksLoad_text = local.Translate("local_status_disks_load").format(disksLoad_data) + disksLoad_text = local.translate("local_status_disks_load").format(disksLoad_data) # Thread status - mytoncoreStatus_bool = GetServiceStatus("mytoncore") - validatorStatus_bool = GetServiceStatus("validator") - mytoncoreUptime = GetServiceUptime("mytoncore") - validatorUptime = GetServiceUptime("validator") - mytoncoreUptime_text = bcolors.Green(time2human(mytoncoreUptime)) - validatorUptime_text = bcolors.Green(time2human(validatorUptime)) + mytoncoreStatus_bool = get_service_status("mytoncore") + validatorStatus_bool = get_service_status("validator") + mytoncoreUptime = get_service_uptime("mytoncore") + validatorUptime = get_service_uptime("validator") + mytoncoreUptime_text = bcolors.green_text(time2human(mytoncoreUptime)) + validatorUptime_text = bcolors.green_text(time2human(validatorUptime)) mytoncoreStatus = GetColorStatus(mytoncoreStatus_bool) validatorStatus = GetColorStatus(validatorStatus_bool) - mytoncoreStatus_text = local.Translate("local_status_mytoncore_status").format(mytoncoreStatus, mytoncoreUptime_text) - validatorStatus_text = local.Translate("local_status_validator_status").format(validatorStatus, validatorUptime_text) - validatorOutOfSync_text = local.Translate("local_status_validator_out_of_sync").format(GetColorInt(validatorOutOfSync, 20, logic="less", ending=" s")) + mytoncoreStatus_text = local.translate("local_status_mytoncore_status").format(mytoncoreStatus, mytoncoreUptime_text) + validatorStatus_text = local.translate("local_status_validator_status").format(validatorStatus, validatorUptime_text) + validatorOutOfSync_text = local.translate("local_status_validator_out_of_sync").format(GetColorInt(validatorOutOfSync, 20, logic="less", ending=" s")) dbSize_text = GetColorInt(dbSize, 1000, logic="less", ending=" Gb") dbUsage_text = GetColorInt(dbUsage, 80, logic="less", ending="%") - dbStatus_text = local.Translate("local_status_db").format(dbSize_text, dbUsage_text) + dbStatus_text = local.translate("local_status_db").format(dbSize_text, dbUsage_text) # Mytonctrl and validator git hash mtcGitPath = "/usr/src/mytonctrl" validatorGitPath = "/usr/src/ton" - mtcGitHash = GetGitHash(mtcGitPath, short=True) - validatorGitHash = GetGitHash(validatorGitPath, short=True) - mtcGitBranch = GetGitBranch(mtcGitPath) - validatorGitBranch = GetGitBranch(validatorGitPath) - mtcGitHash_text = bcolors.Yellow(mtcGitHash) - validatorGitHash_text = bcolors.Yellow(validatorGitHash) - mtcGitBranch_text = bcolors.Yellow(mtcGitBranch) - validatorGitBranch_text = bcolors.Yellow(validatorGitBranch) - mtcVersion_text = local.Translate("local_status_version_mtc").format(mtcGitHash_text, mtcGitBranch_text) - validatorVersion_text = local.Translate("local_status_version_validator").format(validatorGitHash_text, validatorGitBranch_text) - - ColorPrint(local.Translate("local_status_head")) + validatorBinGitPath = "/usr/bin/ton/validator-engine/validator-engine" + mtcGitHash = get_git_hash(mtcGitPath, short=True) + validatorGitHash = GetBinGitHash(validatorBinGitPath, short=True) + mtcGitBranch = get_git_branch(mtcGitPath) + validatorGitBranch = get_git_branch(validatorGitPath) + mtcGitHash_text = bcolors.yellow_text(mtcGitHash) + validatorGitHash_text = bcolors.yellow_text(validatorGitHash) + mtcGitBranch_text = bcolors.yellow_text(mtcGitBranch) + validatorGitBranch_text = bcolors.yellow_text(validatorGitBranch) + mtcVersion_text = local.translate("local_status_version_mtc").format(mtcGitHash_text, mtcGitBranch_text) + validatorVersion_text = local.translate("local_status_version_validator").format(validatorGitHash_text, validatorGitBranch_text) + + color_print(local.translate("local_status_head")) print(validatorIndex_text) print(validatorEfficiency_text) print(adnlAddr_text) @@ -417,25 +435,25 @@ def PrintLocalStatus(adnlAddr, validatorIndex, validatorEfficiency, validatorWal def GetColorInt(data, border, logic, ending=None): if data is None: - result = bcolors.Green("n/a") + result = bcolors.green_text("n/a") elif logic == "more": if data >= border: - result = bcolors.Green(data, ending) + result = bcolors.green_text(data, ending) else: - result = bcolors.Red(data, ending) + result = bcolors.red_text(data, ending) elif logic == "less": if data <= border: - result = bcolors.Green(data, ending) + result = bcolors.green_text(data, ending) else: - result = bcolors.Red(data, ending) + result = bcolors.red_text(data, ending) return result #end define def GetColorStatus(input): if input == True: - result = bcolors.Green("working") + result = bcolors.green_text("working") else: - result = bcolors.Red("not working") + result = bcolors.red_text("not working") return result #end define @@ -447,18 +465,18 @@ def PrintTonConfig(fullConfigAddr, fullElectorAddr, config15, config17): minStake = config17["minStake"] maxStake = config17["maxStake"] - fullConfigAddr_text = local.Translate("ton_config_configurator_addr").format(bcolors.Yellow(fullConfigAddr)) - fullElectorAddr_text = local.Translate("ton_config_elector_addr").format(bcolors.Yellow(fullElectorAddr)) - validatorsElectedFor_text = bcolors.Yellow(validatorsElectedFor) - electionsStartBefore_text = bcolors.Yellow(electionsStartBefore) - electionsEndBefore_text = bcolors.Yellow(electionsEndBefore) - stakeHeldFor_text = bcolors.Yellow(stakeHeldFor) - elections_text = local.Translate("ton_config_elections").format(validatorsElectedFor_text, electionsStartBefore_text, electionsEndBefore_text, stakeHeldFor_text) - minStake_text = bcolors.Yellow(minStake) - maxStake_text = bcolors.Yellow(maxStake) - stake_text = local.Translate("ton_config_stake").format(minStake_text, maxStake_text) - - ColorPrint(local.Translate("ton_config_head")) + fullConfigAddr_text = local.translate("ton_config_configurator_addr").format(bcolors.yellow_text(fullConfigAddr)) + fullElectorAddr_text = local.translate("ton_config_elector_addr").format(bcolors.yellow_text(fullElectorAddr)) + validatorsElectedFor_text = bcolors.yellow_text(validatorsElectedFor) + electionsStartBefore_text = bcolors.yellow_text(electionsStartBefore) + electionsEndBefore_text = bcolors.yellow_text(electionsEndBefore) + stakeHeldFor_text = bcolors.yellow_text(stakeHeldFor) + elections_text = local.translate("ton_config_elections").format(validatorsElectedFor_text, electionsStartBefore_text, electionsEndBefore_text, stakeHeldFor_text) + minStake_text = bcolors.yellow_text(minStake) + maxStake_text = bcolors.yellow_text(maxStake) + stake_text = local.translate("ton_config_stake").format(minStake_text, maxStake_text) + + color_print(local.translate("ton_config_head")) print(fullConfigAddr_text) print(fullElectorAddr_text) print(elections_text) @@ -483,22 +501,22 @@ def PrintTimes(rootWorkchainEnabledTime_int, startWorkTime, oldStartWorkTime, co startNextElection = startElection + validatorsElectedFor # timestamp to datetime - rootWorkchainEnabledTime = Timestamp2Datetime(rootWorkchainEnabledTime_int) - startValidationTime = Timestamp2Datetime(startValidation) - endValidationTime = Timestamp2Datetime(endValidation) - startElectionTime = Timestamp2Datetime(startElection) - endElectionTime = Timestamp2Datetime(endElection) - startNextElectionTime = Timestamp2Datetime(startNextElection) + rootWorkchainEnabledTime = timestamp2datetime(rootWorkchainEnabledTime_int) + startValidationTime = timestamp2datetime(startValidation) + endValidationTime = timestamp2datetime(endValidation) + startElectionTime = timestamp2datetime(startElection) + endElectionTime = timestamp2datetime(endElection) + startNextElectionTime = timestamp2datetime(startNextElection) # datetime to color text - rootWorkchainEnabledTime_text = local.Translate("times_root_workchain_enabled_time").format(bcolors.Yellow(rootWorkchainEnabledTime)) - startValidationTime_text = local.Translate("times_start_validation_time").format(GetColorTime(startValidationTime, startValidation)) - endValidationTime_text = local.Translate("times_end_validation_time").format(GetColorTime(endValidationTime, endValidation)) - startElectionTime_text = local.Translate("times_start_election_time").format(GetColorTime(startElectionTime, startElection)) - endElectionTime_text = local.Translate("times_end_election_time").format(GetColorTime(endElectionTime, endElection)) - startNextElectionTime_text = local.Translate("times_start_next_election_time").format(GetColorTime(startNextElectionTime, startNextElection)) - - ColorPrint(local.Translate("times_head")) + rootWorkchainEnabledTime_text = local.translate("times_root_workchain_enabled_time").format(bcolors.yellow_text(rootWorkchainEnabledTime)) + startValidationTime_text = local.translate("times_start_validation_time").format(GetColorTime(startValidationTime, startValidation)) + endValidationTime_text = local.translate("times_end_validation_time").format(GetColorTime(endValidationTime, endValidation)) + startElectionTime_text = local.translate("times_start_election_time").format(GetColorTime(startElectionTime, startElection)) + endElectionTime_text = local.translate("times_end_election_time").format(GetColorTime(endElectionTime, endElection)) + startNextElectionTime_text = local.translate("times_start_next_election_time").format(GetColorTime(startNextElectionTime, startNextElection)) + + color_print(local.translate("times_head")) print(rootWorkchainEnabledTime_text) print(startValidationTime_text) print(endValidationTime_text) @@ -508,11 +526,11 @@ def PrintTimes(rootWorkchainEnabledTime_int, startWorkTime, oldStartWorkTime, co #end define def GetColorTime(datetime, timestamp): - newTimestamp = GetTimestamp() + newTimestamp = get_timestamp() if timestamp > newTimestamp: - result = bcolors.Green(datetime) + result = bcolors.green_text(datetime) else: - result = bcolors.Yellow(datetime) + result = bcolors.yellow_text(datetime) return result #end define @@ -520,7 +538,7 @@ def Seqno(args): try: walletName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} seqno ") + color_print("{red}Bad args. Usage:{endc} seqno ") return wallet = ton.GetLocalWallet(walletName) seqno = ton.GetSeqno(wallet) @@ -543,13 +561,13 @@ def CreatNewWallet(args): else: subwallet = 698983191 + workchain # 0x29A9A317 + workchain except: - ColorPrint("{red}Bad args. Usage:{endc} nw [ ]") + color_print("{red}Bad args. Usage:{endc} nw [ ]") return wallet = ton.CreateWallet(walletName, workchain, version, subwallet=subwallet) table = list() table += [["Name", "Workchain", "Address"]] table += [[wallet.name, wallet.workchain, wallet.addrB64_init]] - PrintTable(table) + print_table(table) #end define def ActivateWallet(args): @@ -562,10 +580,10 @@ def ActivateWallet(args): else: wallet = ton.GetLocalWallet(walletName) if not os.path.isfile(wallet.bocFilePath): - local.AddLog("Wallet {walletName} already activated".format(walletName=walletName), "warning") + local.add_log("Wallet {walletName} already activated".format(walletName=walletName), "warning") return ton.ActivateWallet(wallet) - ColorPrint("ActivateWallet - {green}OK{endc}") + color_print("ActivateWallet - {green}OK{endc}") #end define def PrintWalletsList(args): @@ -580,24 +598,24 @@ def PrintWalletsList(args): if account.status != "active": wallet.addrB64 = wallet.addrB64_init table += [[wallet.name, account.status, account.balance, wallet.version, wallet.workchain, wallet.addrB64]] - PrintTable(table) + print_table(table) #end define def ImportWalletFromFile(args): try: filePath = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} iw ") + color_print("{red}Bad args. Usage:{endc} iw ") return if (".addr" in filePath): filePath = filePath.replace(".addr", '') if (".pk" in filePath): filePath = filePath.replace(".pk", '') if os.path.isfile(filePath + ".addr") == False: - local.AddLog("ImportWalletFromFile error: Address file not found: " + filePath, "error") + local.add_log("ImportWalletFromFile error: Address file not found: " + filePath, "error") return if os.path.isfile(filePath + ".pk") == False: - local.AddLog("ImportWalletFromFile error: Private key not found: " + filePath, "error") + local.add_log("ImportWalletFromFile error: Private key not found: " + filePath, "error") return if '/' in filePath: walletName = filePath[filePath.rfind('/')+1:] @@ -605,7 +623,7 @@ def ImportWalletFromFile(args): walletName = filePath copyfile(filePath + ".addr", ton.walletsDir + walletName + ".addr") copyfile(filePath + ".pk", ton.walletsDir + walletName + ".pk") - ColorPrint("ImportWalletFromFile - {green}OK{endc}") + color_print("ImportWalletFromFile - {green}OK{endc}") #end define def ImportWallet(args): @@ -613,7 +631,7 @@ def ImportWallet(args): addr = args[0] key = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} iw ") + color_print("{red}Bad args. Usage:{endc} iw ") return name = ton.ImportWallet(addr, key) print("Wallet name:", name) @@ -624,17 +642,17 @@ def SetWalletVersion(args): addr = args[0] version = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} swv ") + color_print("{red}Bad args. Usage:{endc} swv ") return ton.SetWalletVersion(addr, version) - ColorPrint("SetWalletVersion - {green}OK{endc}") + color_print("SetWalletVersion - {green}OK{endc}") #end define def ExportWallet(args): try: name = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} ew ") + color_print("{red}Bad args. Usage:{endc} ew ") return addr, key = ton.ExportWallet(name) print("Wallet name:", name) @@ -646,18 +664,18 @@ def DeleteWallet(args): try: walletName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} dw ") + color_print("{red}Bad args. Usage:{endc} dw ") return wallet = ton.GetLocalWallet(walletName) wallet.Delete() - ColorPrint("DeleteWallet - {green}OK{endc}") + color_print("DeleteWallet - {green}OK{endc}") #end define def ViewAccountStatus(args): try: addrB64 = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} vas ") + color_print("{red}Bad args. Usage:{endc} vas ") return addrB64 = ton.GetDestinationAddr(addrB64) account = ton.GetAccount(addrB64) @@ -666,9 +684,9 @@ def ViewAccountStatus(args): statusTable += [["Address", "Status", "Version", "Balance"]] statusTable += [[addrB64, account.status, version, account.balance]] historyTable = GetHistoryTable(addrB64, 10) - PrintTable(statusTable) + print_table(statusTable) print() - PrintTable(historyTable) + print_table(historyTable) #end define def ViewAccountHistory(args): @@ -676,10 +694,10 @@ def ViewAccountHistory(args): addr = args[0] limit = int(args[1]) except: - ColorPrint("{red}Bad args. Usage:{endc} vah ") + color_print("{red}Bad args. Usage:{endc} vah ") return table = GetHistoryTable(addr, limit) - PrintTable(table) + print_table(table) #end define def GetHistoryTable(addr, limit): @@ -687,7 +705,7 @@ def GetHistoryTable(addr, limit): account = ton.GetAccount(addr) history = ton.GetAccountHistory(account, limit) table = list() - typeText = ColorText("{red}{bold}{endc}") + typeText = color_text("{red}{bold}{endc}") table += [["Time", typeText, "Coins", "From/To"]] for message in history: if message.srcAddr is None: @@ -695,13 +713,13 @@ def GetHistoryTable(addr, limit): srcAddrFull = f"{message.srcWorkchain}:{message.srcAddr}" destAddFull = f"{message.destWorkchain}:{message.destAddr}" if srcAddrFull == account.addrFull: - type = ColorText("{red}{bold}>>>{endc}") + type = color_text("{red}{bold}>>>{endc}") fromto = destAddFull else: - type = ColorText("{blue}{bold}<<<{endc}") + type = color_text("{blue}{bold}<<<{endc}") fromto = srcAddrFull fromto = ton.AddrFull2AddrB64(fromto) - #datetime = Timestamp2Datetime(message.time, "%Y.%m.%d %H:%M:%S") + #datetime = timestamp2datetime(message.time, "%Y.%m.%d %H:%M:%S") datetime = timeago(message.time) table += [[datetime, type, message.value, fromto]] return table @@ -714,12 +732,12 @@ def MoveCoins(args): amount = args[2] flags = args[3:] except: - ColorPrint("{red}Bad args. Usage:{endc} mg ") + color_print("{red}Bad args. Usage:{endc} mg ") return wallet = ton.GetLocalWallet(walletName) destination = ton.GetDestinationAddr(destination) ton.MoveCoins(wallet, destination, amount, flags=flags) - ColorPrint("MoveCoins - {green}OK{endc}") + color_print("MoveCoins - {green}OK{endc}") #end define def MoveCoinsThroughProxy(args): @@ -728,12 +746,12 @@ def MoveCoinsThroughProxy(args): destination = args[1] amount = args[2] except: - ColorPrint("{red}Bad args. Usage:{endc} mgtp ") + color_print("{red}Bad args. Usage:{endc} mgtp ") return wallet = ton.GetLocalWallet(walletName) destination = ton.GetDestinationAddr(destination) ton.MoveCoinsThroughProxy(wallet, destination, amount) - ColorPrint("MoveCoinsThroughProxy - {green}OK{endc}") + color_print("MoveCoinsThroughProxy - {green}OK{endc}") #end define def CreatNewBookmark(args): @@ -741,7 +759,7 @@ def CreatNewBookmark(args): name = args[0] addr = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} nb ") + color_print("{red}Bad args. Usage:{endc} nb ") return if ton.IsAddr(addr): type = "account" @@ -754,7 +772,7 @@ def CreatNewBookmark(args): bookmark["type"] = type bookmark["addr"] = addr ton.AddBookmark(bookmark) - ColorPrint("CreatNewBookmark - {green}OK{endc}") + color_print("CreatNewBookmark - {green}OK{endc}") #end define def PrintBookmarksList(args): @@ -770,7 +788,7 @@ def PrintBookmarksList(args): addr = item.get("addr") data = item.get("data") table += [[name, type, addr, data]] - PrintTable(table) + print_table(table) #end define def DeleteBookmark(args): @@ -778,10 +796,10 @@ def DeleteBookmark(args): name = args[0] type = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} db ") + color_print("{red}Bad args. Usage:{endc} db ") return ton.DeleteBookmark(name, type) - ColorPrint("DeleteBookmark - {green}OK{endc}") + color_print("DeleteBookmark - {green}OK{endc}") #end define def PrintOffersList(args): @@ -804,20 +822,20 @@ def PrintOffersList(args): if "hash" not in args: hash = Reduct(hash) if isPassed == True: - isPassed = bcolors.Green("true") + isPassed = bcolors.green_text("true") if isPassed == False: - isPassed = bcolors.Red("false") + isPassed = bcolors.red_text("false") table += [[hash, votedValidators, wl, approvedPercent_text, isPassed]] - PrintTable(table) + print_table(table) #end define def VoteOffer(args): if len(args) == 0: - ColorPrint("{red}Bad args. Usage:{endc} vo ") + color_print("{red}Bad args. Usage:{endc} vo ") return for offerHash in args: ton.VoteOffer(offerHash) - ColorPrint("VoteOffer - {green}OK{endc}") + color_print("VoteOffer - {green}OK{endc}") #end define def OfferDiff(args): @@ -825,7 +843,7 @@ def OfferDiff(args): offerHash = args[0] offerHash = offerHash except: - ColorPrint("{red}Bad args. Usage:{endc} od ") + color_print("{red}Bad args. Usage:{endc} od ") return ton.GetOfferDiff(offerHash) #end define @@ -835,7 +853,7 @@ def GetConfig(args): configId = args[0] configId = int(configId) except: - ColorPrint("{red}Bad args. Usage:{endc} gc ") + color_print("{red}Bad args. Usage:{endc} gc ") return data = ton.GetConfig(configId) text = json.dumps(data, indent=2) @@ -864,11 +882,11 @@ def PrintComplaintsList(args): if "adnl" not in args: adnl = Reduct(adnl) if isPassed == True: - isPassed = bcolors.Green("true") + isPassed = bcolors.green_text("true") if isPassed == False: - isPassed = bcolors.Red("false") + isPassed = bcolors.red_text("false") table += [[electionId, adnl, Fine_text, votedValidators, approvedPercent_text, isPassed]] - PrintTable(table) + print_table(table) #end define def VoteComplaint(args): @@ -876,10 +894,10 @@ def VoteComplaint(args): electionId = args[0] complaintHash = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} vc ") + color_print("{red}Bad args. Usage:{endc} vc ") return ton.VoteComplaint(electionId, complaintHash) - ColorPrint("VoteComplaint - {green}OK{endc}") + color_print("VoteComplaint - {green}OK{endc}") #end define def NewDomain(args): @@ -888,14 +906,14 @@ def NewDomain(args): walletName = args[1] adnlAddr = args[2] except: - ColorPrint("{red}Bad args. Usage:{endc} nd ") + color_print("{red}Bad args. Usage:{endc} nd ") return domain = dict() domain["name"] = domainName domain["adnlAddr"] = adnlAddr domain["walletName"] = walletName ton.NewDomain(domain) - ColorPrint("NewDomain - {green}OK{endc}") + color_print("NewDomain - {green}OK{endc}") #end define def PrintDomainsList(args): @@ -909,36 +927,36 @@ def PrintDomainsList(args): domainName = item.get("name") walletName = item.get("walletName") endTime = item.get("endTime") - endTime = Timestamp2Datetime(endTime, "%d.%m.%Y") + endTime = timestamp2datetime(endTime, "%d.%m.%Y") adnlAddr = item.get("adnlAddr") table += [[domainName, walletName, endTime, adnlAddr]] - PrintTable(table) + print_table(table) #end define def ViewDomainStatus(args): try: domainName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} vds ") + color_print("{red}Bad args. Usage:{endc} vds ") return domain = ton.GetDomain(domainName) endTime = domain.get("endTime") - endTime = Timestamp2Datetime(endTime, "%d.%m.%Y") + endTime = timestamp2datetime(endTime, "%d.%m.%Y") adnlAddr = domain.get("adnlAddr") table = list() table += [["Domain", "Expiration date", "ADNL address"]] table += [[domainName, endTime, adnlAddr]] - PrintTable(table) + print_table(table) #end define def DeleteDomain(args): try: domainName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} dd ") + color_print("{red}Bad args. Usage:{endc} dd ") return ton.DeleteDomain(domainName) - ColorPrint("DeleteDomain - {green}OK{endc}") + color_print("DeleteDomain - {green}OK{endc}") #end define def PrintElectionEntriesList(args): @@ -963,12 +981,12 @@ def PrintElectionEntriesList(args): if "wallet" not in args: walletAddr = Reduct(walletAddr) table += [[adnl, pubkey, walletAddr, stake, maxFactor]] - PrintTable(table) + print_table(table) #end define def VoteElectionEntry(args): Elections(ton) - ColorPrint("VoteElectionEntry - {green}OK{endc}") + color_print("VoteElectionEntry - {green}OK{endc}") #end define def PrintValidatorList(args): @@ -995,11 +1013,11 @@ def PrintValidatorList(args): if "offline" in args and online != False: continue if online == True: - online = bcolors.Green("true") + online = bcolors.green_text("true") if online == False: - online = bcolors.Red("false") + online = bcolors.red_text("false") table += [[adnl, pubkey, walletAddr, efficiency, online]] - PrintTable(table) + print_table(table) #end define def Reduct(item): @@ -1016,7 +1034,7 @@ def GetSettings(args): try: name = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} get ") + color_print("{red}Bad args. Usage:{endc} get ") return result = ton.GetSettings(name) print(json.dumps(result, indent=2)) @@ -1027,28 +1045,28 @@ def SetSettings(args): name = args[0] value = args[1] except: - ColorPrint("{red}Bad args. Usage:{endc} set ") + color_print("{red}Bad args. Usage:{endc} set ") return result = ton.SetSettings(name, value) - ColorPrint("SetSettings - {green}OK{endc}") + color_print("SetSettings - {green}OK{endc}") #end define def Xrestart(inputArgs): if len(inputArgs) < 2: - ColorPrint("{red}Bad args. Usage:{endc} xrestart ") + color_print("{red}Bad args. Usage:{endc} xrestart ") return args = ["python3", "/usr/src/mytonctrl/scripts/xrestart.py"] args += inputArgs - exitCode = RunAsRoot(args) + exitCode = run_as_root(args) if exitCode == 0: text = "Xrestart - {green}OK{endc}" else: text = "Xrestart - {red}Error{endc}" - ColorPrint(text) + color_print(text) #end define def Xlist(args): - ColorPrint("Xlist - {green}OK{endc}") + color_print("Xlist - {green}OK{endc}") #end define def NewPool(args): @@ -1059,24 +1077,24 @@ def NewPool(args): minValidatorStake = int(args[3]) minNominatorStake = int(args[4]) except: - ColorPrint("{red}Bad args. Usage:{endc} new_pool ") + color_print("{red}Bad args. Usage:{endc} new_pool ") return ton.CreatePool(poolName, validatorRewardSharePercent, maxNominatorsCount, minValidatorStake, minNominatorStake) - ColorPrint("NewPool - {green}OK{endc}") + color_print("NewPool - {green}OK{endc}") #end define def ActivatePool(args): try: poolName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} activate_pool ") + color_print("{red}Bad args. Usage:{endc} activate_pool ") return pool = ton.GetLocalPool(poolName) if not os.path.isfile(pool.bocFilePath): - local.AddLog(f"Pool {poolName} already activated", "warning") + local.add_log(f"Pool {poolName} already activated", "warning") return ton.ActivatePool(pool) - ColorPrint("ActivatePool - {green}OK{endc}") + color_print("ActivatePool - {green}OK{endc}") #end define def PrintPoolsList(args): @@ -1091,14 +1109,14 @@ def PrintPoolsList(args): if account.status != "active": pool.addrB64 = pool.addrB64_init table += [[pool.name, account.status, account.balance, pool.addrB64]] - PrintTable(table) + print_table(table) #end define def GetPoolData(args): try: poolName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} get_pool_data ") + color_print("{red}Bad args. Usage:{endc} get_pool_data ") return if ton.IsAddr(poolName): poolAddr = poolName @@ -1115,10 +1133,10 @@ def DepositToPool(args): pollAddr = args[1] amount = float(args[2]) except: - ColorPrint("{red}Bad args. Usage:{endc} deposit_to_pool ") + color_print("{red}Bad args. Usage:{endc} deposit_to_pool ") return ton.DepositToPool(walletName, pollAddr, amount) - ColorPrint("DepositToPool - {green}OK{endc}") + color_print("DepositToPool - {green}OK{endc}") #end define def WithdrawFromPool(args): @@ -1127,33 +1145,33 @@ def WithdrawFromPool(args): poolAddr = args[1] amount = float(args[2]) except: - ColorPrint("{red}Bad args. Usage:{endc} withdraw_from_pool ") + color_print("{red}Bad args. Usage:{endc} withdraw_from_pool ") return poolAddr = ton.GetDestinationAddr(poolAddr) ton.WithdrawFromPool(walletName, poolAddr, amount) - ColorPrint("WithdrawFromPool - {green}OK{endc}") + color_print("WithdrawFromPool - {green}OK{endc}") #end define def DeletePool(args): try: poolName = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} delete_pool ") + color_print("{red}Bad args. Usage:{endc} delete_pool ") return pool = ton.GetLocalPool(poolName) pool.Delete() - ColorPrint("DeletePool - {green}OK{endc}") + color_print("DeletePool - {green}OK{endc}") #end define def UpdateValidatorSet(args): try: poolAddr = args[0] except: - ColorPrint("{red}Bad args. Usage:{endc} update_validator_set ") + color_print("{red}Bad args. Usage:{endc} update_validator_set ") return wallet = self.GetValidatorWallet() self.PoolUpdateValidatorSet(poolAddr, wallet) - ColorPrint("DeletePool - {green}OK{endc}") + color_print("DeletePool - {green}OK{endc}") #end define diff --git a/mytoninstaller.py b/mytoninstaller.py index e8bd9e58..3d8ec1d7 100644 --- a/mytoninstaller.py +++ b/mytoninstaller.py @@ -100,13 +100,13 @@ def Enable(args): if name == "PT": CreateLocalConfigFile(args) args = ["python3", local.buffer["myPath"], "-u", user, "-e", "enable{name}".format(name=name)] - RunAsRoot(args) + run_as_root(args) #end define def DRVCF(args): user = local.buffer["user"] args = ["python3", local.buffer["myPath"], "-u", user, "-e", "drvcf"] - RunAsRoot(args) + run_as_root(args) #end define def GetLiteServerConfig(): @@ -179,7 +179,7 @@ def CreateLocalConfigFile(args): initBlock_b64 = dict2b64(initBlock) user = local.buffer["user"] args = ["python3", local.buffer["myPath"], "-u", user, "-e", "clc", "-i", initBlock_b64] - RunAsRoot(args) + run_as_root(args) #end define def Event(name): @@ -250,7 +250,7 @@ def Str2Bool(str): #end define def FirstNodeSettings(): - local.AddLog("start FirstNodeSettings fuction", "debug") + local.add_log("start FirstNodeSettings fuction", "debug") # Создать переменные user = local.buffer["user"] @@ -265,7 +265,7 @@ def FirstNodeSettings(): # Проверить конфигурацию if os.path.isfile(vconfigPath): - local.AddLog("Validators config.json already exist. Break FirstNodeSettings fuction", "warning") + local.add_log("Validators config.json already exist. Break FirstNodeSettings fuction", "warning") return #end if @@ -274,7 +274,7 @@ def FirstNodeSettings(): text = file.read() file.close() if vuser not in text: - local.AddLog("Creating new user: " + vuser, "debug") + local.add_log("Creating new user: " + vuser, "debug") args = ["/usr/sbin/useradd", "-d", "/dev/null", "-s", "/dev/null", vuser] subprocess.run(args) #end if @@ -287,16 +287,16 @@ def FirstNodeSettings(): cpus = psutil.cpu_count() - 1 cmd = "{validatorAppPath} --threads {cpus} --daemonize --global-config {globalConfigPath} --db {tonDbDir} --logname {tonLogPath} --state-ttl 604800 --verbosity 1" cmd = cmd.format(validatorAppPath=validatorAppPath, globalConfigPath=globalConfigPath, tonDbDir=tonDbDir, tonLogPath=tonLogPath, cpus=cpus) - Add2Systemd(name="validator", user=vuser, start=cmd) # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\"" + add2systemd(name="validator", user=vuser, start=cmd) # post="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py -e \"validator down\"" # Получить внешний ip адрес ip = requests.get("https://ifconfig.me").text vport = random.randint(2000, 65000) addr = "{ip}:{vport}".format(ip=ip, vport=vport) - local.AddLog("Use addr: " + addr, "debug") + local.add_log("Use addr: " + addr, "debug") # Первый запуск - local.AddLog("First start validator - create config.json", "debug") + local.add_log("First start validator - create config.json", "debug") args = [validatorAppPath, "--global-config", globalConfigPath, "--db", tonDbDir, "--ip", addr, "--logname", tonLogPath] subprocess.run(args) @@ -304,7 +304,7 @@ def FirstNodeSettings(): DownloadDump() # chown 1 - local.AddLog("Chown ton-work dir", "debug") + local.add_log("Chown ton-work dir", "debug") args = ["chown", "-R", vuser + ':' + vuser, tonWorkDir] subprocess.run(args) @@ -318,7 +318,7 @@ def DownloadDump(): return #end if - local.AddLog("start DownloadDump fuction", "debug") + local.add_log("start DownloadDump fuction", "debug") url = "https://dump.ton.org" dumpSize = requests.get(url + "/dumps/latest.size.archive.txt").text print("dumpSize:", dumpSize) @@ -338,17 +338,17 @@ def DownloadDump(): #end define def FirstMytoncoreSettings(): - local.AddLog("start FirstMytoncoreSettings fuction", "debug") + local.add_log("start FirstMytoncoreSettings fuction", "debug") user = local.buffer["user"] # Прописать mytoncore.py в автозагрузку - Add2Systemd(name="mytoncore", user=user, start="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py") + add2systemd(name="mytoncore", user=user, start="/usr/bin/python3 /usr/src/mytonctrl/mytoncore.py") # Проверить конфигурацию path = "/home/{user}/.local/share/mytoncore/mytoncore.db".format(user=user) path2 = "/usr/local/bin/mytoncore/mytoncore.db" if os.path.isfile(path) or os.path.isfile(path2): - local.AddLog("mytoncore.db already exist. Break FirstMytoncoreSettings fuction", "warning") + local.add_log("mytoncore.db already exist. Break FirstMytoncoreSettings fuction", "warning") return #end if @@ -363,7 +363,7 @@ def FirstMytoncoreSettings(): # Подготовить папку mytoncore mconfigPath = local.buffer["mconfigPath"] - mconfigDir = GetDirFromPath(mconfigPath) + mconfigDir = get_dir_from_path(mconfigPath) os.makedirs(mconfigDir, exist_ok=True) # create variables @@ -410,7 +410,7 @@ def FirstMytoncoreSettings(): #end define def EnableValidatorConsole(): - local.AddLog("start EnableValidatorConsole function", "debug") + local.add_log("start EnableValidatorConsole function", "debug") # Create variables user = local.buffer["user"] @@ -429,7 +429,7 @@ def EnableValidatorConsole(): # Check if key exist if os.path.isfile(server_key) or os.path.isfile(client_key): - local.AddLog("Server or client key already exist. Break EnableValidatorConsole fuction", "warning") + local.add_log("Server or client key already exist. Break EnableValidatorConsole fuction", "warning") return #end if @@ -506,7 +506,7 @@ def EnableValidatorConsole(): #end define def EnableLiteServer(): - local.AddLog("start EnableLiteServer function", "debug") + local.add_log("start EnableLiteServer function", "debug") # Create variables user = local.buffer["user"] @@ -523,12 +523,12 @@ def EnableLiteServer(): # Check if key exist if os.path.isfile(liteserver_pubkey): - local.AddLog("Liteserver key already exist. Break EnableLiteServer fuction", "warning") + local.add_log("Liteserver key already exist. Break EnableLiteServer fuction", "warning") return #end if # generate liteserver key - local.AddLog("generate liteserver key", "debug") + local.add_log("generate liteserver key", "debug") args = [generate_random_id, "--mode", "keys", "--name", liteserver_key] process = subprocess.run(args, stdout=subprocess.PIPE) output = process.stdout.decode("utf-8") @@ -537,34 +537,34 @@ def EnableLiteServer(): liteserver_key_b64 = output_arr[1].replace('\n', '') # move key - local.AddLog("move key", "debug") + local.add_log("move key", "debug") newKeyPath = tonDbDir + "/keyring/" + liteserver_key_hex args = ["mv", liteserver_key, newKeyPath] subprocess.run(args) # chown 1 - local.AddLog("chown 1", "debug") + local.add_log("chown 1", "debug") args = ["chown", vuser + ':' + vuser, newKeyPath] subprocess.run(args) # chown 2 - local.AddLog("chown 2", "debug") + local.add_log("chown 2", "debug") args = ["chown", user + ':' + user, liteserver_pubkey] subprocess.run(args) # read vconfig - local.AddLog("read vconfig", "debug") + local.add_log("read vconfig", "debug") vconfig = GetConfig(path=vconfigPath) # prepare vconfig - local.AddLog("prepare vconfig", "debug") + local.add_log("prepare vconfig", "debug") liteserver = dict() liteserver["id"] = liteserver_key_b64 liteserver["port"] = lport vconfig["liteservers"].append(liteserver) # write vconfig - local.AddLog("write vconfig", "debug") + local.add_log("write vconfig", "debug") SetConfig(path=vconfigPath, data=vconfig) # restart validator @@ -572,12 +572,12 @@ def EnableLiteServer(): # edit mytoncore config file # read mconfig - local.AddLog("read mconfig", "debug") + local.add_log("read mconfig", "debug") mconfigPath = local.buffer["mconfigPath"] mconfig = GetConfig(path=mconfigPath) # edit mytoncore config file - local.AddLog("edit mytoncore config file", "debug") + local.add_log("edit mytoncore config file", "debug") liteServer = dict() liteServer["pubkeyPath"] = liteserver_pubkey liteServer["ip"] = "127.0.0.1" @@ -585,7 +585,7 @@ def EnableLiteServer(): mconfig["liteClient"]["liteServer"] = liteServer # write mconfig - local.AddLog("write mconfig", "debug") + local.add_log("write mconfig", "debug") SetConfig(path=mconfigPath, data=mconfig) # restart mytoncore @@ -594,18 +594,18 @@ def EnableLiteServer(): def StartValidator(): # restart validator - local.AddLog("Start/restart validator service", "debug") + local.add_log("Start/restart validator service", "debug") args = ["systemctl", "restart", "validator"] subprocess.run(args) # sleep 10 sec - local.AddLog("sleep 10 sec", "debug") + local.add_log("sleep 10 sec", "debug") time.sleep(10) #end define def StartMytoncore(): # restart mytoncore - local.AddLog("Start/restart mytoncore service", "debug") + local.add_log("Start/restart mytoncore service", "debug") args = ["systemctl", "restart", "mytoncore"] subprocess.run(args) #end define @@ -631,7 +631,7 @@ def SetConfig(**kwargs): #end define def BackupVconfig(): - local.AddLog("Backup validator config file 'config.json' to 'config.json.backup'", "debug") + local.add_log("Backup validator config file 'config.json' to 'config.json.backup'", "debug") vconfigPath = local.buffer["vconfigPath"] backupPath = vconfigPath + ".backup" args = ["cp", vconfigPath, backupPath] @@ -639,7 +639,7 @@ def BackupVconfig(): #end define def BackupMconfig(): - local.AddLog("Backup mytoncore config file 'mytoncore.db' to 'mytoncore.db.backup'", "debug") + local.add_log("Backup mytoncore config file 'mytoncore.db' to 'mytoncore.db.backup'", "debug") mconfigPath = local.buffer["mconfigPath"] backupPath = mconfigPath + ".backup" args = ["cp", mconfigPath, backupPath] @@ -650,21 +650,21 @@ def GetPortsFromVconfig(): vconfigPath = local.buffer["vconfigPath"] # read vconfig - local.AddLog("read vconfig", "debug") + local.add_log("read vconfig", "debug") vconfig = GetConfig(path=vconfigPath) # read mconfig - local.AddLog("read mconfig", "debug") + local.add_log("read mconfig", "debug") mconfigPath = local.buffer["mconfigPath"] mconfig = GetConfig(path=mconfigPath) # edit mytoncore config file - local.AddLog("edit mytoncore config file", "debug") + local.add_log("edit mytoncore config file", "debug") mconfig["liteClient"]["liteServer"]["port"] = mconfig["liteservers"][0]["port"] mconfig["validatorConsole"]["addr"] = "127.0.0.1:{}".format(mconfig["control"][0]["port"]) # write mconfig - local.AddLog("write mconfig", "debug") + local.add_log("write mconfig", "debug") SetConfig(path=mconfigPath, data=mconfig) # restart mytoncore @@ -672,7 +672,7 @@ def GetPortsFromVconfig(): #end define def DangerousRecoveryValidatorConfigFile(): - local.AddLog("start DangerousRecoveryValidatorConfigFile function", "info") + local.add_log("start DangerousRecoveryValidatorConfigFile function", "info") # install and import cryptography library args = ["pip3", "install", "cryptography"] @@ -891,7 +891,7 @@ def b642hex(input): #end define def CreateSymlinks(): - local.AddLog("start CreateSymlinks fuction", "debug") + local.add_log("start CreateSymlinks fuction", "debug") cport = local.buffer["cport"] mytonctrl_file = "/usr/bin/mytonctrl" @@ -927,7 +927,7 @@ def CreateSymlinks(): #end define def EnableDhtServer(): - local.AddLog("start EnableDhtServer function", "debug") + local.add_log("start EnableDhtServer function", "debug") vuser = local.buffer["vuser"] tonBinDir = local.buffer["tonBinDir"] globalConfigPath = local.buffer["globalConfigPath"] @@ -938,7 +938,7 @@ def EnableDhtServer(): # Проверить конфигурацию if os.path.isfile("/var/ton-dht-server/config.json"): - local.AddLog("DHT-Server config.json already exist. Break EnableDhtServer fuction", "warning") + local.add_log("DHT-Server config.json already exist. Break EnableDhtServer fuction", "warning") return #end if @@ -948,7 +948,7 @@ def EnableDhtServer(): # Прописать автозагрузку cmd = "{dht_server} -C {globalConfigPath} -D {tonDhtServerDir}" cmd = cmd.format(dht_server=dht_server, globalConfigPath=globalConfigPath, tonDhtServerDir=tonDhtServerDir) - Add2Systemd(name="dht-server", user=vuser, start=cmd) + add2systemd(name="dht-server", user=vuser, start=cmd) # Получить внешний ip адрес ip = requests.get("https://ifconfig.me").text @@ -990,25 +990,25 @@ def SetWebPassword(args): #end define def EnableJsonRpc(): - local.AddLog("start EnableJsonRpc function", "debug") + local.add_log("start EnableJsonRpc function", "debug") user = local.buffer["user"] - exitCode = RunAsRoot(["bash", "/usr/src/mytonctrl/scripts/jsonrpcinstaller.sh", "-u", user]) + exitCode = run_as_root(["bash", "/usr/src/mytonctrl/scripts/jsonrpcinstaller.sh", "-u", user]) if exitCode == 0: text = "EnableJsonRpc - {green}OK{endc}" else: text = "EnableJsonRpc - {red}Error{endc}" - ColorPrint(text) + color_print(text) #end define def EnablePytonv3(): - local.AddLog("start EnablePytonv3 function", "debug") + local.add_log("start EnablePytonv3 function", "debug") user = local.buffer["user"] - exitCode = RunAsRoot(["bash", "/usr/src/mytonctrl/scripts/pytonv3installer.sh", "-u", user]) + exitCode = run_as_root(["bash", "/usr/src/mytonctrl/scripts/pytonv3installer.sh", "-u", user]) if exitCode == 0: text = "EnablePytonv3 - {green}OK{endc}" else: text = "EnablePytonv3 - {red}Error{endc}" - ColorPrint(text) + color_print(text) #end define def str2b64(s): diff --git a/scripts/toninstaller.sh b/scripts/toninstaller.sh index 8ff8bec1..807036e9 100755 --- a/scripts/toninstaller.sh +++ b/scripts/toninstaller.sh @@ -134,6 +134,8 @@ rm -rf $SOURCES_DIR/ton rm -rf $SOURCES_DIR/mytonctrl git clone --recursive https://github.com/ton-blockchain/ton.git git clone --recursive https://github.com/ton-blockchain/mytonctrl.git +git config --global --add safe.directory $SOURCES_DIR/ton +git config --global --add safe.directory $SOURCES_DIR/mytonctrl # Подготавливаем папки для компиляции echo -e "${COLOR}[3/6]${ENDC} Preparing for compilation" diff --git a/translate.json b/translate.json index b41fdff9..5ce41b98 100644 --- a/translate.json +++ b/translate.json @@ -374,10 +374,10 @@ "ru": "{green}Доступно обновление TON. {red}Пожалуйста, обновите его с помощью команды `upgrade`.{endc}", "zh_TW": "{green}TON 有可用更新. {red}請使用 `upgrade` 命令進行更新.{endc}" }, - "test": { - "en": "001", - "ru": "002", - "zh_TW": "003" + "vport_error": { + "en": "{red}Error - UDP port of the validator is not accessible from the outside.{endc}", + "ru": "{red}Ошибка - UDP порт валидатора недоступен извне.{endc}", + "zh_TW": "{red}錯誤 - 驗證器的 UDP 端口無法從外部訪問.{endc}" }, "000a": { "en": "001", From ef7d665a28c009a849013f1db5ca08187c2c0dd2 Mon Sep 17 00:00:00 2001 From: Igroman787 <27614297+igroman787@users.noreply.github.com> Date: Sat, 1 Jul 2023 12:59:14 +0300 Subject: [PATCH 2/4] bugfix --- mytoncore.py | 13 +++++-------- mytonctrl.py | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index a971fd8c..9d3c79c7 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -3758,11 +3758,11 @@ def Elections(ton): ton.ElectionEntry() #end define -def Statistics(scanner): +def Statistics(): ReadNetworkData() SaveNetworkStatistics() - ReadTransData(scanner) - SaveTransStatistics() + #ReadTransData(scanner) + #SaveTransStatistics() ReadDiskData() SaveDiskStatistics() #end define @@ -3862,7 +3862,6 @@ def ReadNetworkData(): buff = psutil.net_io_counters(pernic=True) buff = buff[interfaceName] data = dict() - data = dict() data["timestamp"] = timestamp data["bytesRecv"] = buff.bytes_recv data["bytesSent"] = buff.bytes_sent @@ -4087,7 +4086,7 @@ def Telemetry(ton): data["stake"] = local.db.get("stake") # Get validator config - vconfig = self.GetValidatorConfig() + vconfig = ton.GetValidatorConfig() data["fullnode_adnl"] = vconfig.fullnode # Send data to toncenter server @@ -4192,12 +4191,10 @@ def ScanLiteServers(ton): def General(): local.add_log("start General function", "debug") ton = MyTonCore() - scanner = Dict() - #scanner.Run() # Запустить потоки local.start_cycle(Elections, sec=600, args=(ton, )) - local.start_cycle(Statistics, sec=10, args=(scanner,)) + local.start_cycle(Statistics, sec=10) local.start_cycle(Offers, sec=600, args=(ton, )) local.start_cycle(Complaints, sec=600, args=(ton, )) local.start_cycle(Slashing, sec=600, args=(ton, )) diff --git a/mytonctrl.py b/mytonctrl.py index ab90a066..f3511252 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -127,7 +127,7 @@ def check_vport(): color_print(local.translate("vport_error")) #end define -def check_git(input_args, default_repo): +def check_git(input_args, default_repo, text): src_dir = "/usr/src" git_path = f"{src_dir}/{default_repo}" default_author = "ton-blockchain" @@ -147,9 +147,9 @@ def check_git(input_args, default_repo): if ((need_author is None and local_author != default_author) or (need_repo is None and local_repo != default_repo)): remote_url = f"https://github.com/{local_author}/{local_repo}/tree/{need_branch if need_branch else local_branch}" - raise Exception(f"update error: You are on {remote_url} remote url, to update to the tip use `update {remote_url}` command") + raise Exception(f"{text} error: You are on {remote_url} remote url, to {text} to the tip use `{text} {remote_url}` command") elif need_branch is None and local_branch != default_branch: - raise Exception(f"update error: You are on {local_branch} branch, to update to the tip of {local_branch} branch use `update {local_branch}` command") + raise Exception(f"{text} error: You are on {local_branch} branch, to {text} to the tip of {local_branch} branch use `{text} {local_branch}` command") #end if if need_author is None: @@ -185,7 +185,7 @@ def GetAuthorRepoBranchFromArgs(args): def Update(args): repo = "mytonctrl" - author, repo, branch = check_git(args, repo) + author, repo, branch = check_git(args, repo, "update") # Run script runArgs = ["bash", "/usr/src/mytonctrl/scripts/update.sh", "-a", author, "-r", repo, "-b", branch] @@ -200,7 +200,7 @@ def Update(args): def Upgrade(args): repo = "ton" - author, repo, branch = check_git(args, repo) + author, repo, branch = check_git(args, repo, "upgrade") # Run script runArgs = ["bash", "/usr/src/mytonctrl/scripts/upgrade.sh", "-a", author, "-r", repo, "-b", branch] From 2a359a8a381c7bf968004907f87b0911e44eca5e Mon Sep 17 00:00:00 2001 From: Igroman787 <27614297+igroman787@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:33:36 +0300 Subject: [PATCH 3/4] update `mypylib` --- README.md | 6 +++--- mypylib | 2 +- mytoncore.py | 42 +++++++++++++++++++++--------------------- mytonctrl.py | 10 ++++------ 4 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 148283d2..a41b61d4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ ![GitHub stars](https://img.shields.io/github/stars/ton-blockchain/mytonctrl?style=flat-square&logo=github) ![GitHub forks](https://img.shields.io/github/forks/ton-blockchain/mytonctrl?style=flat-square&logo=github) ![GitHub issues](https://img.shields.io/github/issues/ton-blockchain/mytonctrl?style=flat-square&logo=github) ![GitHub pull requests](https://img.shields.io/github/issues-pr/ton-blockchain/mytonctrl?style=flat-square&logo=github) ![GitHub last commit](https://img.shields.io/github/last-commit/ton-blockchain/mytonctrl?style=flat-square&logo=github) ![GitHub license](https://img.shields.io/github/license/ton-blockchain/mytonctrl?style=flat-square&logo=github) -# MytTonCtrl +# MyTonCtrl [Данный текст доступен на русском языке.](README.Ru.md) ## Contents -- [What is MytTonCtrl?](#what-is-myttonctrl) +- [What is MyTonCtrl?](#what-is-myttonctrl) - [Functionality](#functionality) - [List of tested operating systems](#list-of-tested-operating-systems) - [Installation](#installation) @@ -23,7 +23,7 @@ - [Useful links](#useful-links) -# What is MytTonCtrl? +# What is MyTonCtrl? MyTonCtrl is a console application that serves as a convenient wrapper for `fift`, `lite-client`, and `validator-engine-console`. It has been specifically developed to streamline wallet, domain, and validator management tasks on the Linux operating system. ![MyTonCtrl Status](screens/mytonctrl-status.png) diff --git a/mypylib b/mypylib index 01a9219e..e95756c5 160000 --- a/mypylib +++ b/mypylib @@ -1 +1 @@ -Subproject commit 01a9219eee82d45ae9db56130058b1d762a61e44 +Subproject commit e95756c588f2ef7faf9e8f331b08109058ec5ba2 diff --git a/mytoncore.py b/mytoncore.py index 9d3c79c7..501c2ed7 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -749,7 +749,7 @@ def WalletVersion2Wallet(self, wallet): def SetWalletVersion(self, addrB64, version): walletsVersionList = self.GetWalletsVersionList() walletsVersionList[addrB64] = version - #local.save_db() + local.save() #end define def GetWalletVersionFromHash(self, inputHash): @@ -2928,7 +2928,7 @@ def AddDomain(self, domain): local.db["domains"] = list() #end if local.db["domains"].append(domain) - #local.save_db() + local.save() #end define def GetDomains(self): @@ -2952,7 +2952,7 @@ def DeleteDomain(self, domainName): for domain in domains: if (domainName == domain.get("name")): domains.remove(domain) - #local.save_db() + local.save() return raise Exception("DeleteDomain error: Domain not found") #end define @@ -2968,7 +2968,7 @@ def GetAutoTransferRules(self): def AddAutoTransferRule(self, rule): autoTransferRules = self.GetAutoTransferRules() autoTransferRules.append(rule) - #local.save_db() + local.save() #end define def AddBookmark(self, bookmark): @@ -2976,7 +2976,7 @@ def AddBookmark(self, bookmark): local.db["bookmarks"] = list() #end if local.db["bookmarks"].append(bookmark) - #local.save_db() + local.save() #end define def GetBookmarks(self): @@ -3005,7 +3005,7 @@ def DeleteBookmark(self, name, type): bookmarkName = bookmark.get("name") if (type == bookmarkType and name == bookmarkName): bookmarks.remove(bookmark) - #local.save_db() + local.save() return raise Exception("DeleteBookmark error: Bookmark not found") #end define @@ -3046,7 +3046,7 @@ def AddSaveOffer(self, offer): saveOffers = self.GetSaveOffers() if offerHash not in saveOffers: saveOffers[offerHash] = offerPseudohash - #local.save_db() + local.save() #end define def GetVotedComplaints(self): @@ -3063,7 +3063,7 @@ def AddVotedComplaints(self, complaint): votedComplaints = self.GetVotedComplaints() if pseudohash not in votedComplaints: votedComplaints[pseudohash] = complaint - #local.save_db() + local.save() #end define def GetDestinationAddr(self, destination): @@ -3222,7 +3222,7 @@ def SetSettings(self, name, data): data = json.loads(data) except: pass local.db[name] = data - #local.save_db() + local.save() #end define def Tlb2Json(self, text): @@ -3455,17 +3455,17 @@ def DepositToPool(self, walletName, poolAddr, amount): self.SendFile(resultFilePath, wallet) #end define - def WithdrawFromPool(self, walletName, poolAddr, amount): + def WithdrawFromPool(self, poolAddr, amount): poolData = self.GetPoolData(poolAddr) if poolData["state"] == 0: - self.WithdrawFromPoolProcess(walletName, poolAddr, amount) + self.WithdrawFromPoolProcess(poolAddr, amount) else: - self.PendWithdrawFromPool(walletName, poolAddr, amount) + self.PendWithdrawFromPool(poolAddr, amount) #end define - def WithdrawFromPoolProcess(self, walletName, poolAddr, amount): + def WithdrawFromPoolProcess(self, poolAddr, amount): local.add_log("start WithdrawFromPoolProcess function", "debug") - wallet = self.GetLocalWallet(walletName) + wallet = self.GetValidatorWallet() bocPath = local.buffer.my_temp_dir + wallet.name + "validator-withdraw-query.boc" fiftScript = self.contractsDir + "nominator-pool/func/validator-withdraw.fif" args = [fiftScript, amount, bocPath] @@ -3474,16 +3474,16 @@ def WithdrawFromPoolProcess(self, walletName, poolAddr, amount): self.SendFile(resultFilePath, wallet) #end define - def PendWithdrawFromPool(self, walletName, poolAddr, amount): + def PendWithdrawFromPool(self, poolAddr, amount): local.add_log("start PendWithdrawFromPool function", "debug") pendingWithdraws = self.GetPendingWithdraws() - pendingWithdraws[poolAddr] = (walletName, amount) - #local.save_db() + pendingWithdraws[poolAddr] = amount + local.save() #end define def HandlePendingWithdraw(self, pendingWithdraws, poolAddr): - walletName, amount = pendingWithdraws.get(poolAddr) - self.WithdrawFromPoolProcess(walletName, poolAddr, amount) + amount = pendingWithdraws.get(poolAddr) + self.WithdrawFromPoolProcess(poolAddr, amount) pendingWithdraws.pop(poolAddr) #end define @@ -3739,7 +3739,7 @@ def EnableVcEvent(): local.db["adnlAddr"] = adnlAddr # Сохранить - #local.save_db() + local.save() #end define def ValidatorDownEvent(): @@ -3762,7 +3762,7 @@ def Statistics(): ReadNetworkData() SaveNetworkStatistics() #ReadTransData(scanner) - #SaveTransStatistics() + SaveTransStatistics() ReadDiskData() SaveDiskStatistics() #end define diff --git a/mytonctrl.py b/mytonctrl.py index f3511252..da15a68c 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -1141,14 +1141,12 @@ def DepositToPool(args): def WithdrawFromPool(args): try: - walletName = args[0] - poolAddr = args[1] - amount = float(args[2]) + poolAddr = args[0] + amount = float(args[1]) except: - color_print("{red}Bad args. Usage:{endc} withdraw_from_pool ") + color_print("{red}Bad args. Usage:{endc} withdraw_from_pool ") return - poolAddr = ton.GetDestinationAddr(poolAddr) - ton.WithdrawFromPool(walletName, poolAddr, amount) + ton.WithdrawFromPool(poolAddr, amount) color_print("WithdrawFromPool - {green}OK{endc}") #end define From f1f52478734f0bae82648c929e93f086799bd211 Mon Sep 17 00:00:00 2001 From: Igroman787 <27614297+igroman787@users.noreply.github.com> Date: Thu, 3 Aug 2023 00:31:19 +0300 Subject: [PATCH 4/4] add GetDomainFromAuction function --- mytoncore.py | 10 ++++++++++ mytonctrl.py | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/mytoncore.py b/mytoncore.py index 501c2ed7..7e9ec77f 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -2896,6 +2896,16 @@ def GetItemFromDict(self, data, search): #end for return None #end define + + def GetDomainFromAuction(self, walletName, addr): + wallet = self.GetLocalWallet(walletName) + bocPath = local.buffer.my_temp_dir + "get_dns_data.boc" + bocData = bytes.fromhex("b5ee9c7241010101000e0000182fcb26a20000000000000000f36cae4d") + with open(bocPath, 'wb') as file: + file.write(bocData) + resultFilePath = self.SignBocWithWallet(wallet, bocPath, addr, 0.1) + self.SendFile(resultFilePath, wallet) + #end define def NewDomain(self, domain): local.add_log("start NewDomain function", "debug") diff --git a/mytonctrl.py b/mytonctrl.py index da15a68c..4bf1dde1 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -46,6 +46,7 @@ def Init(argv): console.AddItem("dl", PrintDomainsList, local.translate("dl_cmd")) console.AddItem("vds", ViewDomainStatus, local.translate("vds_cmd")) console.AddItem("dd", DeleteDomain, local.translate("dd_cmd")) + console.AddItem("gdfa", GetDomainFromAuction, local.translate("gdfa_cmd")) console.AddItem("ol", PrintOffersList, local.translate("ol_cmd")) console.AddItem("vo", VoteOffer, local.translate("vo_cmd")) @@ -959,6 +960,17 @@ def DeleteDomain(args): color_print("DeleteDomain - {green}OK{endc}") #end define +def GetDomainFromAuction(args): + try: + walletName = args[0] + addr = args[1] + except: + color_print("{red}Bad args. Usage:{endc} gdfa ") + return + ton.GetDomainFromAuction(walletName, addr) + color_print("GetDomainFromAuction - {green}OK{endc}") +#end define + def PrintElectionEntriesList(args): past = "past" in args entries = ton.GetElectionEntries(past=past)