|
8 | 8 | import psutil |
9 | 9 | import subprocess |
10 | 10 | import pkg_resources |
| 11 | +import requests |
11 | 12 | from fastcrc import crc16 |
12 | 13 |
|
13 | 14 | from mytoncore.utils import xhex2hex, ng2g |
@@ -1200,14 +1201,35 @@ def SendFile(self, filePath, wallet=None, **kwargs): |
1200 | 1201 | wallet.oldseqno = self.GetSeqno(wallet) |
1201 | 1202 | self.liteClient.Run("sendfile " + filePath) |
1202 | 1203 | if duplicateSendfile: |
1203 | | - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) |
1204 | | - self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) |
| 1204 | + self.send_boc_toncenter(filePath) |
| 1205 | + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) |
| 1206 | + # self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False) |
1205 | 1207 | if timeout and wallet: |
1206 | 1208 | self.WaitTransaction(wallet, timeout) |
1207 | 1209 | if remove == True: |
1208 | 1210 | os.remove(filePath) |
1209 | 1211 | #end define |
1210 | 1212 |
|
| 1213 | + def send_boc_toncenter(self, file_path: str): |
| 1214 | + self.local.add_log('Start send_boc_toncenter function: ' + file_path, 'debug') |
| 1215 | + with open(file_path, "rb") as f: |
| 1216 | + boc = f.read() |
| 1217 | + boc_b64 = base64.b64encode(boc).decode("utf-8") |
| 1218 | + data = {"boc": boc_b64} |
| 1219 | + network_name = self.GetNetworkName() |
| 1220 | + if network_name == 'testnet': |
| 1221 | + url = 'https://testnet.toncenter.com/api/v2/sendBoc' |
| 1222 | + elif network_name == 'mainnet': |
| 1223 | + url = 'https://toncenter.com/api/v2/sendBoc' |
| 1224 | + else: |
| 1225 | + return False |
| 1226 | + result = requests.post(url=url, json=data) |
| 1227 | + if result.status_code != 200: |
| 1228 | + self.local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info') |
| 1229 | + return False |
| 1230 | + self.local.add_log('Sent boc to toncenter', 'info') |
| 1231 | + return True |
| 1232 | + |
1211 | 1233 | def WaitTransaction(self, wallet, timeout=30): |
1212 | 1234 | self.local.add_log("start WaitTransaction function", "debug") |
1213 | 1235 | timesleep = 3 |
|
0 commit comments