forked from TurtleNetwork/TN-ETH-Gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
38 lines (31 loc) · 1011 Bytes
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sqlite3 as sqlite
import json
import threading
import uvicorn
import setupDB
from tnChecker import TNChecker
from ethChecker import ETHChecker
with open('config.json') as json_file:
config = json.load(json_file)
def main():
#check db
try:
dbCon = sqlite.connect('gateway.db')
result = dbCon.cursor().execute('SELECT chain, height FROM heights WHERE chain = "TN" or chain = "ETH"').fetchall()
#dbcon.close()
if len(result) == 0:
setupDB.initialisedb(config)
except:
setupDB.createdb()
setupDB.initialisedb(config)
setupDB.createVerify()
#load and start threads
tn = TNChecker(config)
eth = ETHChecker(config)
ethThread = threading.Thread(target=eth.run)
tnThread = threading.Thread(target=tn.run)
ethThread.start()
tnThread.start()
#start app
uvicorn.run("gateway:app", host="0.0.0.0", port=config["main"]["port"], log_level="info")
main()