From b9276da9db8dedced012b995f354994015b70a28 Mon Sep 17 00:00:00 2001 From: Luke Anderson Date: Thu, 29 Aug 2019 13:36:51 +1000 Subject: [PATCH] Flesh spec. & update display bugs. - Add correct string formatting when incorrect parameters provided. - Fill /beacon/block and /beacon/block_root endpoints - Add 500 error responses to endpoints as appropriate --- beacon_node/rest_api/src/beacon.rs | 8 ++-- docs/api_spec.yaml | 69 ++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/beacon_node/rest_api/src/beacon.rs b/beacon_node/rest_api/src/beacon.rs index 5dcbc728a..66d0b2673 100644 --- a/beacon_node/rest_api/src/beacon.rs +++ b/beacon_node/rest_api/src/beacon.rs @@ -81,7 +81,7 @@ pub fn get_block(req: Request) -> ApiResult let target = parse_slot(&value)?; block_root_at_slot(&beacon_chain, target).ok_or_else(|| { - ApiError::NotFound(format!("Unable to find BeaconBlock for slot {}", target)) + ApiError::NotFound(format!("Unable to find BeaconBlock for slot {:?}", target)) })? } ("root", value) => parse_root(&value)?, @@ -93,7 +93,7 @@ pub fn get_block(req: Request) -> ApiResult .get::>(&block_root)? .ok_or_else(|| { ApiError::NotFound(format!( - "Unable to find BeaconBlock for root {}", + "Unable to find BeaconBlock for root {:?}", block_root )) })?; @@ -121,7 +121,7 @@ pub fn get_block_root(req: Request) -> ApiR let target = parse_slot(&slot_string)?; let root = block_root_at_slot(&beacon_chain, target).ok_or_else(|| { - ApiError::NotFound(format!("Unable to find BeaconBlock for slot {}", target)) + ApiError::NotFound(format!("Unable to find BeaconBlock for slot {:?}", target)) })?; let json: String = serde_json::to_string(&root) @@ -174,7 +174,7 @@ pub fn get_state(req: Request) -> ApiResult let state = beacon_chain .store .get(root)? - .ok_or_else(|| ApiError::NotFound(format!("No state for root: {}", root)))?; + .ok_or_else(|| ApiError::NotFound(format!("No state for root: {:?}", root)))?; (*root, state) } diff --git a/docs/api_spec.yaml b/docs/api_spec.yaml index 5053c5dd2..b43d99b8a 100644 --- a/docs/api_spec.yaml +++ b/docs/api_spec.yaml @@ -248,9 +248,6 @@ paths: format: uint64 description: "UNIX time in milliseconds that the block was first discovered, either from a network peer or the validator client." - - - /beacon/head: get: tags: @@ -307,13 +304,75 @@ paths: format: bytes pattern: "^0x[a-fA-F0-9]{64}$" description: "The block root of the second most recent justified block." + 500: + $ref: '#/components/responses/InternalError' - #TODO Fill out block endpoint /beacon/block: + get: + tags: + - Phase0 + summary: 'Retrieve blocks by root or slot.' + description: "Request that the beacon node return beacon chain blocks that match the provided criteria (a block root or beacon chain slot). Only one of the parameters can be be provided at a time." + parameters: + - name: root + description: "Filter by block root." + in: query + required: false + schema: + type: string + format: bytes + pattern: "^0x[a-fA-F0-9]{64}$" + - name: slot + description: "Filter blocks by slot number. Only one block which has been finalized, or is believed to be the canonical block for that slot, is returned." + in: query + required: false + schema: + type: integer + format: uint64 + responses: + 200: + description: Success response. + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/BeaconBlock' + 400: + $ref: '#/components/responses/InvalidRequest' + 500: + $ref: '#/components/responses/InternalError' #TODO Fill out block_root endpoint /beacon/block_root: + get: + tags: + - Phase0 + summary: "Retrieve the canonical block root, given a particular slot." + description: "Request that the beacon node return the root of the canonical beacon chain block, which matches the provided slot number." + parameters: + - name: slot + description: "Filter blocks by slot number. Only one block which has been finalized, or is believed to be the canonical block for that slot, is returned." + in: query + required: true + schema: + type: integer + format: uint64 + responses: + 200: + description: Success response. + content: + application/json: + schema: + type: string + format: byte + pattern: "^0x[a-fA-F0-9]{64}$" + description: "The 0x prefixed block root." + 400: + $ref: '#/components/responses/InvalidRequest' + 500: + $ref: '#/components/responses/InternalError' /beacon/blocks: get: @@ -373,6 +432,8 @@ paths: application/json: schema: $ref: '#/components/schemas/Fork' + 500: + $ref: '#/components/responses/InternalError' /beacon/attestations: