Skip to content
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d8db6e3
fix: replace edge middleware with route handler for explorer API proxy
danieljrc888 Mar 11, 2026
70d96b4
feat: enhance explorer with value formatting, search, syntax highligh…
danieljrc888 Mar 11, 2026
fe48614
revert: remove route handler, restore middleware from PR #1522
danieljrc888 Mar 11, 2026
9870d93
fix: address PR review feedback
danieljrc888 Mar 11, 2026
6fa96f3
fix: address remaining PR review comments
danieljrc888 Mar 12, 2026
38a7103
feat(simulator): allow disconnecting external wallets
danieljrc888 Mar 12, 2026
7552b8a
feat(explorer): add unified address page with contract/validator/acco…
danieljrc888 Mar 12, 2026
b501a70
feat(explorer): enhance dashboard with TPS stat and 14-day volume chart
danieljrc888 Mar 12, 2026
f9902e8
feat(explorer): replace status dropdown with tab-based transaction fi…
danieljrc888 Mar 12, 2026
3955ee8
feat(explorer): enhance global search with validators and quick links
danieljrc888 Mar 12, 2026
a786a8f
refactor(explorer): remove PATCH/DELETE tx endpoints, rename /state t…
danieljrc888 Mar 12, 2026
b3f6672
test(explorer): add comprehensive tests for explorer query layer
danieljrc888 Mar 12, 2026
c3b2a00
refactor(explorer): move transaction journey from monitoring to overv…
danieljrc888 Mar 12, 2026
b7cfaee
fix(explorer): move transaction journey to bottom of overview tab
danieljrc888 Mar 12, 2026
4f6c2e9
fix(explorer): fill 14-day volume chart with zeros up to current date
danieljrc888 Mar 12, 2026
487cdf6
perf(explorer): convert pages to server components and optimize data …
danieljrc888 Mar 12, 2026
a763a5e
fix(explorer): disable server-side caching to prevent stale data
danieljrc888 Mar 12, 2026
357267e
fix(explorer): address PR review comments
danieljrc888 Mar 12, 2026
1294237
Merge remote-tracking branch 'origin/main' into feat/explorer-phase2-…
danieljrc888 Mar 12, 2026
4c96c2c
style: format Python files with Black
danieljrc888 Mar 12, 2026
cbb111e
perf(explorer): render dashboard sections async with Suspense streaming
danieljrc888 Mar 13, 2026
3733326
fix(explorer): pass icon names as strings to avoid Server→Client seri…
danieljrc888 Mar 13, 2026
5c634c7
Merge remote-tracking branch 'origin/main' into feat/explorer-phase2-…
danieljrc888 Mar 13, 2026
b1926f7
feat(explorer): rebrand header with GenLayer logo and Switzer font
danieljrc888 Mar 13, 2026
49ca18b
feat(explorer): migrate middleware to proxy convention
danieljrc888 Mar 13, 2026
9252af7
fix(explorer): resolve SSR hydration and undefined property errors
danieljrc888 Mar 13, 2026
7cafc87
feat(explorer): add calldata decoding and InputDataPanel for transact…
danieljrc888 Mar 13, 2026
170abf1
feat(explorer): add Method column to transaction tables
danieljrc888 Mar 13, 2026
2973015
feat(explorer): add Code/Read/Write Contract tabs using genlayer-js SDK
danieljrc888 Mar 13, 2026
f27268a
fix(explorer): address PR review issues
danieljrc888 Mar 13, 2026
2ac4a9d
refactor(explorer): extract reusable hooks for SRP and DRY
danieljrc888 Mar 13, 2026
355e1f0
refactor(explorer): extract AddressDisplay component to eliminate dup…
danieljrc888 Mar 13, 2026
f752eb4
refactor(explorer): split MonitoringTab into focused sub-components
danieljrc888 Mar 13, 2026
20c25a7
refactor(explorer): extract MethodForm and StatItem as shared components
danieljrc888 Mar 13, 2026
f3896e2
Revert "feat(simulator): allow disconnecting external wallets"
danieljrc888 Mar 15, 2026
3477d76
Merge branch 'main' into feat/explorer-phase2-enhancements
cristiam86 Mar 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 192 additions & 30 deletions backend/protocol_rpc/explorer/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import base64
import math
from datetime import datetime
from datetime import datetime, timedelta, timezone
from typing import Optional

