Skip to content

Commit 9218364

Browse files
committed
add webapi ans and solution redirection
1 parent 023aab8 commit 9218364

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

webapi/address_routes.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aleo_types import LiteralPlaintext, Literal, Address, PlaintextValue, Value, Int, StructPlaintext, u64
77
from aleo_types.cached import cached_get_key_id
88
from db import Database
9+
from util import arc0137
910
from webapi.utils import CJSONResponse, public_cache_seconds
1011
from webui.classes import UIAddress
1112

@@ -15,7 +16,7 @@ async def address_route(request: Request) -> CJSONResponse:
1516
db: Database = request.app.state.db
1617
address = request.path_params["address"]
1718
if not address:
18-
return CJSONResponse({"error": "Address not found"}, status_code=404)
19+
return CJSONResponse({"error": "Address not provided"}, status_code=400)
1920
try:
2021
Address.loads(address)
2122
except ValueError:
@@ -210,4 +211,16 @@ async def address_route(request: Request) -> CJSONResponse:
210211
"latest_height": await db.get_latest_height(),
211212
}
212213
result["resolved_addresses"] = await UIAddress.resolve_recursive_detached(result, db, {})
213-
return CJSONResponse(result)
214+
return CJSONResponse(result)
215+
216+
@public_cache_seconds(60)
217+
async def ans_route(request: Request) -> CJSONResponse:
218+
db: Database = request.app.state.db
219+
name = request.path_params["name"]
220+
if not name:
221+
return CJSONResponse({"error": "Name not provided"}, status_code=400)
222+
223+
address = await arc0137.get_address_from_domain(db, name)
224+
if address is None:
225+
return CJSONResponse({"error": "Name not found"}, status_code=404)
226+
return CJSONResponse(address)

webapi/chain_routes.py

+10
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,13 @@ async def search_route(request: Request):
547547
else:
548548
return CJSONResponse({"error": "No results found"}, status_code=404)
549549

550+
@public_cache_seconds(5)
551+
async def solution_route(request: Request):
552+
db: Database = request.app.state.db
553+
solution_id = request.path_params.get("id")
554+
if solution_id is None:
555+
return CJSONResponse({"error": "Missing solution id"}, status_code=400)
556+
height = await db.get_solution_block_height(solution_id)
557+
if height is None:
558+
return CJSONResponse({"error": "Solution not found"}, status_code=404)
559+
return CJSONResponse(height)

webapi/webapi.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
from middleware.auth import AuthMiddleware
1818
from middleware.server_timing import ServerTimingMiddleware
1919
from util.set_proc_title import set_proc_title
20-
from .address_routes import address_route
20+
from .address_routes import address_route, ans_route
2121
from .chain_routes import blocks_route, get_summary, recent_blocks_route, index_update_route, block_route, search_route, \
2222
transaction_route, \
23-
validators_route, transition_route
23+
validators_route, transition_route, solution_route
2424
from .error_routes import bad_request, not_found, internal_error
2525
from .program_routes import programs_route, program_route
2626
from .utils import public_cache_seconds, out_of_sync_check, CJSONResponse
@@ -67,12 +67,14 @@ async def summary_route(request: Request):
6767
Route("/validators", validators_route),
6868
Route("/transaction/{id}", transaction_route),
6969
Route("/transition/{id}", transition_route),
70+
Route("/solution/{id}", solution_route),
7071
Route("/search", search_route),
7172

7273
Route("/programs", programs_route),
7374
Route("/program/{id}", program_route),
7475

7576
Route("/address/{address}", address_route),
77+
Route("/ans/{name}", ans_route),
7678
]
7779

7880
exc_handlers = {

0 commit comments

Comments
 (0)