Skip to content

Commit

Permalink
add total supply to block info
Browse files Browse the repository at this point in the history
  • Loading branch information
HarukaMa committed Sep 14, 2024
1 parent 86fb637 commit 4b6d0e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions db/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,20 @@ async def get_block_target_sum_by_height(self, height: int) -> int:
if (res := await cur.fetchone()) is None:
return 0
return res["target_sum"]
except Exception as e:
await self.message_callback(ExplorerMessage(ExplorerMessage.Type.DatabaseError, e))
raise

async def get_total_supply_at_height(self, height: int) -> int:
async with self.pool.connection() as conn:
async with conn.cursor() as cur:
try:
await cur.execute(
"SELECT total_supply FROM block WHERE height = %s", (height,)
)
if (res := await cur.fetchone()) is None:
return 0
return res["total_supply"]
except Exception as e:
await self.message_callback(ExplorerMessage(ExplorerMessage.Type.DatabaseError, e))
raise
2 changes: 2 additions & 0 deletions webapi/block_routes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math
from decimal import Decimal
from typing import Any

from starlette.requests import Request
Expand Down Expand Up @@ -92,6 +93,7 @@ async def block_route(request: Request):
"validators": validators,
"all_validators": all_validators,
"solutions": css,
"total_supply": Decimal(await db.get_total_supply_at_height(height)),
}
result["resolved_addresses"] = \
await UIAddress.resolve_recursive_detached(
Expand Down

0 comments on commit 4b6d0e9

Please sign in to comment.