from sqlalchemy import func, or_, text
Expand Down Expand Up @@ -201,6 +201,43 @@ def get_stats(session: Session) -> dict:
.all()
)

# Finalized count from the status breakdown
finalized_count = by_status.get("FINALIZED", 0)

# Average TPS over the last 24 hours
now = datetime.now(timezone.utc)
day_ago = now - timedelta(hours=24)
tx_last_24h = (
session.query(func.count())
.select_from(Transactions)
.filter(Transactions.created_at >= day_ago)
.scalar()
or 0
)
avg_tps_24h = round(tx_last_24h / 86400, 4)

# 14-day transaction volume (grouped by date, filled to today)
today = now.date()
fourteen_days_ago = now - timedelta(days=13) # 14 days including today
volume_rows = (
session.query(
func.date(Transactions.created_at).label("date"),
func.count().label("count"),
)
.filter(Transactions.created_at >= fourteen_days_ago)
.group_by(func.date(Transactions.created_at))
.order_by(func.date(Transactions.created_at))
.all()
)
counts_by_date = {row.date: row.count for row in volume_rows}
tx_volume_14d = [
{
"date": (today - timedelta(days=13 - i)).isoformat(),
"count": counts_by_date.get(today - timedelta(days=13 - i), 0),
}
for i in range(14)
]

