diff --git a/src/index.ts b/src/index.ts index 86dd5c9..56fd16e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,47 +13,6 @@ const EXECUTION_RPC_URL = const CONSENSUS_RPC_URL = "https://www.lightclientdata.org"; -const RPC_CACHE = new NodeCache({ stdTTL: 60 * 60 * 12 }); - -async function doFetch(url: string, request: RequestInit) { - sanitizeRequestArgs(url, request); - - let req = new Request(url, { - ...request, - headers: { - "Content-Type": "application/json", - }, - }); - - const resp = await fetch(req); - - return (await resp.json()) as any; -} - -function sanitizeRequestArgs(url: string, request: RequestInit) { - if (!request || typeof request !== "object") { - throw Error("invalid request"); - } - - [ - "agent", - "hostname", - "referrer", - "referrerPolicy", - "compress", - "port", - "protocol", - "hostname", - "insecureHTTPParser", - "highWaterMark", - "size", - ].forEach((element) => { - if (element in request) { - delete request[element]; - } - }); -} - interface ExecutionRequest { method: string; params: any[]; @@ -197,11 +156,8 @@ const plugin: Plugin = { api.registerMethod("consensus_optimistic_update", { cacheable: false, async handler(): Promise { - return await doFetch( - `${CONSENSUS_RPC_URL}/eth/v1/beacon/light_client/optimistic_update`, - { - method: "GET", - } + return await handleGETRequest( + `${CONSENSUS_RPC_URL}/eth/v1/beacon/light_client/optimistic_update` ); }, });