-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_active.py
101 lines (87 loc) · 2.85 KB
/
show_active.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import sqlite3
from datetime import datetime
from tabulate import tabulate
import json
from config import DB_NAME
def setup_database():
"""Set up database tables"""
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
# Active addresses table
cursor.execute('''
CREATE TABLE IF NOT EXISTS active_addresses (
id INTEGER PRIMARY KEY AUTOINCREMENT,
address TEXT UNIQUE,
private_key TEXT,
first_found_date TIMESTAMP,
chains_with_transactions TEXT,
total_tx_count INTEGER
)
''')
conn.commit()
conn.close()
def format_datetime(dt_str):
"""Convert datetime to readable format"""
try:
dt = datetime.fromisoformat(dt_str)
return dt.strftime('%Y-%m-%d %H:%M:%S')
except:
return dt_str
def show_active_addresses():
"""Display active address information"""
conn = sqlite3.connect(DB_NAME)
cursor = conn.cursor()
# Get active addresses
cursor.execute('''
SELECT
address,
private_key,
first_found_date,
chains_with_transactions,
total_tx_count
FROM active_addresses
ORDER BY total_tx_count DESC
''')
active = cursor.fetchall()
if active:
print("\n=== Active Addresses ===")
headers = ["Address", "Private Key", "Found Date", "Active Chains", "Total Transactions"]
table_data = [
[
addr,
key,
format_datetime(found_date),
"\n".join(json.loads(chains)), # Display chains with line breaks
tx_count
]
for addr, key, found_date, chains, tx_count in active
]
print(tabulate(table_data, headers=headers, tablefmt="grid", maxcolwidths=[None, None, None, None, None]))
# Statistics
total_addresses = len(active)
total_transactions = sum(row[4] for row in active)
print(f"\nTotal Active Addresses: {total_addresses}")
print(f"Total Transactions: {total_transactions}")
# Statistics by chain
chain_stats = {}
for _, _, _, chains, _ in active:
for chain in json.loads(chains):
chain_stats[chain] = chain_stats.get(chain, 0) + 1
if chain_stats:
print("\nActive Addresses by Chain:")
for chain, count in sorted(chain_stats.items(), key=lambda x: x[1], reverse=True):
print(f"- {chain}: {count} addresses")
else:
print("\nNo active addresses found")
conn.close()
def main():
"""Main execution function"""
try:
setup_database()
show_active_addresses()
except sqlite3.Error as e:
print(f"Database error: {str(e)}")
except Exception as e:
print(f"An error occurred: {str(e)}")
if __name__ == "__main__":
main()