*Initial version

This commit is contained in:
Derrick Hammer 2023-03-19 17:17:05 -04:00
parent d777af05d1
commit df6da15952
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
5 changed files with 88 additions and 1 deletions

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) <year> <copyright holders> Copyright (c) 2023 Hammer Technologies LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

9
build.js Normal file
View File

@ -0,0 +1,9 @@
import esbuild from "esbuild";
esbuild.buildSync({
entryPoints: ["src/index.ts"],
outfile: "dist/eth.js",
format: "cjs",
bundle: true,
platform: "node",
});

3
pkg/load-eth.json Normal file
View File

@ -0,0 +1,3 @@
{
"plugins": ["eth"]
}

62
src/index.ts Normal file
View File

@ -0,0 +1,62 @@
import type { Plugin, PluginAPI } from "@lumeweb/interface-relay";
import fetch, { Request, RequestInit } from "node-fetch";
const EXECUTION_RPC_URL =
"https://g.w.lavanet.xyz:443/gateway/eth/rpc-http/f195d68175eb091ec1f71d00f8952b85";
const CONSENSUS_RPC_URL = "https://www.lightclientdata.org";
async function doFetch(url: string, request: RequestInit) {
sanitizeRequestArgs(request);
let req = new Request(url, request);
const resp = await fetch(req);
return (await resp.json()) as any;
}
function sanitizeRequestArgs(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];
}
});
}
const plugin: Plugin = {
name: "eth",
async plugin(api: PluginAPI): Promise<void> {
api.registerMethod("execution_request", {
cacheable: false,
async handler(request: RequestInit): Promise<object> {
return doFetch(EXECUTION_RPC_URL, request);
},
});
api.registerMethod("consensus_request", {
cacheable: false,
async handler(request: RequestInit): Promise<object> {
return doFetch(CONSENSUS_RPC_URL, request);
},
});
},
};
export default plugin;

13
tsconfig.json Normal file
View File

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"esModuleInterop": true,
"outDir": "dist",
"moduleResolution": "node"
},
"include": ["src"],
"exclude": [
"node_modules"
]
}