@@ -1223,11 +1223,17 @@ def SendFile(self, filePath, wallet=None, **kwargs):
12231223 self .liteClient .Run ("sendfile " + filePath , useLocalLiteServer = False )
12241224 except : pass
12251225 if duplicateApi :
1226- self .send_boc_toncenter (filePath )
1226+ try :
1227+ self .send_boc_toncenter (filePath )
1228+ except Exception as e :
1229+ self .local .add_log (f'Failed to send file { filePath } to toncenter: { e } ' , 'warning' )
12271230 if timeout and wallet :
12281231 self .WaitTransaction (wallet , timeout )
1229- if remove == True :
1230- os .remove (filePath )
1232+ if remove :
1233+ try :
1234+ os .remove (filePath )
1235+ except Exception as e :
1236+ self .local .add_log (f'Failed to remove file { filePath } : { e } ' , 'warning' )
12311237 #end define
12321238
12331239 def send_boc_toncenter (self , file_path : str ):
@@ -2274,23 +2280,23 @@ def SignComplaintVoteRequestWithValidator(self, complaintHash, electionId, valid
22742280 return fileName
22752281 #end define
22762282
2277- def VoteOffer (self , offerHash ):
2283+ def VoteOffer (self , offer ):
22782284 self .local .add_log ("start VoteOffer function" , "debug" )
2279- fullConfigAddr = self .GetFullConfigAddr ()
2285+ full_config_addr = self .GetFullConfigAddr ()
22802286 wallet = self .GetValidatorWallet (mode = "vote" )
2281- validatorKey = self .GetValidatorKey ()
2282- validatorPubkey_b64 = self .GetPubKeyBase64 (validatorKey )
2283- validatorIndex = self .GetValidatorIndex ()
2284- offer = self . GetOffer ( offerHash )
2285- if validatorIndex in offer .get ("votedValidators" ):
2287+ validator_key = self .GetValidatorKey ()
2288+ validator_pubkey_b64 = self .GetPubKeyBase64 (validator_key )
2289+ validator_index = self .GetValidatorIndex ()
2290+ offer_hash = offer . get ( "hash" )
2291+ if validator_index in offer .get ("votedValidators" ):
22862292 self .local .add_log ("Proposal already has been voted" , "debug" )
22872293 return
22882294 self .add_save_offer (offer )
2289- var1 = self .CreateConfigProposalRequest (offerHash , validatorIndex )
2290- validatorSignature = self .GetValidatorSignature (validatorKey , var1 )
2291- resultFilePath = self .SignProposalVoteRequestWithValidator (offerHash , validatorIndex , validatorPubkey_b64 , validatorSignature )
2292- resultFilePath = self .SignBocWithWallet (wallet , resultFilePath , fullConfigAddr , 1.5 )
2293- self .SendFile (resultFilePath , wallet )
2295+ var1 = self .CreateConfigProposalRequest (offer_hash , validator_index )
2296+ validator_signature = self .GetValidatorSignature (validator_key , var1 )
2297+ result_file_path = self .SignProposalVoteRequestWithValidator (offer_hash , validator_index , validator_pubkey_b64 , validator_signature )
2298+ result_file_path = self .SignBocWithWallet (wallet , result_file_path , full_config_addr , 1.5 )
2299+ self .SendFile (result_file_path , wallet , remove = False )
22942300 #end define
22952301
22962302 def VoteComplaint (self , electionId , complaintHash ):
@@ -2598,11 +2604,12 @@ def CheckValidators(self, start, end):
25982604 self .local .add_log ("var1: {}, var2: {}, pubkey: {}, election_id: {}" .format (var1 , var2 , pubkey , electionId ), "debug" )
25992605 #end define
26002606
2601- def GetOffer (self , offerHash ):
2607+ def GetOffer (self , offer_hash : str , offers : list = None ):
26022608 self .local .add_log ("start GetOffer function" , "debug" )
2603- offers = self .GetOffers ()
2609+ if offers is None :
2610+ offers = self .GetOffers ()
26042611 for offer in offers :
2605- if offerHash == offer .get ("hash" ):
2612+ if offer_hash == offer .get ("hash" ):
26062613 return offer
26072614 raise Exception ("GetOffer error: offer not found." )
26082615 #end define
@@ -2872,9 +2879,11 @@ def offers_gc(self, save_offers):
28722879 if offer_hash not in current_offers_hashes :
28732880 if isinstance (offer , list ):
28742881 param_id = offer [1 ]
2875- if param_id is not None and offer [0 ] != self .calculate_offer_pseudohash (offer_hash , param_id ):
2882+ phash = self .calculate_offer_pseudohash (offer_hash , param_id )
2883+ if param_id is not None and offer [0 ] != phash :
28762884 # param has been changed so no need to keep anymore
28772885 save_offers .pop (offer_hash )
2886+ self .local .add_log (f"Removing offer { offer_hash } from save_offers. Saved phash: { offer [0 ]} , now phash: { phash } " , "debug" )
28782887 else : # old version of offer in db
28792888 save_offers .pop (offer_hash )
28802889 return save_offers
@@ -2885,7 +2894,6 @@ def GetSaveOffers(self):
28852894 if save_offers is None or isinstance (save_offers , list ):
28862895 save_offers = dict ()
28872896 self .local .db [bname ] = save_offers
2888- self .offers_gc (save_offers )
28892897 return save_offers
28902898 #end define
28912899
@@ -3208,12 +3216,15 @@ def set_initial_sync_off(self):
32083216 self .local .db .pop ('initialSync' , None )
32093217 self .local .save ()
32103218
3211- def Tlb2Json (self , text ):
3219+ def Tlb2Json (self , text : str ):
32123220 # Заменить скобки
32133221 start = 0
32143222 end = len (text )
32153223 if '=' in text :
32163224 start = text .find ('=' )+ 1
3225+ if text [start :].startswith (' x{' ): # param has no tlb scheme, return cell value
3226+ end = text .rfind ('}' )+ 1
3227+ return {'_' : text [start :end ].strip ()}
32173228 if "x{" in text :
32183229 end = text .find ("x{" )
32193230 text = text [start :end ]
0 commit comments