@@ -1317,8 +1317,7 @@ def GetStake(self, account, args=None):
13171317 if stake > account .balance - 10 :
13181318 stake = account .balance - 10
13191319
1320- pool_version = self .GetVersionFromCodeHash (account .codeHash )
1321- is_single_nominator = pool_version is not None and 'spool' in pool_version
1320+ is_single_nominator = self .is_account_single_nominator (account )
13221321
13231322 if stake is None and usePool and not is_single_nominator :
13241323 stake = account .balance - 20
@@ -1406,6 +1405,7 @@ def ElectionEntry(self, args=None):
14061405 if (startWorkTime - now ) > self .local .db ["participateBeforeEnd" ] and \
14071406 (now + self .local .db ["periods" ]["elections" ]) < startWorkTime :
14081407 return
1408+ #end if
14091409
14101410 vconfig = self .GetValidatorConfig ()
14111411
@@ -1415,8 +1415,10 @@ def ElectionEntry(self, args=None):
14151415 if base64 .b64decode (a .id ) == adnl_addr_bytes :
14161416 have_adnl = True
14171417 break
1418+ #end for
14181419 if not have_adnl :
14191420 raise Exception ('ADNL address is not found' )
1421+ #end if
14201422
14211423 # Check if election entry already completed
14221424 entries = self .GetElectionEntries ()
@@ -1426,14 +1428,13 @@ def ElectionEntry(self, args=None):
14261428 #end if
14271429
14281430 if usePool :
1429- pool = self .GetPool ( mode = "stake" )
1431+ pool = self .get_pool ( )
14301432 addrB64 = pool .addrB64
14311433 elif useController :
14321434 controllerAddr = self .GetController (mode = "stake" )
14331435 self .CheckController (controllerAddr )
14341436 self .CreateLoanRequest (controllerAddr )
14351437 addrB64 = controllerAddr
1436- #end if
14371438
14381439 # Calculate stake
14391440 account = self .GetAccount (addrB64 )
@@ -3547,35 +3548,44 @@ def GetPools(self):
35473548 return pools
35483549 #end define
35493550
3550- def GetPool (self , mode ):
3551+ def get_pool (self ):
35513552 pools = self .GetPools ()
35523553 for pool in pools :
3553- if mode == "stake" and self .IsPoolReadyToStake (pool .addrB64 ):
3554- return pool
3555- if mode == "vote" and self .IsPoolReadyToVote (pool .addrB64 ):
3554+ if self .is_pool_ready_to_stake (pool ):
35563555 return pool
35573556 raise Exception ("Validator pool not found or not ready" )
35583557 #end define
35593558
3560- def GetPoolLastSentStakeTime (self , addrB64 ):
3561- poolData = self .GetPoolData (addrB64 )
3562- return poolData ["stakeAt" ]
3559+ def get_pool_last_sent_stake_time (self , addrB64 ):
3560+ pool_data = self .GetPoolData (addrB64 )
3561+ return pool_data ["stakeAt" ]
35633562 #end define
35643563
3565- def IsPoolReadyToStake (self , addrB64 ):
3564+ def is_pool_ready_to_stake (self , pool : Pool ):
3565+ addr = pool .addrB64
3566+ account = self .GetAccount (addr )
3567+ is_single_nominator = self .is_account_single_nominator (account )
3568+ if self .using_single_nominator () and not is_single_nominator :
3569+ return False
3570+ try : # check that account balance is enough for stake
3571+ stake = self .GetStake (account )
3572+ if not stake :
3573+ raise Exception (f'Stake is { stake } ' )
3574+ except Exception as e :
3575+ self .local .add_log (f"Failed to get stake for pool { addr } : { e } " , "debug" )
3576+ return False
35663577 now = get_timestamp ()
35673578 config15 = self .GetConfig15 ()
3568- lastSentStakeTime = self .GetPoolLastSentStakeTime ( addrB64 )
3569- stakeFreezeDelay = config15 ["validatorsElectedFor" ] + config15 ["stakeHeldFor" ]
3570- result = lastSentStakeTime + stakeFreezeDelay < now
3571- print (f"{ addrB64 } : { result } . { lastSentStakeTime } , { stakeFreezeDelay } , { now } " )
3579+ last_sent_stake_time = self .get_pool_last_sent_stake_time ( addr )
3580+ stake_freeze_delay = config15 ["validatorsElectedFor" ] + config15 ["stakeHeldFor" ]
3581+ result = last_sent_stake_time + stake_freeze_delay < now
3582+ print (f"{ addr } : { result } . { last_sent_stake_time } , { stake_freeze_delay } , { now } " )
35723583 return result
35733584 #end define
35743585
3575- def IsPoolReadyToVote (self , addrB64 ):
3576- vwl = self .GetValidatorsWalletsList ()
3577- result = addrB64 in vwl
3578- return result
3586+ def is_account_single_nominator (self , account : Account ):
3587+ account_version = self .GetVersionFromCodeHash (account .codeHash )
3588+ return account_version is not None and 'spool' in account_version
35793589 #end define
35803590
35813591 def GetPoolData (self , addrB64 ):
0 commit comments