@@ -80,7 +80,17 @@ class Alert:
8080 "info" ,
8181 "Validator's stake {stake} TON has been accepted" ,
8282 ELECTIONS_START_BEFORE
83- )
83+ ),
84+ "stake_returned" : Alert (
85+ "info" ,
86+ "Validator's stake {stake} TON has been returned on address {address}. The reward amount is {reward} TON." ,
87+ 0
88+ ),
89+ "stake_not_returned" : Alert (
90+ "high" ,
91+ "Validator's stake has not been returned on address {address}." ,
92+ 0
93+ ),
8494}
8595
8696
@@ -283,32 +293,53 @@ def check_adnl_connection_failed(self):
283293 if not ok :
284294 self .send_alert ("adnl_connection_failed" )
285295
286- def get_myself_from_election (self ):
287- config = self .ton .GetConfig36 ()
296+ def get_myself_from_election (self , config : dict ):
288297 if not config ["validators" ]:
289298 return
290- validator = self .validator_module .find_myself (config ["validators" ])
291- if validator is None :
292- return False
299+ adnl = self .ton .GetAdnlAddr ()
293300 save_elections = self .ton .GetSaveElections ()
294301 elections = save_elections .get (str (config ["startWorkTime" ]))
295302 if elections is None :
296- return validator
297- adnl = self .ton .GetAdnlAddr ()
303+ return
304+ if adnl not in elections : # didn't participate in elections
305+ return
306+ validator = self .validator_module .find_myself (config ["validators" ])
307+ if validator is None :
308+ return False
298309 validator ['stake' ] = elections [adnl ].get ('stake' )
310+ validator ['walletAddr' ] = elections [adnl ].get ('walletAddr' )
299311 return validator
300312
301- def check_stake (self ):
313+ def check_stake_sent (self ):
302314 if not self .ton .using_validator ():
303315 return
304- res = self .get_myself_from_election ()
316+ config = self .ton .GetConfig36 ()
317+ res = self .get_myself_from_election (config )
305318 if res is None :
306319 return
307320 if res is False :
308321 self .send_alert ("stake_not_accepted" )
309322 return
310323 self .send_alert ("stake_accepted" , stake = res .get ('stake' ))
311324
325+ def check_stake_returned (self ):
326+ if not self .ton .using_validator ():
327+ return
328+ config = self .ton .GetConfig32 ()
329+ if not (config ['endWorkTime' ] + FREEZE_PERIOD + 1200 <= time .time () < config ['endWorkTime' ] + FREEZE_PERIOD + 1260 ): # check between 20th and 21st minutes after stakes have been unfrozen
330+ return
331+ res = self .get_myself_from_election (config )
332+ if not res :
333+ return
334+ trs = self .ton .GetAccountHistory (self .ton .GetAccount (res ["walletAddr" ]), limit = 10 )
335+
336+ for tr in trs :
337+ if tr .time >= config ['endWorkTime' ] + FREEZE_PERIOD and tr .srcAddr == '3333333333333333333333333333333333333333333333333333333333333333' and tr .body .startswith ('F96F7324' ): # Elector Recover Stake Response
338+ self .send_alert ("stake_returned" , stake = res .get ('stake' ), address = res ["walletAddr" ], reward = tr .value - res .get ('stake' , 0 ))
339+ return
340+ self .send_alert ("stake_not_returned" , address = res ["walletAddr" ])
341+
342+
312343 def check_status (self ):
313344 if not self .ton .using_alert_bot ():
314345 return
@@ -323,7 +354,8 @@ def check_status(self):
323354 self .local .try_function (self .check_sync )
324355 self .local .try_function (self .check_slashed )
325356 self .local .try_function (self .check_adnl_connection_failed )
326- self .local .try_function (self .check_stake )
357+ self .local .try_function (self .check_stake_sent )
358+ self .local .try_function (self .check_stake_returned )
327359
328360 def add_console_commands (self , console ):
329361 console .AddItem ("enable_alert" , self .enable_alert , self .local .translate ("enable_alert_cmd" ))
0 commit comments