fix: Use new db connection for getNewestBlock to work with web server
This commit is contained in:
parent
78cb528e45
commit
71f162218f
12
main.py
12
main.py
@ -141,12 +141,20 @@ def setupDB():
|
|||||||
def getNewestBlock() -> int:
|
def getNewestBlock() -> int:
|
||||||
"""Returns the height of the newest block in the database"""
|
"""Returns the height of the newest block in the database"""
|
||||||
|
|
||||||
with dbGet.cursor() as cursor:
|
dbNB = mysql.connector.connect(
|
||||||
|
host=DB_HOST,
|
||||||
|
user=DB_USER,
|
||||||
|
password=DB_PASSWORD,
|
||||||
|
database=DB_NAME,
|
||||||
|
charset='utf8mb4',
|
||||||
|
collation='utf8mb4_unicode_ci',
|
||||||
|
)
|
||||||
|
with dbNB.cursor() as cursor:
|
||||||
cursor.execute("SELECT height FROM blocks ORDER BY height DESC LIMIT 1")
|
cursor.execute("SELECT height FROM blocks ORDER BY height DESC LIMIT 1")
|
||||||
newestBlock = cursor.fetchone()
|
newestBlock = cursor.fetchone()
|
||||||
if newestBlock:
|
if newestBlock:
|
||||||
return int(newestBlock[0])
|
return int(newestBlock[0])
|
||||||
|
dbNB.close()
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user