*doFetch not needed, use handleGETRequest

This commit is contained in:
Derrick Hammer 2023-03-29 11:31:07 -04:00
parent 0e5d96475b
commit 4c4f91c265
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 2 additions and 46 deletions

View File

@ -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<object> {
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`
);
},
});