Compare commits
5 Commits
0e5d96475b
...
f5099a4546
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | f5099a4546 | |
Derrick Hammer | 89f2be35f7 | |
Derrick Hammer | 2cfc39d1b4 | |
Derrick Hammer | 106e1926bf | |
Derrick Hammer | 4c4f91c265 |
|
@ -81,7 +81,7 @@ export class RPC {
|
|||
const hash = this._pluginApi.util.crypto
|
||||
.createHash(stringify(tempRequest))
|
||||
.toString("hex");
|
||||
this._cache.set(hash, response);
|
||||
// this._cache.set(hash, response);
|
||||
}
|
||||
return {
|
||||
success: !response.error,
|
||||
|
|
|
@ -34,7 +34,6 @@ export function getDefaultClientConfig() {
|
|||
|
||||
export async function handleGETRequest(
|
||||
url: string,
|
||||
isBuffer: boolean = true,
|
||||
retry: number = 3
|
||||
): Promise<any> {
|
||||
if (retry < 0) {
|
||||
|
@ -45,6 +44,6 @@ export async function handleGETRequest(
|
|||
return await ret.json();
|
||||
} catch (e) {
|
||||
console.error(`failed GET request (${url}): ${e.message}`);
|
||||
return handleGETRequest(url, isBuffer, retry - 1);
|
||||
return handleGETRequest(url, retry - 1);
|
||||
}
|
||||
}
|
||||
|
|
57
src/index.ts
57
src/index.ts
|
@ -9,51 +9,10 @@ import { DEFAULT_BATCH_SIZE } from "./client/constants.js";
|
|||
import { handleGETRequest } from "./client/utils.js";
|
||||
|
||||
const EXECUTION_RPC_URL =
|
||||
"https://eth-mainnet.g.alchemy.com/v2/bu1mqVhh0t-sMdud2yaviKt5-gwb4zab";
|
||||
"https://solemn-small-frost.discover.quiknode.pro/dbbe3dc75a8b828611df3f12722de5cc88214947/";
|
||||
|
||||
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[];
|
||||
|
@ -80,6 +39,7 @@ const RPC_NO_CACHE = [
|
|||
"eth_sendRawTransaction",
|
||||
"eth_getTransactionReceipt",
|
||||
"eth_getTransactionCount",
|
||||
"eth_getProof",
|
||||
];
|
||||
|
||||
const plugin: Plugin = {
|
||||
|
@ -173,7 +133,7 @@ const plugin: Plugin = {
|
|||
api.registerMethod("execution_request", {
|
||||
cacheable: false,
|
||||
async handler(request: ExecutionRequest): Promise<object> {
|
||||
const cache = provider.rpc.getCachedRequest(request);
|
||||
/* const cache = provider.rpc.getCachedRequest(request);
|
||||
|
||||
if (cache) {
|
||||
return cache;
|
||||
|
@ -188,7 +148,9 @@ const plugin: Plugin = {
|
|||
|
||||
if (RPC_NO_CACHE.includes(request.method)) {
|
||||
provider.rpc.deleteCachedRequest(request);
|
||||
}
|
||||
}*/
|
||||
|
||||
let ret = await provider.rpc.request(request);
|
||||
// @ts-ignore
|
||||
return { ...ret, id: request.id ?? ret.id };
|
||||
},
|
||||
|
@ -197,11 +159,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