fix: Use new db connection for getNewestBlock to work with web server

This commit is contained in:
Nathan Woodburn 2025-02-06 12:35:35 +11:00
parent 78cb528e45
commit 71f162218f
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

12
main.py
View File

@ -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