Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: split stake in 2 when not elected / ValidatorList in testnet #260

Open
wants to merge 2 commits into
base: mytonctrl2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,8 @@ def GetStake(self, account, args=None):
useController = self.using_liquid_staking()
stakePercent = self.local.db.get("stakePercent", 99)
vconfig = self.GetValidatorConfig()
validators = vconfig.get("validators")
config17 = self.GetConfig17()
config15 = self.GetConfig15()

# Check if optional arguments have been passed to us
if args:
Expand Down Expand Up @@ -1331,14 +1331,21 @@ def GetStake(self, account, args=None):
stake = account.balance - 50
if stake is None:
sp = stakePercent / 100

if sp > 1 or sp < 0:
self.local.add_log("Wrong stakePercent value. Using default stake.", "warning")
elif len(vconfig.validators) == 0:
stake = int(account.balance*sp/2)
if stake < config17["minStake"]: # not enough funds to divide them by 2
stake = int(account.balance*sp)
elif len(vconfig.validators) > 0:
stake = int(account.balance*sp)
else:
for validator in vconfig.validators:
# Check validator is in active period
if validator.election_date - config15["electionsEndBefore"] < get_timestamp() < validator.expire_at:
# Check validator is elected
if self.GetAdnlAddr() in [x["adnlAddr"] for x in self.GetValidatorsList()]:
stake = int(account.balance*sp)
break
else:
stake = int(account.balance*sp/2)
if stake < config17["minStake"]: # not enough funds to divide them by 2
stake = int(account.balance*sp)

# Check if we have enough coins
if stake > config17["maxStake"]:
Expand Down Expand Up @@ -1662,7 +1669,7 @@ def CreateWallet(self, name, workchain=0, version="v1", **kwargs):
if os.path.isfile(wallet_path + ".pk") and "v3" not in version:
self.local.add_log("CreateWallet error: Wallet already exists: " + name, "warning")
else:
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
wallet_path=wallet_path, subwallet=subwallet)
result = self.fift.Run(fift_args)
if "Creating new" not in result:
Expand Down Expand Up @@ -1731,7 +1738,7 @@ def import_wallet_with_version(self, key, version, **kwargs):
wallet_path = self.walletsDir + wallet_name
with open(wallet_path + ".pk", 'wb') as file:
file.write(pk_bytes)
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
fift_args = self.get_new_wallet_fift_args(version, workchain=workchain,
wallet_path=wallet_path, subwallet=subwallet)
result = self.fift.Run(fift_args)
if "Creating new" not in result:
Expand Down Expand Up @@ -2577,7 +2584,10 @@ def GetValidatorsList(self, past=False):
start = config.get("startWorkTime")
end = config.get("endWorkTime") - 60
#end if
validatorsLoad = self.GetValidatorsLoad(start, end)
if self.GetNetworkName() != "testnet":
validatorsLoad = self.GetValidatorsLoad(start, end)
else:
validatorsLoad = []
validators = config["validators"]
electionId = config.get("startWorkTime")
saveElectionEntries = self.GetSaveElectionEntries(electionId)
Expand Down