From 9846c732b5b18b3a906d81c299af3f16ce3a3cff Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 1 Feb 2024 18:54:02 +0700 Subject: [PATCH 1/5] add duplicating externals to toncenter --- mytoncore.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index fd1a9671..6aee5760 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1430,14 +1430,28 @@ def SendFile(self, filePath, wallet=None, **kwargs): wallet.oldseqno = self.GetSeqno(wallet) self.liteClient.Run("sendfile " + filePath) if duplicateSendfile: - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + self.send_boc_toncenter(filePath) + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) if timeout and wallet: self.WaitTransaction(wallet, timeout) if remove == True: os.remove(filePath) #end define + def send_boc_toncenter(self, file_path: str): + local.add_log('Start send_boc_toncenter function: ' + file_path, 'debug') + with open(file_path, "rb") as f: + boc = f.read() + boc_b64 = base64.b64encode(boc).decode("utf-8") + data = {"boc": boc_b64} + result = requests.post(url='https://toncenter.com/api/v2/sendBoc', json=data) + if result.status_code != 200: + local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') + return False + local.add_log('Sent boc to toncenter', 'info') + return True + def WaitTransaction(self, wallet, timeout=30): local.add_log("start WaitTransaction function", "debug") timesleep = 3 From cfc85fc2ae0980bcc3f5e69734453d8619f480eb Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 1 Feb 2024 19:02:29 +0700 Subject: [PATCH 2/5] add testnet support to sending bocs via toncenter --- mytoncore.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mytoncore.py b/mytoncore.py index 6aee5760..db2dca60 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1445,7 +1445,11 @@ def send_boc_toncenter(self, file_path: str): boc = f.read() boc_b64 = base64.b64encode(boc).decode("utf-8") data = {"boc": boc_b64} - result = requests.post(url='https://toncenter.com/api/v2/sendBoc', json=data) + if self.GetNetworkName() == 'testnet': + url = 'https://testnet.toncenter.com/api/v2/sendBoc' + else: + url = 'https://toncenter.com/api/v2/sendBoc' + result = requests.post(url=url, json=data) if result.status_code != 200: local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') return False From a12dd8df4187620c34b251304deda7b046de5aff Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 15 Feb 2024 01:01:53 +0700 Subject: [PATCH 3/5] fix GetSaveOffers() and GetSaveComplaints() --- mytoncore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index db2dca60..71797d9f 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -2396,7 +2396,7 @@ def GetComplaints(self, electionId=None, past=False): def GetSaveComplaints(self): timestamp = get_timestamp() saveComplaints = local.db.get("saveComplaints") - if type(saveComplaints) is not dict: + if saveComplaints is None: saveComplaints = dict() local.db["saveComplaints"] = saveComplaints buff = saveComplaints.copy() @@ -3061,7 +3061,7 @@ def WriteBookmarkData(self, bookmark): def GetSaveOffers(self): bname = "saveOffers" saveOffers = local.db.get(bname) - if type(saveOffers) != dict: + if saveOffers is None: saveOffers = dict() local.db[bname] = saveOffers return saveOffers From 5f839f5a81066fada0c94e4204f7be66eab34f29 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 19 Feb 2024 13:58:20 +0700 Subject: [PATCH 4/5] fix GetValidatorKey --- mytoncore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 71797d9f..56307d28 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -2078,12 +2078,13 @@ def MoveCoinsFromHW(self, wallet, destList, **kwargs): def GetValidatorKey(self): vconfig = self.GetValidatorConfig() - for validator in vconfig.validators: + validators = sorted(vconfig["validators"], key=lambda i: i['election_date'], reverse=True) + for validator in validators: validatorId = validator["id"] key_bytes = base64.b64decode(validatorId) validatorKey = key_bytes.hex().upper() timestamp = get_timestamp() - if timestamp > validator["election_date"]: + if validator["election_date"] < timestamp < validator["expire_at"]: return validatorKey raise Exception("GetValidatorKey error: validator key not found. Are you sure you are a validator?") #end define From 846ef29be01d9bd28d389ca19cece64fce34d447 Mon Sep 17 00:00:00 2001 From: yungwine Date: Mon, 19 Feb 2024 14:19:42 +0700 Subject: [PATCH 5/5] update duplicateSendfile --- mytoncore.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 56307d28..65d66d3e 100755 --- a/mytoncore.py +++ b/mytoncore.py @@ -1430,9 +1430,12 @@ def SendFile(self, filePath, wallet=None, **kwargs): wallet.oldseqno = self.GetSeqno(wallet) self.liteClient.Run("sendfile " + filePath) if duplicateSendfile: + try: + self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) + except Exception as e: + local.add_log('failed to send file via liteclient: ' + str(e), 'info') self.send_boc_toncenter(filePath) - # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) - # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) if timeout and wallet: self.WaitTransaction(wallet, timeout) if remove == True: