Skip to content

Commit da1811d

Browse files
authored
Merge pull request #164 from yungwine/master
Duplicate externals to TonCenter
2 parents b9d5937 + cfc85fc commit da1811d

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

mytoncore.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,14 +1430,32 @@ def SendFile(self, filePath, wallet=None, **kwargs):
14301430
wallet.oldseqno = self.GetSeqno(wallet)
14311431
self.liteClient.Run("sendfile " + filePath)
14321432
if duplicateSendfile:
1433-
self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False)
1434-
self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False)
1433+
self.send_boc_toncenter(filePath)
1434+
# self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False)
1435+
# self.liteClient.Run("sendfile " + filePath, useLocalLiteServer=False)
14351436
if timeout and wallet:
14361437
self.WaitTransaction(wallet, timeout)
14371438
if remove == True:
14381439
os.remove(filePath)
14391440
#end define
14401441

1442+
def send_boc_toncenter(self, file_path: str):
1443+
local.add_log('Start send_boc_toncenter function: ' + file_path, 'debug')
1444+
with open(file_path, "rb") as f:
1445+
boc = f.read()
1446+
boc_b64 = base64.b64encode(boc).decode("utf-8")
1447+
data = {"boc": boc_b64}
1448+
if self.GetNetworkName() == 'testnet':
1449+
url = 'https://testnet.toncenter.com/api/v2/sendBoc'
1450+
else:
1451+
url = 'https://toncenter.com/api/v2/sendBoc'
1452+
result = requests.post(url=url, json=data)
1453+
if result.status_code != 200:
1454+
local.add_log(f'Failed to send boc to toncenter: {result.content}', 'info')
1455+
return False
1456+
local.add_log('Sent boc to toncenter', 'info')
1457+
return True
1458+
14411459
def WaitTransaction(self, wallet, timeout=30):
14421460
local.add_log("start WaitTransaction function", "debug")
14431461
timesleep = 3

0 commit comments

Comments
 (0)