@lodestar/api
Version:
A Typescript REST client for the Ethereum Consensus API
120 lines • 4.76 kB
JavaScript
import { ContainerType } from "@chainsafe/ssz";
import { ssz, stringType } from "@lodestar/types";
import { ArrayOf, EmptyMetaCodec, EmptyRequestCodec, EmptyResponseCodec, JsonOnlyResponseCodec, } from "../../utils/codecs.js";
import { Schema } from "../../utils/index.js";
import { WireFormat } from "../../utils/wireFormat.js";
export const NetworkIdentityType = new ContainerType({
/** Cryptographic hash of a peer’s public key. [Read more](https://docs.libp2p.io/concepts/peer-id/) */
peerId: stringType,
/** Ethereum node record. [Read more](https://eips.ethereum.org/EIPS/eip-778) */
enr: stringType,
p2pAddresses: ArrayOf(stringType),
discoveryAddresses: ArrayOf(stringType),
/** Based on Ethereum Consensus [Metadata object](https://github.com/ethereum/consensus-specs/blob/v1.1.10/specs/phase0/p2p-interface.md#metadata) */
metadata: ssz.altair.Metadata,
}, { jsonCase: "eth2" });
export const PeerCountType = new ContainerType({
disconnected: ssz.UintNum64,
connecting: ssz.UintNum64,
connected: ssz.UintNum64,
disconnecting: ssz.UintNum64,
}, { jsonCase: "eth2" });
export const SyncingStatusType = new ContainerType({
/** Head slot node is trying to reach */
headSlot: ssz.Slot,
/** How many slots node needs to process to reach head. 0 if synced. */
syncDistance: ssz.Slot,
/** Set to true if the node is syncing, false if the node is synced. */
isSyncing: ssz.Boolean,
/** Set to true if the node is optimistically tracking head. */
isOptimistic: ssz.Boolean,
/** Set to true if the connected el client is offline */
elOffline: ssz.Boolean,
}, { jsonCase: "eth2" });
export var NodeHealth;
(function (NodeHealth) {
NodeHealth[NodeHealth["READY"] = 200] = "READY";
NodeHealth[NodeHealth["SYNCING"] = 206] = "SYNCING";
NodeHealth[NodeHealth["NOT_INITIALIZED_OR_ISSUES"] = 503] = "NOT_INITIALIZED_OR_ISSUES";
})(NodeHealth || (NodeHealth = {}));
export function getDefinitions(_config) {
return {
getNetworkIdentity: {
url: "/eth/v1/node/identity",
method: "GET",
req: EmptyRequestCodec,
resp: {
onlySupport: WireFormat.json,
data: NetworkIdentityType,
meta: EmptyMetaCodec,
},
},
getPeers: {
url: "/eth/v1/node/peers",
method: "GET",
req: {
writeReq: ({ state, direction }) => ({ query: { state, direction } }),
parseReq: ({ query }) => ({ state: query.state, direction: query.direction }),
schema: { query: { state: Schema.StringArray, direction: Schema.StringArray } },
},
resp: {
...JsonOnlyResponseCodec,
meta: {
toJson: (d) => d,
fromJson: (d) => ({ count: d.count }),
toHeadersObject: () => ({}),
fromHeaders: () => ({}),
},
transform: {
toResponse: (data, meta) => ({ data, meta }),
fromResponse: (resp) => resp,
},
},
},
getPeer: {
url: "/eth/v1/node/peers/{peer_id}",
method: "GET",
req: {
writeReq: ({ peerId }) => ({ params: { peer_id: peerId } }),
parseReq: ({ params }) => ({ peerId: params.peer_id }),
schema: { params: { peer_id: Schema.StringRequired } },
},
resp: JsonOnlyResponseCodec,
},
getPeerCount: {
url: "/eth/v1/node/peer_count",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: PeerCountType,
meta: EmptyMetaCodec,
},
},
getNodeVersion: {
url: "/eth/v1/node/version",
method: "GET",
req: EmptyRequestCodec,
resp: JsonOnlyResponseCodec,
},
getSyncingStatus: {
url: "/eth/v1/node/syncing",
method: "GET",
req: EmptyRequestCodec,
resp: {
data: SyncingStatusType,
meta: EmptyMetaCodec,
},
},
getHealth: {
url: "/eth/v1/node/health",
method: "GET",
req: {
writeReq: ({ syncingStatus }) => ({ query: { syncing_status: syncingStatus } }),
parseReq: ({ query }) => ({ syncingStatus: query.syncing_status }),
schema: { query: { syncing_status: Schema.Uint } },
},
resp: EmptyResponseCodec,
},
};
}
//# sourceMappingURL=node.js.map