@@ -1430,14 +1430,35 @@ 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+ try :
1434+ self .liteClient .Run ("sendfile " + filePath , useLocalLiteServer = False )
1435+ self .liteClient .Run ("sendfile " + filePath , useLocalLiteServer = False )
1436+ except Exception as e :
1437+ local .add_log ('failed to send file via liteclient: ' + str (e ), 'info' )
1438+ self .send_boc_toncenter (filePath )
14351439 if timeout and wallet :
14361440 self .WaitTransaction (wallet , timeout )
14371441 if remove == True :
14381442 os .remove (filePath )
14391443 #end define
14401444
1445+ def send_boc_toncenter (self , file_path : str ):
1446+ local .add_log ('Start send_boc_toncenter function: ' + file_path , 'debug' )
1447+ with open (file_path , "rb" ) as f :
1448+ boc = f .read ()
1449+ boc_b64 = base64 .b64encode (boc ).decode ("utf-8" )
1450+ data = {"boc" : boc_b64 }
1451+ if self .GetNetworkName () == 'testnet' :
1452+ url = 'https://testnet.toncenter.com/api/v2/sendBoc'
1453+ else :
1454+ url = 'https://toncenter.com/api/v2/sendBoc'
1455+ result = requests .post (url = url , json = data )
1456+ if result .status_code != 200 :
1457+ local .add_log (f'Failed to send boc to toncenter: { result .content } ' , 'info' )
1458+ return False
1459+ local .add_log ('Sent boc to toncenter' , 'info' )
1460+ return True
1461+
14411462 def WaitTransaction (self , wallet , timeout = 30 ):
14421463 local .add_log ("start WaitTransaction function" , "debug" )
14431464 timesleep = 3
@@ -2060,12 +2081,13 @@ def MoveCoinsFromHW(self, wallet, destList, **kwargs):
20602081
20612082 def GetValidatorKey (self ):
20622083 vconfig = self .GetValidatorConfig ()
2063- for validator in vconfig .validators :
2084+ validators = sorted (vconfig ["validators" ], key = lambda i : i ['election_date' ], reverse = True )
2085+ for validator in validators :
20642086 validatorId = validator ["id" ]
20652087 key_bytes = base64 .b64decode (validatorId )
20662088 validatorKey = key_bytes .hex ().upper ()
20672089 timestamp = get_timestamp ()
2068- if timestamp > validator ["election_date " ]:
2090+ if validator [ "election_date" ] < timestamp < validator ["expire_at " ]:
20692091 return validatorKey
20702092 raise Exception ("GetValidatorKey error: validator key not found. Are you sure you are a validator?" )
20712093 #end define
@@ -2378,7 +2400,7 @@ def GetComplaints(self, electionId=None, past=False):
23782400 def GetSaveComplaints (self ):
23792401 timestamp = get_timestamp ()
23802402 saveComplaints = local .db .get ("saveComplaints" )
2381- if type ( saveComplaints ) is not dict :
2403+ if saveComplaints is None :
23822404 saveComplaints = dict ()
23832405 local .db ["saveComplaints" ] = saveComplaints
23842406 buff = saveComplaints .copy ()
@@ -3043,7 +3065,7 @@ def WriteBookmarkData(self, bookmark):
30433065 def GetSaveOffers (self ):
30443066 bname = "saveOffers"
30453067 saveOffers = local .db .get (bname )
3046- if type ( saveOffers ) != dict :
3068+ if saveOffers is None :
30473069 saveOffers = dict ()
30483070 local .db [bname ] = saveOffers
30493071 return saveOffers
0 commit comments