diff --git a/beacon_node/rest_api/src/beacon.rs b/beacon_node/rest_api/src/beacon.rs index 66d0b2673..36e7f6c57 100644 --- a/beacon_node/rest_api/src/beacon.rs +++ b/beacon_node/rest_api/src/beacon.rs @@ -163,8 +163,26 @@ pub fn get_state(req: Request) -> ApiResult .get::>>() .ok_or_else(|| ApiError::ServerError("Beacon chain extension missing".to_string()))?; - let query_params = ["root", "slot"]; - let (key, value) = UrlQuery::from_request(&req)?.first_of(&query_params)?; + let (key, value) = match UrlQuery::from_request(&req) { + Ok(query) => { + // We have *some* parameters, check them. + let query_params = ["root", "slot"]; + match query.first_of(&query_params) { + Ok((k, v)) => (k, v), + Err(e) => { + // Wrong parameters provided, or another error, return the error. + return Err(e); + } + } + }, + Err(ApiError::InvalidQueryParams(_)) => { + // No parameters provided at all, use current slot. + (String::from("slot"), beacon_chain.head().beacon_state.slot.to_string()) + } + Err(e) => { + return Err(e); + } + }; let (root, state): (Hash256, BeaconState) = match (key.as_ref(), value) { ("slot", value) => state_at_slot(&beacon_chain, parse_slot(&value)?)?, diff --git a/docs/api_spec.yaml b/docs/api_spec.yaml index 42b394e69..892ce7a68 100644 --- a/docs/api_spec.yaml +++ b/docs/api_spec.yaml @@ -344,7 +344,6 @@ paths: 500: $ref: '#/components/responses/InternalError' - #TODO Fill out block_root endpoint /beacon/block_root: get: tags: @@ -977,6 +976,46 @@ paths: #TODO fill out /beacon/state /beacon/state: + get: + tags: + - Phase0 + summary: "Get the full beacon state, at a particular slot or block root." + description: "Requests the beacon node to provide the full beacon state object, and the state root, given a particular slot number or block root. If no parameters are provided, the latest slot of the beacon node (the 'head' slot) is used." + parameters: + - name: root + description: "The block root at which the state should be provided." + in: query + required: false + schema: + type: string + format: bytes + pattern: "^0x[a-fA-F0-9]{64}$" + - name: slot + description: "The slot number at which the state should be provided." + in: query + required: false + schema: + type: integer + format: uint64 + responses: + 200: + description: Success response + content: + application/json: + schema: + type: object + properties: + root: + type: string + format: bytes + pattern: "^0x[a-fA-F0-9]{64}$" + beacon_state: + #TODO: Need to add BeaconState Schema + $ref: '#/components/schemas/BeaconState' + 400: + $ref: '#/components/responses/InvalidRequest' + 500: + $ref: '#/components/responses/InternalError' #TODO fill out /beacon/state_root /beacon/state_root: