refactor: switch to lavanet

This commit is contained in:
Derrick Hammer 2023-11-17 01:10:33 -05:00
parent 957ff166a3
commit 6a58fdaf8d
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 19 deletions

View File

@ -18,6 +18,10 @@ import {
import * as capella from "@lodestar/types/capella";
import defer from "p-defer";
import { Level } from "level";
import {
type LavaNetClient,
createClient as createLavanetClient,
} from "@lumeweb/kernel-lavanet-client";
onmessage = handleMessage;
@ -28,6 +32,7 @@ const moduleReadyDefer = defer();
const clientInitDefer = defer();
let client: EthClient;
let lavanet: LavaNetClient;
let rpc: RpcNetwork;
const db = new Level<number | string, Uint8Array>("consensus", {
valueEncoding: "buffer",
@ -112,29 +117,12 @@ async function consensusHandler(method: string, data: any) {
async function executionHandler(data: Map<string, string | any>) {
await rpc.ready;
while (true) {
let query = await rpc.simpleQuery({
query: {
module: "eth",
method: "execution_request",
data,
},
options: {
relayTimeout: 30,
queryTimeout: 30,
},
});
let ret = await query.result;
if (ret.data) {
return ret.data;
}
}
return await lavanet.query("ETH1", data);
}
async function setup() {
rpc = createRpcClient();
lavanet = createLavanetClient();
await db.open();
await rpc.ready;