*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 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`
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue