@lodestar/api
Version:
A Typescript REST client for the Ethereum Consensus API
114 lines • 4.01 kB
JavaScript
import { ContainerType } from "@chainsafe/ssz";
import { StringType, ssz } from "@lodestar/types";
import { ArrayOf, EmptyMetaCodec, EmptyRequestCodec, WithVersion, } from "../../utils/codecs.js";
import { ExecutionOptimisticFinalizedAndVersionCodec, } from "../../utils/metadata.js";
import { Schema } from "../../utils/schema.js";
import { WireFormat } from "../../utils/wireFormat.js";
const stringType = new StringType();
const ProtoNodeType = new ContainerType({
executionPayloadBlockHash: stringType,
executionPayloadNumber: ssz.UintNum64,
executionStatus: stringType,
slot: ssz.Slot,
blockRoot: stringType,
parentRoot: stringType,
stateRoot: stringType,
targetRoot: stringType,
timeliness: ssz.Boolean,
justifiedEpoch: ssz.Epoch,
justifiedRoot: stringType,
finalizedEpoch: ssz.Epoch,
finalizedRoot: stringType,
unrealizedJustifiedEpoch: ssz.Epoch,
unrealizedJustifiedRoot: stringType,
unrealizedFinalizedEpoch: ssz.Epoch,
unrealizedFinalizedRoot: stringType,
parent: stringType,
weight: ssz.Uint32,
bestChild: stringType,
bestDescendant: stringType,
}, { jsonCase: "eth2" });
const DebugChainHeadType = new ContainerType({
slot: ssz.Slot,
root: stringType,
executionOptimistic: ssz.Boolean,
}, { jsonCase: "eth2" });
const ForkChoiceNodeType = new ContainerType({
slot: ssz.Slot,
blockRoot: stringType,
parentRoot: stringType,
justifiedEpoch: ssz.Epoch,
finalizedEpoch: ssz.Epoch,
weight: ssz.UintNum64,
validity: new StringType(),
executionBlockHash: stringType,
}, { jsonCase: "eth2" });
const ForkChoiceResponseType = new ContainerType({
justifiedCheckpoint: ssz.phase0.Checkpoint,
finalizedCheckpoint: ssz.phase0.Checkpoint,
forkChoiceNodes: ArrayOf(ForkChoiceNodeType),
}, { jsonCase: "eth2" });
const ProtoNodeListType = ArrayOf(ProtoNodeType);
const DebugChainHeadListType = ArrayOf(DebugChainHeadType);
export function getDefinitions(_config) {
return {
getDebugChainHeadsV2: {
url: "/eth/v2/debug/beacon/heads",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: DebugChainHeadListType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
},
},
getDebugForkChoice: {
url: "/eth/v1/debug/fork_choice",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: ForkChoiceResponseType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
transform: {
toResponse: (data) => ({
...data,
}),
fromResponse: (resp) => ({
data: resp,
}),
},
},
},
getProtoArrayNodes: {
url: "/eth/v0/debug/forkchoice",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: ProtoNodeListType,
meta: EmptyMetaCodec,
onlySupport: WireFormat.json,
},
},
getStateV2: {
url: "/eth/v2/debug/beacon/states/{state_id}",
method: "GET",
req: {
writeReq: ({ stateId }) => ({ params: { state_id: stateId.toString() } }),
parseReq: ({ params }) => ({ stateId: params.state_id }),
schema: {
params: { state_id: Schema.StringRequired },
},
},
resp: {
data: WithVersion((fork) => ssz[fork].BeaconState),
meta: ExecutionOptimisticFinalizedAndVersionCodec,
},
init: {
// Default timeout is not sufficient to download state as JSON
timeoutMs: 5 * 60 * 1000,
},
},
};
}
//# sourceMappingURL=debug.js.map