Updating REST API.

- Made /beacon/state return the current 'head' state when no parameters are provided.
 - Added some of the YAML api spec stuff to the /beacon/state endpoint in the rest_api spec.
This commit is contained in:
Luke Anderson 2019-09-03 16:30:04 +10:00
parent 632c13a9ec
commit c13f27e245
No known key found for this signature in database
GPG Key ID: 44408169EC61E228
2 changed files with 60 additions and 3 deletions

View File

@ -163,8 +163,26 @@ pub fn get_state<T: BeaconChainTypes + 'static>(req: Request<Body>) -> ApiResult
.get::<Arc<BeaconChain<T>>>()
.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<T::EthSpec>) = match (key.as_ref(), value) {
("slot", value) => state_at_slot(&beacon_chain, parse_slot(&value)?)?,

View File

@ -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: