Skip to content

Commit dcb0198

Browse files
authored
Merge pull request #188 from yungwine/mytonctrl2_dev
git config and adnl address
2 parents b201751 + 777b1bf commit dcb0198

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

mytoncore/mytoncore.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,17 +1428,30 @@ def ElectionEntry(self, args=None):
14281428
#end if
14291429

14301430
# Get ADNL address
1431-
adnlAddr = self.GetAdnlAddr()
1431+
adnl_addr = self.GetAdnlAddr()
1432+
adnl_addr_bytes = bytes.fromhex(adnl_addr)
14321433

14331434
# Check wether it is too early to participate
14341435
if "participateBeforeEnd" in self.local.db:
14351436
now = time.time()
14361437
if (startWorkTime - now) > self.local.db["participateBeforeEnd"] and \
14371438
(now + self.local.db["periods"]["elections"]) < startWorkTime:
14381439
return
1440+
1441+
vconfig = self.GetValidatorConfig()
1442+
1443+
have_adnl = False
1444+
# Check if ADNL address is in the list
1445+
for a in vconfig.adnl:
1446+
if base64.b64decode(a.id) == adnl_addr_bytes:
1447+
have_adnl = True
1448+
break
1449+
if not have_adnl:
1450+
raise Exception('ADNL address is not found')
1451+
14391452
# Check if election entry already completed
14401453
entries = self.GetElectionEntries()
1441-
if adnlAddr in entries:
1454+
if adnl_addr in entries:
14421455
self.local.add_log("Elections entry already completed", "info")
14431456
return
14441457
#end if
@@ -1456,32 +1469,32 @@ def ElectionEntry(self, args=None):
14561469
validatorPubkey_b64 = self.GetPubKeyBase64(validatorKey)
14571470

14581471
# Attach ADNL addr to validator
1459-
self.AttachAdnlAddrToValidator(adnlAddr, validatorKey, endWorkTime)
1472+
self.AttachAdnlAddrToValidator(adnl_addr, validatorKey, endWorkTime)
14601473

14611474
# Get max factor
14621475
maxFactor = self.GetMaxFactor()
14631476

14641477
# Create fift's. Continue with pool or walet
14651478
if usePool:
1466-
var1 = self.CreateElectionRequest(pool, startWorkTime, adnlAddr, maxFactor)
1479+
var1 = self.CreateElectionRequest(pool, startWorkTime, adnl_addr, maxFactor)
14671480
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
1468-
validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor, stake)
1481+
validatorPubkey, resultFilePath = self.SignElectionRequestWithPoolWithValidator(pool, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor, stake)
14691482

14701483
# Send boc file to TON
14711484
resultFilePath = self.SignBocWithWallet(wallet, resultFilePath, pool.addrB64, 1.3)
14721485
self.SendFile(resultFilePath, wallet)
14731486
else:
1474-
var1 = self.CreateElectionRequest(wallet, startWorkTime, adnlAddr, maxFactor)
1487+
var1 = self.CreateElectionRequest(wallet, startWorkTime, adnl_addr, maxFactor)
14751488
validatorSignature = self.GetValidatorSignature(validatorKey, var1)
1476-
validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnlAddr, validatorPubkey_b64, validatorSignature, maxFactor)
1489+
validatorPubkey, resultFilePath = self.SignElectionRequestWithValidator(wallet, startWorkTime, adnl_addr, validatorPubkey_b64, validatorSignature, maxFactor)
14771490

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

14831496
# Save vars to json file
1484-
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)
1497+
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)
14851498

14861499
self.local.add_log("ElectionEntry completed. Start work time: " + str(startWorkTime))
14871500
#end define

mytonctrl/mytonctrl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,26 @@ def check_vport(local, ton):
225225
color_print(local.translate("vport_error"))
226226
#end define
227227

228+
229+
def fix_git_config(git_path: str):
230+
args = ["git", "status"]
231+
try:
232+
process = subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=git_path, timeout=3)
233+
err = process.stderr.decode("utf-8")
234+
except Exception as e:
235+
err = str(e)
236+
if err:
237+
if 'git config --global --add safe.directory' in err:
238+
args = ["git", "config", "--global", "--add", "safe.directory", git_path]
239+
subprocess.run(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=3)
240+
else:
241+
raise Exception(f'Failed to check git status: {err}')
242+
243+
228244
def check_git(input_args, default_repo, text):
229245
src_dir = "/usr/src"
230246
git_path = f"{src_dir}/{default_repo}"
247+
fix_git_config(git_path)
231248
default_author = "ton-blockchain"
232249
default_branch = "master"
233250

0 commit comments

Comments
 (0)