solana-bankingstage-dashboard/transaction_database.py

51 lines
1.3 KiB
Python
Raw Normal View History

2023-10-18 00:20:38 -07:00
import postgres_connection
2023-10-17 05:30:55 -07:00
2023-10-13 11:14:06 -07:00
2023-10-18 00:20:38 -07:00
def run_query():
con = postgres_connection.create_connection()
2023-10-17 05:36:20 -07:00
cursor = con.cursor()
cursor.execute(
2023-10-13 11:14:06 -07:00
"""
2023-10-13 13:12:49 -07:00
SELECT * FROM (
SELECT
2023-10-17 05:30:55 -07:00
ROW_NUMBER() OVER () AS pos,
signature,
message,
2023-10-17 06:33:30 -07:00
-- e.g. "Account in use-225558172:2;Account in use-225558173:1;"
2023-10-17 05:30:55 -07:00
errors,
is_executed,
is_confirmed,
first_notification_slot,
cu_requested,
prioritization_fees,
2023-10-17 06:31:17 -07:00
utc_timestamp,
2023-10-17 06:33:30 -07:00
-- e.g. "OCT 17 12:29:17.5127"
2023-10-18 03:54:23 -07:00
to_char(utc_timestamp, 'MON DD HH24:MI:SS.MS') as timestamp_formatted,
2023-10-17 05:30:55 -07:00
accounts_used
2023-10-13 13:12:49 -07:00
FROM banking_stage_results.transaction_infos
2023-10-17 05:44:17 -07:00
WHERE true
2023-10-17 06:31:17 -07:00
ORDER BY utc_timestamp DESC
2023-10-17 09:53:11 -07:00
LIMIT 50
2023-10-13 13:12:49 -07:00
) AS data
2023-10-13 11:14:06 -07:00
""")
2023-10-13 12:40:18 -07:00
2023-10-17 05:36:20 -07:00
keys = [k[0] for k in cursor.description]
maprows = [dict(zip(keys, row)) for row in cursor]
2023-10-17 05:30:55 -07:00
2023-10-18 00:20:38 -07:00
# print some samples
for row in maprows[:3]:
print(row)
print("...")
2023-10-17 05:30:55 -07:00
2023-10-17 06:31:17 -07:00
for row in maprows:
row['errors_array'] = row['errors'].rstrip().split(';')
2023-10-13 12:40:18 -07:00
return maprows
2023-10-18 00:20:38 -07:00
def main():
run_query()
2023-10-13 11:14:06 -07:00
if __name__=="__main__":
2023-10-18 00:20:38 -07:00
main()
2023-10-13 11:14:06 -07:00