return {
"totalTransactions": total,
"transactionsByStatus": by_status,
Expand All @@ -211,6 +248,9 @@ def get_stats(session: Session) -> dict:
"totalValidators": total_validators,
"totalContracts": total_contracts,
"appealedTransactions": appealed,
"finalizedTransactions": finalized_count,
"avgTps24h": avg_tps_24h,
"txVolume14d": tx_volume_14d,
"recentTransactions": [
_serialize_tx(tx, include_snapshot=False) for tx in recent
],
Expand All @@ -233,8 +273,14 @@ def get_all_transactions_paginated(
) -> dict:
filters = []
if status:
# Support comma-separated status values for multi-status filtering
status_values = [s.strip() for s in status.split(",") if s.strip()]
try:
filters.append(Transactions.status == TransactionStatus(status))
parsed = [TransactionStatus(s) for s in status_values]
if len(parsed) == 1:
filters.append(Transactions.status == parsed[0])
else:
filters.append(Transactions.status.in_(parsed))
except ValueError:
# Invalid status value — return empty results
return {
Expand Down Expand Up @@ -353,34 +399,6 @@ def get_transaction_with_relations(session: Session, tx_hash: str) -> Optional[d
# ---------------------------------------------------------------------------


def delete_transaction(session: Session, tx_hash: str) -> Optional[dict]:
tx = session.query(Transactions).filter(Transactions.hash == tx_hash).first()
if not tx:
return None

child_count = (
session.query(func.count())
.select_from(Transactions)
.filter(Transactions.triggered_by_hash == tx_hash)
.scalar()
or 0
)

if child_count > 0:
session.query(Transactions).filter(
Transactions.triggered_by_hash == tx_hash
).update({"triggered_by_hash": None}, synchronize_session=False)

session.delete(tx)
session.flush()

return {
"success": True,
"message": "Transaction deleted successfully",
"childTransactionsUpdated": child_count,
}


# ---------------------------------------------------------------------------
# State
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -517,10 +535,31 @@ def get_state_with_transactions(session: Session, state_id: str) -> Optional[dic

contract_code = _extract_contract_code(session, state_id)

# Find the deploy transaction to get creator info
creator_info = None
deploy_tx = (
session.query(Transactions)
.filter(
Transactions.to_address == state_id,
Transactions.type == 1,
)
.order_by(Transactions.created_at.asc())
.first()
)
if deploy_tx:
creator_info = {
"creator_address": deploy_tx.from_address,
"deployment_tx_hash": deploy_tx.hash,
"creation_timestamp": (
deploy_tx.created_at.isoformat() if deploy_tx.created_at else None
),
}

return {
"state": _serialize_state(state),
"transactions": [_serialize_tx(tx, include_snapshot=False) for tx in txs],
"contract_code": contract_code,
"creator_info": creator_info,
}


Expand All @@ -529,6 +568,129 @@ def get_state_with_transactions(session: Session, state_id: str) -> Optional[dic
# ---------------------------------------------------------------------------


def get_address_info(session: Session, address: str) -> Optional[dict]:
"""Resolve an address to its type (CONTRACT, VALIDATOR, or ACCOUNT) and return
relevant data."""

# 1. Check if it's a contract (exists in CurrentState with a deploy tx)
state = session.query(CurrentState).filter(CurrentState.id == address).first()
if state:
deploy_tx = (
session.query(Transactions)
.filter(
Transactions.to_address == address,
Transactions.type == 1,
)
.order_by(Transactions.created_at.asc())
.first()
)
if deploy_tx:
# Return full contract detail inline
contract_detail = get_state_with_transactions(session, address)
return {
"type": "CONTRACT",
"address": address,
**(contract_detail or {}),
}

# 2. Check if it's a validator
validator = session.query(Validators).filter(Validators.address == address).first()
if validator:
return {
"type": "VALIDATOR",
"address": address,
"validator": _serialize_validator(validator),
}

# 3. Check if there are any transactions involving this address
tx_count = (
session.query(func.count())
.select_from(Transactions)
.filter(
or_(
Transactions.from_address == address,
Transactions.to_address == address,
)
)
.scalar()
or 0
)
if tx_count > 0:
# Get the account's balance from CurrentState if it exists
balance = state.balance if state else 0

addr_filter = or_(
Transactions.from_address == address,
Transactions.to_address == address,
)

recent_txs = (
session.query(Transactions)
.options(*_HEAVY_TX_COLUMNS)
.filter(addr_filter)
.order_by(Transactions.created_at.desc())
.limit(50)
.all()
)

first_tx_time = (
session.query(func.min(Transactions.created_at))
.filter(addr_filter)
.scalar()
)
last_tx_time = (
session.query(func.max(Transactions.created_at))
.filter(addr_filter)
.scalar()
)

return {
"type": "ACCOUNT",
"address": address,
"balance": balance,
"tx_count": tx_count,
"first_tx_time": first_tx_time.isoformat() if first_tx_time else None,
"last_tx_time": last_tx_time.isoformat() if last_tx_time else None,
"transactions": [
_serialize_tx(tx, include_snapshot=False) for tx in recent_txs
],
}

# Also check if it exists as a CurrentState entry without deploy tx (EOA with state)
if state:
return {
"type": "ACCOUNT",
"address": address,
"balance": state.balance,
"tx_count": 0,
"first_tx_time": None,
"last_tx_time": None,
"transactions": [],
}

return None


def get_all_validators(
session: Session,
search: Optional[str] = None,
limit: Optional[int] = None,
) -> dict:
q = session.query(Validators).order_by(Validators.id)
if search:
like = f"%{search}%"
q = q.filter(
or_(
Validators.address.ilike(like),
Validators.provider.ilike(like),
Validators.model.ilike(like),
)
)
if limit:
q = q.limit(limit)
return {"validators": [_serialize_validator(v) for v in q.all()]}


def get_all_providers(session: Session) -> dict:
providers = (
session.query(LLMProviderDBModel)
Expand Down
Loading
Loading