UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

23 lines 1.14 kB
import { LightClientServerErrorCode, RespStatus, ResponseError, } from "@lodestar/reqresp"; import { computeEpochAtSlot } from "@lodestar/state-transition"; import { assertLightClientServer } from "../../../node/utils/lightclient.js"; import { ReqRespMethod, responseSszTypeByMethod } from "../types.js"; export async function* onLightClientBootstrap(requestBody, chain) { assertLightClientServer(chain.lightClientServer); try { const bootstrap = await chain.lightClientServer.getBootstrap(requestBody); const boundary = chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(bootstrap.header.beacon.slot)); const type = responseSszTypeByMethod[ReqRespMethod.LightClientBootstrap](boundary.fork, 0); yield { data: type.serialize(bootstrap), boundary, }; } catch (e) { if (e.type?.code === LightClientServerErrorCode.RESOURCE_UNAVAILABLE) { throw new ResponseError(RespStatus.RESOURCE_UNAVAILABLE, e.message); } throw new ResponseError(RespStatus.SERVER_ERROR, e.message); } } //# sourceMappingURL=lightClientBootstrap.js.map