2021-03-17 18:46:45 +00:00
|
|
|
import
|
|
|
|
std/sequtils,
|
|
|
|
presto,
|
|
|
|
chronicles,
|
|
|
|
../version, ../beacon_node_common,
|
|
|
|
../spec/[datatypes, digest, presets],
|
2021-03-23 22:50:18 +00:00
|
|
|
./eth2_json_rest_serialization, ./rest_utils
|
2021-03-17 18:46:45 +00:00
|
|
|
|
|
|
|
logScope: topics = "rest_debug"
|
|
|
|
|
|
|
|
proc installDebugApiHandlers*(router: var RestRouter, node: BeaconNode) =
|
|
|
|
router.api(MethodGet,
|
|
|
|
"/api/eth/v1/debug/beacon/states/{state_id}") do (
|
|
|
|
state_id: StateIdent) -> RestApiResponse:
|
2021-03-23 22:50:18 +00:00
|
|
|
let bslot =
|
|
|
|
block:
|
|
|
|
if state_id.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http400, InvalidStateIdValueError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$state_id.error())
|
|
|
|
let bres = node.getBlockSlot(state_id.get())
|
|
|
|
if bres.isErr():
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http404, StateNotFoundError,
|
2021-03-23 22:50:18 +00:00
|
|
|
$bres.error())
|
|
|
|
bres.get()
|
|
|
|
node.withStateForBlockSlot(bslot):
|
|
|
|
return RestApiResponse.jsonResponse(state())
|
2021-04-08 10:49:28 +00:00
|
|
|
return RestApiResponse.jsonError(Http500, InternalServerError)
|
2021-03-17 18:46:45 +00:00
|
|
|
|
|
|
|
router.api(MethodGet,
|
|
|
|
"/api/eth/v1/debug/beacon/heads") do () -> RestApiResponse:
|
|
|
|
return RestApiResponse.jsonResponse(
|
2021-03-23 22:50:18 +00:00
|
|
|
node.chainDag.heads.mapIt((root: it.root, slot: it.slot))
|
2021-03-17 18:46:45 +00:00
|
|
|
)
|
2021-04-13 10:19:31 +00:00
|
|
|
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/debug/beacon/states/{state_id}",
|
|
|
|
"/api/eth/v1/debug/beacon/states/{state_id}"
|
|
|
|
)
|
|
|
|
router.redirect(
|
|
|
|
MethodGet,
|
|
|
|
"/eth/v1/debug/beacon/heads",
|
|
|
|
"/api/eth/v1/debug/beacon/heads"
|
|
|
|
)
|