From bf2de372958f31ce5ff5815013ed661090bf2a7f Mon Sep 17 00:00:00 2001 From: yungwine Date: Thu, 1 Feb 2024 19:10:06 +0700 Subject: [PATCH] add duplicating externals to toncenter --- mytoncore/mytoncore.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/mytoncore/mytoncore.py b/mytoncore/mytoncore.py index 79f01b7f..e6a245f5 100644 --- a/mytoncore/mytoncore.py +++ b/mytoncore/mytoncore.py @@ -8,6 +8,7 @@ import psutil import subprocess import pkg_resources +import requests from fastcrc import crc16 from mytoncore.utils import xhex2hex, ng2g @@ -1200,14 +1201,35 @@ 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): + self.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} + network_name = self.GetNetworkName() + if network_name == 'testnet': + url = 'https://testnet.toncenter.com/api/v2/sendBoc' + elif network_name == 'mainnet': + url = 'https://toncenter.com/api/v2/sendBoc' + else: + return False + result = requests.post(url=url, json=data) + if result.status_code != 200: + self.local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') + return False + self.local.add_log('Sent boc to toncenter', 'info') + return True + def WaitTransaction(self, wallet, timeout=30): self.local.add_log("start WaitTransaction function", "debug") timesleep = 3