Skip to content

Commit c34a459

Browse files
committed
check validator wallet status before activating pool
1 parent 7c8a5c9 commit c34a459

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

modules/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Setting:
3434
'stake': Setting('validator', None, 'Stake amount'),
3535
'stakePercent': Setting('validator', 99, 'Stake percent if `stake` is null'),
3636
'isSlashing': Setting('validator', None, 'Create complaints to validators'),
37+
'walletName': Setting('validator', None, 'Wallet name'),
3738
'maxFactor': Setting('validator', None, 'Param send to Elector. if null will be taken from 17 config param'),
3839
'participateBeforeEnd': Setting('validator', None, 'Amount of seconds before start of round to participate'),
3940
'liquid_pool_addr': Setting('liquid-staking', None, 'Liquid staking pool address'),

modules/nominator_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def do_activate_pool(self, pool, ex=True):
6262
elif account.status == "active":
6363
self.local.add_log("do_activate_pool warning: account status is active", "warning")
6464
else:
65+
validator_wallet = self.ton.GetValidatorWallet()
66+
self.ton.check_account_status(validator_wallet.addrB64)
6567
self.ton.SendFile(pool.bocFilePath, pool, timeout=False, remove=False)
6668
#end define
6769

modules/single_pool.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def do_activate_single_pool(self, pool):
5151
self.local.add_log("start activate_single_pool function", "debug")
5252
boc_mode = "--with-init"
5353
validator_wallet = self.ton.GetValidatorWallet()
54+
self.ton.check_account_status(validator_wallet.addrB64)
5455
result_file_path = self.ton.SignBocWithWallet(validator_wallet, pool.bocFilePath, pool.addrB64_init, 1, boc_mode=boc_mode)
5556
self.ton.SendFile(result_file_path, validator_wallet)
5657

mytoncore/mytoncore.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,9 +1180,7 @@ def SignBocWithWallet(self, wallet, boc_path, dest, coins, **kwargs):
11801180

11811181
# Balance checking
11821182
account = self.GetAccount(wallet.addrB64)
1183-
if account.balance < coins + 0.1:
1184-
raise Exception("Wallet balance is less than requested coins")
1185-
#end if
1183+
self.check_account_balance(account, coins + 0.1)
11861184

11871185
# Bounceable checking
11881186
destAccount = self.GetAccount(dest)
@@ -1864,6 +1862,22 @@ def GetWalletId(self, wallet):
18641862
return subwallet
18651863
#end define
18661864

1865+
def check_account_balance(self, account, coins):
1866+
if not isinstance(account, Account):
1867+
account = self.GetAccount(account)
1868+
if account.balance < coins:
1869+
raise Exception(f"Wallet {account.addrB64} balance is less than requested coins. Balance: {account.balance}, requested amount: {coins} (need {coins - account.balance} more)")
1870+
# end if
1871+
# end define
1872+
1873+
def check_account_status(self, account):
1874+
if not isinstance(account, Account):
1875+
account = self.GetAccount(account)
1876+
if account.status != "active":
1877+
raise Exception(f"Wallet {account.addrB64} account is uninitialized")
1878+
# end if
1879+
# end define
1880+
18671881
def MoveCoins(self, wallet, dest, coins, **kwargs):
18681882
self.local.add_log("start MoveCoins function", "debug")
18691883
flags = kwargs.get("flags", list())
@@ -1884,11 +1898,8 @@ def MoveCoins(self, wallet, dest, coins, **kwargs):
18841898

18851899
# Balance checking
18861900
account = self.GetAccount(wallet.addrB64)
1887-
if account.balance < coins + 0.1:
1888-
raise Exception("Wallet balance is less than requested coins")
1889-
if account.status != "active":
1890-
raise Exception("Wallet account is uninitialized")
1891-
#end if
1901+
self.check_account_balance(account, coins + 0.1)
1902+
self.check_account_status(account)
18921903

18931904
# Bounceable checking
18941905
destAccount = self.GetAccount(dest)

0 commit comments

Comments
 (0)