-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
index.ts
76 lines (68 loc) 路 2.46 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import {ChainForkConfig} from "@lodestar/config";
import {phase0, ssz} from "@lodestar/types";
import {ApiClientResponse} from "../../../interfaces.js";
import {HttpStatusCode} from "../../../utils/client/httpStatusCode.js";
import {RoutesData, ReturnTypes, reqEmpty, ContainerData} from "../../../utils/index.js";
import * as block from "./block.js";
import * as pool from "./pool.js";
import * as state from "./state.js";
import * as rewards from "./rewards.js";
// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes
// NOTE: We choose to split the block, pool, and state namespaces so the files are not too big.
// However, for a consumer all these methods are within the same service "beacon"
export * as block from "./block.js";
export * as pool from "./pool.js";
export * as state from "./state.js";
export * as rewards from "./rewards.js";
export {BroadcastValidation} from "./block.js";
export type {BlockId, BlockHeaderResponse} from "./block.js";
export type {AttestationFilters} from "./pool.js";
export type {BlockRewards, SyncCommitteeRewards} from "./rewards.js";
// TODO: Review if re-exporting all these types is necessary
export type {
StateId,
ValidatorId,
ValidatorStatus,
ValidatorFilters,
CommitteesFilters,
FinalityCheckpoints,
ValidatorResponse,
ValidatorBalance,
EpochCommitteeResponse,
EpochSyncCommitteeResponse,
} from "./state.js";
export type Api = block.Api &
pool.Api &
state.Api &
rewards.Api & {
getGenesis(): Promise<ApiClientResponse<{[HttpStatusCode.OK]: {data: phase0.Genesis}}>>;
};
export const routesData: RoutesData<Api> = {
getGenesis: {url: "/eth/v1/beacon/genesis", method: "GET"},
...block.routesData,
...pool.routesData,
...state.routesData,
...rewards.routesData,
};
export type ReqTypes = {
[K in keyof ReturnType<typeof getReqSerializers>]: ReturnType<ReturnType<typeof getReqSerializers>[K]["writeReq"]>;
};
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export function getReqSerializers(config: ChainForkConfig) {
return {
getGenesis: reqEmpty,
...block.getReqSerializers(config),
...pool.getReqSerializers(),
...state.getReqSerializers(),
...rewards.getReqSerializers(),
};
}
export function getReturnTypes(): ReturnTypes<Api> {
return {
getGenesis: ContainerData(ssz.phase0.Genesis),
...block.getReturnTypes(),
...pool.getReturnTypes(),
...state.getReturnTypes(),
...rewards.getReturnTypes(),
};
}