Skip to content

Commit

Permalink
add python db
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Sep 6, 2024
1 parent 126f4e4 commit 87836c2
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions python-db-explorations/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
Empty file.
6 changes: 6 additions & 0 deletions python-db-explorations/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def main():
print("Hello from python-db-explorations!")


if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions python-db-explorations/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "python-db-explorations"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[project.scripts]
query-proofs = "query_proofs.py"
61 changes: 61 additions & 0 deletions python-db-explorations/query_proofs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import sqlite3
from enum import Enum

class ProofType(Enum):
SPAN = 1
AGG = 2

class ProofStatus(Enum):
UNREQ = 1
REQ = 2
COMPLETE = 3
FAILED = 4

def query_span_proofs(db_path, start_block):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()

# query = """
# SELECT * FROM proof_requests
# WHERE type = ? AND status = ? AND start_block = ?
# """
# cursor.execute(query, (ProofType.SPAN.value, ProofStatus.COMPLETE.value, start_block))

query = """
SELECT * FROM proof_requests
WHERE type = 'SPAN' AND start_block = ?
"""
cursor.execute(query, (start_block,))

results = cursor.fetchall()
if results:
first_result = results[0]
# print(f"ID: {first_result[0]}")
# print(f"Type: {first_result[1]}")
# print(f"Start Block: {first_result[2]}")
# print(f"End Block: {first_result[3]}")
# print(f"Status: {first_result[4]}")
# print(f"Request Added Time: {first_result[5]}")
# print(f"Prover Request ID: {first_result[6]}")
# print(f"Proof Request Time: {first_result[7]}")
# print(f"L1 Block Number: {first_result[8]}")
# print(f"L1 Block Hash: {first_result[9]}")
# print(f"Proof: {first_result[10]}")

# print("Results:", results)
conn.close()

return results

if __name__ == "__main__":
print("Querying span proofs")
db_path = "../db/proofs.db"

start_block = 16843141 # Replace with the desired start block
for i in range(1000):

proofs = query_span_proofs(db_path, start_block)

for proof in proofs:
print(f"Proof ID: {proof[0]}, Start Block: {proof[2]}, End Block: {proof[3]}, Status: {proof[4]}, Prover Request ID: {proof[6]}")
start_block += 1
7 changes: 7 additions & 0 deletions python-db-explorations/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87836c2

Please sign in to comment.