forked from jacklevin74/xenminer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_superblocks.py
65 lines (52 loc) · 2.13 KB
/
make_superblocks.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import re
import sqlite3
import threading
import time
from collections import defaultdict
def run_db_operations():
max_retries = 3
for i in range(max_retries):
try:
# Connect to SQLite database
conn = sqlite3.connect('blocks.db', timeout=10) # 10 seconds timeout
cursor = conn.cursor()
# Drop super_blocks table if it exists
cursor.execute("DROP TABLE IF EXISTS super_blocks")
# Create the table
cursor.execute("""
CREATE TABLE super_blocks (
account TEXT PRIMARY KEY,
super_block_count INTEGER
);
""")
# Fetch all hash_to_verify and account records from blocks table
cursor.execute("SELECT hash_to_verify, account FROM blocks;")
rows = cursor.fetchall()
# Prepare a dictionary to keep counts
super_block_counts = defaultdict(int)
for row in rows:
hash_to_verify, account_to_update = row
last_element = hash_to_verify.split("$")[-1]
hash_uppercase_only = ''.join(filter(str.isupper, last_element))
capital_count = len(hash_uppercase_only)
#capital_count = sum(1 for char in re.sub('[0-9]', '', hash_to_verify) if char.isupper())
if capital_count >= 50:
super_block_counts[account_to_update] += 1
# Insert all rows in one go
cursor.executemany("""
INSERT INTO super_blocks (account, super_block_count)
VALUES (?, ?);
""", super_block_counts.items())
# Commit the changes to the database
conn.commit()
# Close the connection
conn.close()
# If successful, break the retry loop
break
except sqlite3.OperationalError:
print(f"Database is locked, retrying {i+1}/{max_retries}")
time.sleep(1) # wait for 1 second before retrying
# Schedule the next run
threading.Timer(300, run_db_operations).start()
# Kick off the first run
run_db_operations()