Skip to content

Commit 06b31e3

Browse files
authored
Merge pull request #165 from yungwine/mytonctrl2_dev
add duplicating externals to toncenter
2 parents 4b0811d + bf2de37 commit 06b31e3

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

mytoncore/mytoncore.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import psutil
99
import subprocess
1010
import pkg_resources
11+
import requests
1112
from fastcrc import crc16
1213

1314
from mytoncore.utils import xhex2hex, ng2g
@@ -1200,14 +1201,35 @@ def SendFile(self, filePath, wallet=None, **kwargs):
12001201
wallet.oldseqno = self.GetSeqno(wallet)
12011202
self.liteClient.Run("sendfile " + filePath)
12021203
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)
12051207
if timeout and wallet:
12061208
self.WaitTransaction(wallet, timeout)
12071209
if remove == True:
12081210
os.remove(filePath)
12091211
#end define
12101212

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+
12111233
def WaitTransaction(self, wallet, timeout=30):
12121234
self.local.add_log("start WaitTransaction function", "debug")
12131235
timesleep = 3

0 commit comments

Comments
 (0)