rest: fix ssz preference string (#3357)
This commit is contained in:
parent
e0fb5d95a6
commit
6f10e651ff
|
@ -115,7 +115,7 @@ proc publishBlock*(body: altair.SignedBeaconBlock): RestPlainResponse {.
|
|||
|
||||
proc getBlockPlain*(block_id: BlockIdent): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v1/beacon/blocks/{block_id}",
|
||||
accept: "application/octet-stream,application-json;q=0.9",
|
||||
accept: preferSSZ,
|
||||
meth: MethodGet.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlock
|
||||
|
||||
|
@ -138,7 +138,9 @@ proc raiseUnknownStatusError(resp: RestPlainResponse)
|
|||
raise newException(RestError, msg)
|
||||
|
||||
proc getBlock*(client: RestClientRef, block_id: BlockIdent,
|
||||
restAccept = ""): Future[ForkedSignedBeaconBlock] {.async.} =
|
||||
restAccept = preferSSZ): Future[ForkedSignedBeaconBlock] {.async.} =
|
||||
# TODO restAccept should be "" by default, but for some reason that doesn't
|
||||
# work
|
||||
let resp =
|
||||
if len(restAccept) > 0:
|
||||
await client.getBlockPlain(block_id, restAcceptType = restAccept)
|
||||
|
@ -176,16 +178,18 @@ proc getBlock*(client: RestClientRef, block_id: BlockIdent,
|
|||
|
||||
proc getBlockV2Plain*(block_id: BlockIdent): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v2/beacon/blocks/{block_id}",
|
||||
accept: "application/octet-stream,application-json;q=0.9",
|
||||
accept: preferSSZ,
|
||||
meth: MethodGet.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/getBlockV2
|
||||
|
||||
proc getBlockV2*(client: RestClientRef, block_id: BlockIdent,
|
||||
cfg: RuntimeConfig,
|
||||
restAccept = ""): Future[Option[ForkedSignedBeaconBlock]] {.
|
||||
restAccept = preferSSZ): Future[Option[ForkedSignedBeaconBlock]] {.
|
||||
async.} =
|
||||
# Return the asked-for block, or None in case 404 is returned from the server.
|
||||
# Raises on other errors
|
||||
# TODO restAccept should be "" by default, but for some reason that doesn't
|
||||
# work
|
||||
let resp =
|
||||
if len(restAccept) > 0:
|
||||
await client.getBlockV2Plain(block_id, restAcceptType = restAccept)
|
||||
|
|
|
@ -15,12 +15,14 @@ export chronos, client, rest_types, eth2_rest_serialization
|
|||
|
||||
proc getStatePlain*(state_id: StateIdent): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v1/debug/beacon/states/{state_id}",
|
||||
accept: "application/octet-stream,application-json;q=0.9",
|
||||
accept: preferSSZ,
|
||||
meth: MethodGet.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Beacon/getState
|
||||
|
||||
proc getState*(client: RestClientRef, state_id: StateIdent,
|
||||
restAccept = ""): Future[phase0.BeaconState] {.async.} =
|
||||
restAccept = preferSSZ): Future[phase0.BeaconState] {.async.} =
|
||||
# TODO restAccept should be "" by default, but for some reason that doesn't
|
||||
# work
|
||||
let resp =
|
||||
if len(restAccept) > 0:
|
||||
await client.getStatePlain(state_id, restAcceptType = restAccept)
|
||||
|
@ -73,15 +75,17 @@ proc getDebugChainHeads*(): RestResponse[GetDebugChainHeadsResponse] {.
|
|||
|
||||
proc getStateV2Plain*(state_id: StateIdent): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v2/debug/beacon/states/{state_id}",
|
||||
accept: "application/octet-stream,application-json;q=0.9",
|
||||
accept: preferSSZ,
|
||||
meth: MethodGet.}
|
||||
## https://ethereum.github.io/beacon-APIs/#/Debug/getStateV2
|
||||
|
||||
proc getStateV2*(client: RestClientRef, state_id: StateIdent,
|
||||
cfg: RuntimeConfig,
|
||||
restAccept = ""): Future[ref ForkedHashedBeaconState] {.async.} =
|
||||
restAccept = preferSSZ): Future[ref ForkedHashedBeaconState] {.async.} =
|
||||
# nil is returned if the state is not found due to a 404 - `ref` is needed
|
||||
# to manage stack usage
|
||||
# TODO restAccept should be "" by default, but for some reason that doesn't
|
||||
# work
|
||||
let resp =
|
||||
if len(restAccept) > 0:
|
||||
await client.getStateV2Plain(state_id, restAcceptType = restAccept)
|
||||
|
|
|
@ -26,6 +26,9 @@ const
|
|||
# https://github.com/ethereum/eth2.0-APIs/blob/master/apis/beacon/states/validators.yaml#L17
|
||||
MaximumValidatorIds* = 16384
|
||||
|
||||
const
|
||||
preferSSZ* = "application/octet-stream,application/json;q=0.9"
|
||||
|
||||
type
|
||||
EventTopic* {.pure.} = enum
|
||||
Head, Block, Attestation, VoluntaryExit, FinalizedCheckpoint, ChainReorg,
|
||||
|
|
Loading…
Reference in New Issue