refactor: switch to lavanet
This commit is contained in:
parent
957ff166a3
commit
6a58fdaf8d
26
src/index.ts
26
src/index.ts
|
@ -18,6 +18,10 @@ import {
|
||||||
import * as capella from "@lodestar/types/capella";
|
import * as capella from "@lodestar/types/capella";
|
||||||
import defer from "p-defer";
|
import defer from "p-defer";
|
||||||
import { Level } from "level";
|
import { Level } from "level";
|
||||||
|
import {
|
||||||
|
type LavaNetClient,
|
||||||
|
createClient as createLavanetClient,
|
||||||
|
} from "@lumeweb/kernel-lavanet-client";
|
||||||
|
|
||||||
onmessage = handleMessage;
|
onmessage = handleMessage;
|
||||||
|
|
||||||
|
@ -28,6 +32,7 @@ const moduleReadyDefer = defer();
|
||||||
const clientInitDefer = defer();
|
const clientInitDefer = defer();
|
||||||
|
|
||||||
let client: EthClient;
|
let client: EthClient;
|
||||||
|
let lavanet: LavaNetClient;
|
||||||
let rpc: RpcNetwork;
|
let rpc: RpcNetwork;
|
||||||
const db = new Level<number | string, Uint8Array>("consensus", {
|
const db = new Level<number | string, Uint8Array>("consensus", {
|
||||||
valueEncoding: "buffer",
|
valueEncoding: "buffer",
|
||||||
|
@ -112,29 +117,12 @@ async function consensusHandler(method: string, data: any) {
|
||||||
|
|
||||||
async function executionHandler(data: Map<string, string | any>) {
|
async function executionHandler(data: Map<string, string | any>) {
|
||||||
await rpc.ready;
|
await rpc.ready;
|
||||||
while (true) {
|
return await lavanet.query("ETH1", data);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setup() {
|
async function setup() {
|
||||||
rpc = createRpcClient();
|
rpc = createRpcClient();
|
||||||
|
lavanet = createLavanetClient();
|
||||||
await db.open();
|
await db.open();
|
||||||
await rpc.ready;
|
await rpc.ready;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue