Skip to content

Commit 22993b8

Browse files
committed
check if tha exists before enabling
1 parent 305117f commit 22993b8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

mytoncore/mytoncore.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
Dict, int2ip
3434
)
3535

36+
from mytoninstaller.utils import enable_tha
37+
3638

3739
class MyTonCore():
3840
def __init__(self, local):
@@ -3079,8 +3081,7 @@ def check_enable_mode(self, name):
30793081
raise Exception(f'Cannot enable validator mode while liteserver mode is enabled. '
30803082
f'Use `disable_mode liteserver` first.')
30813083
if name == 'liquid-staking':
3082-
from mytoninstaller.settings import enable_ton_http_api
3083-
enable_ton_http_api(self.local)
3084+
enable_tha(self.local)
30843085

30853086
def enable_mode(self, name):
30863087
if name not in MODES:

mytoninstaller/utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import json
33
import time
44
import subprocess
5+
6+
import requests
57
from nacl.signing import SigningKey
68

79

@@ -50,3 +52,25 @@ def get_ed25519_pubkey(privkey):
5052
pubkey = privkey_obj.verify_key.encode()
5153
return pubkey
5254
#end define
55+
56+
57+
def tha_exists():
58+
try:
59+
resp = requests.get('http://127.0.0.1:8801/healthcheck', timeout=3)
60+
except:
61+
return False
62+
if resp.status_code == 200 and resp.text == '"OK"':
63+
return True
64+
return False
65+
66+
67+
def enable_tha(local):
68+
try:
69+
if not tha_exists():
70+
local.add_log("Enabling TON HTTP API", "debug")
71+
from mytoninstaller.settings import enable_ton_http_api
72+
enable_ton_http_api(local)
73+
local.add_log("Enabled TON HTTP API", "debug")
74+
except Exception as e:
75+
local.add_log(f"Error in enable_tha: {e}", "warning")
76+
pass

0 commit comments

Comments
 (0)