From ddc3468eafdbd092826f8339beb8803597678589 Mon Sep 17 00:00:00 2001 From: sonofmom Date: Tue, 26 May 2020 14:50:12 +0200 Subject: [PATCH 1/4] Enable agruments for election entry (ve) --- mytoncore.py | 42 +++++++++++++++++++++++++++++++++++------- mytonctrl.py | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) mode change 100644 => 100755 mytonctrl.py diff --git a/mytoncore.py b/mytoncore.py index 12abec55..3f84faaa 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -3,6 +3,7 @@ import crc16 import struct +import re from mypylib.mypylib import * local = MyPyClass(__file__) @@ -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") @@ -734,11 +735,38 @@ 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) + # Check if optional arguments have been passed to us + if args: + m = re.match(r"(\d+\.?\d?)\%", args[0]) + if m: + # Stake was in percent + stake = round((account.balance / 100) * float(m.group(1))) + elif desiredStake.isnumeric(): + # Stake was a number + stake = int(args[0]) + 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: + 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) + + rateMultiplier = 1 # Calculate endWorkTime validatorsElectedFor = self.GetValidatorsElectedFor() @@ -757,7 +785,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) diff --git a/mytonctrl.py b/mytonctrl.py old mode 100644 new mode 100755 index 21109755..38cb26bd --- a/mytonctrl.py +++ b/mytonctrl.py @@ -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 From 502c5c95640885be4aa3fa57401c23261d46b236 Mon Sep 17 00:00:00 2001 From: sonofmom Date: Tue, 26 May 2020 14:57:57 +0200 Subject: [PATCH 2/4] Fixed comparison with available funds --- mytoncore.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mytoncore.py b/mytoncore.py index 3f84faaa..77bab7c6 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -749,7 +749,7 @@ def ElectionEntry(self,args): return # Limit stake to maximum available amount minus 10 (for transaction fees) - if stake > account.balance: + if stake > account.balance - 10: stake = account.balance - 10 if minStake > stake: From 1502923438e18a09b6a382e18a7045ffad4cf2b9 Mon Sep 17 00:00:00 2001 From: sonofmom Date: Tue, 26 May 2020 14:59:54 +0200 Subject: [PATCH 3/4] Ensure rateMultiplier is set in all scenarios --- mytoncore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 77bab7c6..34394e26 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -735,6 +735,9 @@ def ElectionEntry(self,args): local.AddLog("You don't have enough grams. Minimum stake: " + str(minStake), "debug") return + # Default rate multiplier + rateMultiplier = 1 + # Check if optional arguments have been passed to us if args: m = re.match(r"(\d+\.?\d?)\%", args[0]) @@ -766,8 +769,6 @@ def ElectionEntry(self,args): if len(validators) > 0 or (stake is not None and stake < minStake): stake = int(account.balance*0.99) - rateMultiplier = 1 - # Calculate endWorkTime validatorsElectedFor = self.GetValidatorsElectedFor() endWorkTime = startWorkTime + validatorsElectedFor + 300 # 300 sec - margin of seconds From 361d080e058c696da5c4e038e95c39821d2d8004 Mon Sep 17 00:00:00 2001 From: sonofmom Date: Tue, 26 May 2020 15:04:08 +0200 Subject: [PATCH 4/4] Write argument into it's own variable for easier understanding --- mytoncore.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mytoncore.py b/mytoncore.py index 34394e26..3c89cd80 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -740,13 +740,14 @@ def ElectionEntry(self,args): # Check if optional arguments have been passed to us if args: - m = re.match(r"(\d+\.?\d?)\%", args[0]) + 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(args[0]) + stake = int(desiredStake) else: local.AddLog("Specified stake must be a percentage or whole number", "error") return