*doFetch not needed, use handleGETRequest
This commit is contained in:
parent
0e5d96475b
commit
4c4f91c265
48
src/index.ts
48
src/index.ts
|
@ -13,47 +13,6 @@ const EXECUTION_RPC_URL =
|
||||||
|
|
||||||
const CONSENSUS_RPC_URL = "https://www.lightclientdata.org";
|
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 {
|
interface ExecutionRequest {
|
||||||
method: string;
|
method: string;
|
||||||
params: any[];
|
params: any[];
|
||||||
|
@ -197,11 +156,8 @@ const plugin: Plugin = {
|
||||||
api.registerMethod("consensus_optimistic_update", {
|
api.registerMethod("consensus_optimistic_update", {
|
||||||
cacheable: false,
|
cacheable: false,
|
||||||
async handler(): Promise<object> {
|
async handler(): Promise<object> {
|
||||||
return await doFetch(
|
return await handleGETRequest(
|
||||||
`${CONSENSUS_RPC_URL}/eth/v1/beacon/light_client/optimistic_update`,
|
`${CONSENSUS_RPC_URL}/eth/v1/beacon/light_client/optimistic_update`
|
||||||
{
|
|
||||||
method: "GET",
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue