Skip to content

Commit e3d152e

Browse files
authored
Merge pull request #314 from yungwine/mytonctrl2_dev
check validator wallet status before activating pool
2 parents cf3f94c + f50f6af commit e3d152e

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-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+
'validatorWalletName': Setting('validator', 'wallet_001', 'Validator\'s 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_active(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_active(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: 22 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,25 @@ 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"Account {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_active(self, account):
1874+
if not isinstance(account, Account):
1875+
address = account
1876+
account = self.GetAccount(account)
1877+
else:
1878+
address = account.addrB64
1879+
if account.status != "active":
1880+
raise Exception(f"Account {address} account is uninitialized")
1881+
# end if
1882+
# end define
1883+
18671884
def MoveCoins(self, wallet, dest, coins, **kwargs):
18681885
self.local.add_log("start MoveCoins function", "debug")
18691886
flags = kwargs.get("flags", list())
@@ -1884,11 +1901,8 @@ def MoveCoins(self, wallet, dest, coins, **kwargs):
18841901

18851902
# Balance checking
18861903
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
1904+
self.check_account_balance(account, coins + 0.1)
1905+
self.check_account_active(account)
18921906

18931907
# Bounceable checking
18941908
destAccount = self.GetAccount(dest)

0 commit comments

Comments
 (0)