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
29 changes: 21 additions & 8 deletions mytoncore/mytoncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,17 +1428,30 @@ def ElectionEntry(self, args=None):
#end if

# Get ADNL address
adnlAddr = self.GetAdnlAddr()
adnl_addr = self.GetAdnlAddr()
adnl_addr_bytes = bytes.fromhex(adnl_addr)

# Check wether it is too early to participate
if "participateBeforeEnd" in self.local.db:
now = time.time()
if (startWorkTime - now) > self.local.db["participateBeforeEnd"] and \
(now + self.local.db["periods"]["elections"]) < startWorkTime:
return

vconfig = self.GetValidatorConfig()

have_adnl = False
# Check if ADNL address is in the list
for a in vconfig.adnl:
if base64.b64decode(a.id) == adnl_addr_bytes:
have_adnl = True
break
if not have_adnl:
raise Exception('ADNL address is not found')

# Check if election entry already completed
entries = self.GetElectionEntries()
if adnlAddr in entries:
if adnl_addr in entries:
self.local.add_log("Elections entry already completed", "info")
return
#end if
Expand All @@ -1456,32 +1469,32 @@ def ElectionEntry(self, args=None):
validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey)

# Attach ADNL addr to validator
self.AttachAdnlAddrToValidator(adnlAddr, validatorKey, endWorkTime)
self.AttachAdnlAddrToValidator(adnl_addr, validatorKey, endWorkTime)

# Get max factor
maxFactor = self.GetMaxFactor()

# Create fift's. Continue with pool or walet
if usePool:
var1 = self.CreateElectionRequest(pool, startWorkTime, adnlAddr, maxFactor)
var1 = self.CreateElectionRequest(pool, startWorkTime, adnl_addr, maxFactor)
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor, stake)
validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor, stake)

# Send boc file to TON
resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, pool.addrB64, 1.3)
self.SendFile(resultFilePath, wallet)
else:
var1 = self.CreateElectionRequest(wallet, startWorkTime, adnlAddr, maxFactor)
var1 = self.CreateElectionRequest(wallet, startWorkTime, adnl_addr, maxFactor)
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor)
validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor)

# Send boc file to TON
resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, fullElectorAddr, stake)
self.SendFile(resultFilePath, wallet)
#end if

# Save vars to json file
self.SaveElectionVarsToJsonFile(wallet=wallet, account=account, stake=stake, maxFactor=maxFactor, fullElectorAddr=fullElectorAddr, startWorkTime=startWorkTime, validatorsElectedFor=validatorsElectedFor, endWorkTime=endWorkTime, validatorKey=validatorKey, validatorPubkey_b64=validatorPubkey_b64, adnlAddr=adnlAddr, var1=var1, validatorSignature=validatorSignature, validatorPubkey=validatorPubkey)
self.SaveElectionVarsToJsonFile(wallet=wallet, account=account, stake=stake, maxFactor=maxFactor, fullElectorAddr=fullElectorAddr, startWorkTime=startWorkTime, validatorsElectedFor=validatorsElectedFor, endWorkTime=endWorkTime, validatorKey=validatorKey, validatorPubkey_b64=validatorPubkey_b64, adnlAddr=adnl_addr, var1=var1, validatorSignature=validatorSignature, validatorPubkey=validatorPubkey)

self.local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime))
#end define
Expand Down
17 changes: 17 additions & 0 deletions mytonctrl/mytonctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,26 @@ def check_vport(local, ton):
color_print(local.translate("vport_error"))
#end define


def fix_git_config(git_path: str):
args = ["git", "status"]
try:
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3)
err = process.stderr.decode("utf-8")
except Exception as e:
err = str(e)
if err:
if 'git config --global --add safe.directory' in err:
args = ["git", "config", "--global", "--add", "safe.directory", git_path]
subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
else:
raise Exception(f'Failed to check git status: {err}')


def check_git(input_args, default_repo, text):
src_dir = "/usr/src"
git_path = f"{src_dir}/{default_repo}"
fix_git_config(git_path)
default_author = "ton-blockchain"
default_branch = "master"

Expand Down