Skip to content
Merged
Show file tree
Hide file tree
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
44 changes: 37 additions & 7 deletions mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import crc16
import struct
import re
from mypylib.mypylib import *

local = MyPyClass(__file__)
Expand Down Expand Up @@ -701,7 +702,7 @@ def RecoverStake(self):
return resultFilePath
#end define

def ElectionEntry(self):
def ElectionEntry(self,args):
#self.TestElectionEntry()

local.AddLog("start ElectionEntry function", "debug")
Expand Down Expand Up @@ -734,11 +735,40 @@ def ElectionEntry(self):
local.AddLog("You don't have enough grams. Minimum stake: " + str(minStake), "debug")
return

# Calculate stake
if len(validators) == 0:
stake = int(account.balance*0.99/2)
if len(validators) > 0 or (stake is not None and stake < minStake):
stake = int(account.balance*0.99)
# Default rate multiplier
rateMultiplier = 1

# Check if optional arguments have been passed to us
if args:
desiredStake = args[0]
m = re.match(r"(\d+\.?\d?)\%", desiredStake)
if m:
# Stake was in percent
stake = round((account.balance / 100) * float(m.group(1)))
elif desiredStake.isnumeric():
# Stake was a number
stake = int(desiredStake)
else:
local.AddLog("Specified stake must be a percentage or whole number", "error")
return

# Limit stake to maximum available amount minus 10 (for transaction fees)
if stake > account.balance - 10:
stake = account.balance - 10

if minStake > stake:
local.AddLog('Stake is smaller then Minimum stake: ' + str(minStake), "error")
return

# Get rateMultiplier
if len(args) > 1:
rateMultiplier = float(args[1])
else:
# Calculate stake
if len(validators) == 0:
stake = int(account.balance*0.99/2)
if len(validators) > 0 or (stake is not None and stake < minStake):
stake = int(account.balance*0.99)

# Calculate endWorkTime
validatorsElectedFor = self.GetValidatorsElectedFor()
Expand All @@ -757,7 +787,7 @@ def ElectionEntry(self):
self.AttachAdnlAddrToValidator(adnlAddr, validatorKey, endWorkTime)

# Create fift's
rate = round(stake / minStake, 1)
rate = round((stake / minStake) * rateMultiplier, 1)
var1 = self.CreateElectionRequest(wallet, startWorkTime, adnlAddr, rate)
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, rate)
Expand Down
2 changes: 1 addition & 1 deletion mytonctrl.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def VoteElectionEntry(args):
if ton.validatorWalletName is None:
ColorPrint("{red}You are not a validator, or this utility is not configured correctly.{endc}")
ton.ReturnStake()
ton.ElectionEntry()
ton.ElectionEntry(args)
ColorPrint("VoteElectionEntry - {green}OK{endc}")
#end define

Expand Down