Skip to content

Commit 8af9b98

Browse files
committed
fix: split stake in 2 when not elected / ValidatorList in textnet
1 parent f97cfff commit 8af9b98

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

mytoncore/mytoncore.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@ def GetStake(self, account, args=None):
13021302
useController = self.using_liquid_staking()
13031303
stakePercent = self.local.db.get("stakePercent", 99)
13041304
vconfig = self.GetValidatorConfig()
1305-
validators = vconfig.get("validators")
13061305
config17 = self.GetConfig17()
1306+
config15 = self.GetConfig15()
13071307

13081308
# Check if optional arguments have been passed to us
13091309
if args:
@@ -1331,14 +1331,21 @@ def GetStake(self, account, args=None):
13311331
stake = account.balance - 50
13321332
if stake is None:
13331333
sp = stakePercent / 100
1334+
13341335
if sp > 1 or sp < 0:
13351336
self.local.add_log("Wrong stakePercent value. Using default stake.", "warning")
1336-
elif len(vconfig.validators) == 0:
1337-
stake = int(account.balance*sp/2)
1338-
if stake < config17["minStake"]: # not enough funds to divide them by 2
1339-
stake = int(account.balance*sp)
1340-
elif len(vconfig.validators) > 0:
1341-
stake = int(account.balance*sp)
1337+
else:
1338+
for validator in vconfig.validators:
1339+
# Check validator is in active period
1340+
if validator.election_date - config15["elections_end_before"] < get_timestamp() < validator.expire_at:
1341+
# Check validator is elected
1342+
if self.GetAdnlAddr() in self.GetValidatorsList():
1343+
stake = int(account.balance*sp)
1344+
break
1345+
else:
1346+
stake = int(account.balance*sp/2)
1347+
if stake < config17["minStake"]: # not enough funds to divide them by 2
1348+
stake = int(account.balance*sp)
13421349

13431350
# Check if we have enough coins
13441351
if stake > config17["maxStake"]:
@@ -1662,7 +1669,7 @@ def CreateWallet(self, name, workchain=0, version="v1", **kwargs):
16621669
if os.path.isfile(wallet_path + ".pk") and "v3" not in version:
16631670
self.local.add_log("CreateWallet error: Wallet already exists: " + name, "warning")
16641671
else:
1665-
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
1672+
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
16661673
wallet_path=wallet_path, subwallet=subwallet)
16671674
result = self.fift.Run(fift_args)
16681675
if "Creating new" not in result:
@@ -1731,7 +1738,7 @@ def import_wallet_with_version(self, key, version, **kwargs):
17311738
wallet_path = self.walletsDir + wallet_name
17321739
with open(wallet_path + ".pk", 'wb') as file:
17331740
file.write(pk_bytes)
1734-
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
1741+
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
17351742
wallet_path=wallet_path, subwallet=subwallet)
17361743
result = self.fift.Run(fift_args)
17371744
if "Creating new" not in result:
@@ -2577,7 +2584,10 @@ def GetValidatorsList(self, past=False):
25772584
start = config.get("startWorkTime")
25782585
end = config.get("endWorkTime") - 60
25792586
#end if
2580-
validatorsLoad = self.GetValidatorsLoad(start, end)
2587+
if self.GetNetworkName() != "testnet":
2588+
validatorsLoad = self.GetValidatorsLoad(start, end)
2589+
else:
2590+
validatorsLoad = []
25812591
validators = config["validators"]
25822592
electionId = config.get("startWorkTime")
25832593
saveElectionEntries = self.GetSaveElectionEntries(electionId)

0 commit comments

Comments
 (0)