From fd2251bddeffad3c625257ea5d4efe893780d6ca Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 23 Oct 2023 12:37:34 -0400 Subject: [PATCH] refactor: upgrade lavanet --- patches/@lavanet+lava-sdk+0.21.1.patch | 46 -------------------------- patches/@lavanet+lava-sdk+0.25.6.patch | 13 ++++++++ src/index.ts | 11 +++--- 3 files changed, 18 insertions(+), 52 deletions(-) delete mode 100644 patches/@lavanet+lava-sdk+0.21.1.patch create mode 100644 patches/@lavanet+lava-sdk+0.25.6.patch diff --git a/patches/@lavanet+lava-sdk+0.21.1.patch b/patches/@lavanet+lava-sdk+0.21.1.patch deleted file mode 100644 index 5b59e13..0000000 --- a/patches/@lavanet+lava-sdk+0.21.1.patch +++ /dev/null @@ -1,46 +0,0 @@ -diff --git a/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js b/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js -index 0c3063a..b989837 100644 ---- a/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js -+++ b/node_modules/@lavanet/lava-sdk/bin/src/badge/fetchBadge.js -@@ -24,6 +24,7 @@ class BadgeManager { - this.badgeServerAddress = ""; - this.projectId = ""; - this.active = true; -+ this.transport = options?.transport; - if (!options) { - this.active = false; - return; -@@ -52,7 +53,7 @@ class BadgeManager { - request: request, - host: this.badgeServerAddress, - metadata: this.authentication ? this.authentication : {}, -- transport: browser_1.default, -+ transport: this.transport ?? browser_1.default, - onMessage: (message) => { - resolve(message); - }, -diff --git a/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js b/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js -index 53bfa7d..4ef0fd7 100644 ---- a/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js -+++ b/node_modules/@lavanet/lava-sdk/bin/src/sdk/sdk.js -@@ -47,9 +47,6 @@ class LavaSDK { - if (!badge && !privateKey) { - throw errors_1.default.errPrivKeyAndBadgeNotInitialized; - } -- else if (badge && privateKey) { -- throw errors_1.default.errPrivKeyAndBadgeBothInitialized; -- } - // Initialize local attributes - this.debugMode = options.debug ? options.debug : false; // enabling debug prints mainly used for development / debugging - this.secure = options.secure !== undefined ? options.secure : true; -@@ -148,8 +145,8 @@ class LavaSDK { - return __awaiter(this, void 0, void 0, function* () { - const start = performance.now(); - if (this.badgeManager.isActive()) { -- const { wallet, privKey } = yield (0, wallet_1.createDynamicWallet)(); -- this.privKey = privKey; -+ const wallet = yield (0, wallet_1.createWallet)(this.privKey); -+ const account = yield wallet.getConsumerAccount(); - this.walletAddress = (yield wallet.getConsumerAccount()).address; - const badgeResponse = yield this.fetchNewBadge(); - this.currentEpochBadge = badgeResponse.getBadge(); diff --git a/patches/@lavanet+lava-sdk+0.25.6.patch b/patches/@lavanet+lava-sdk+0.25.6.patch new file mode 100644 index 0000000..c1a23f0 --- /dev/null +++ b/patches/@lavanet+lava-sdk+0.25.6.patch @@ -0,0 +1,13 @@ +diff --git a/node_modules/@lavanet/lava-sdk/bin/src/badge/badgeManager.js b/node_modules/@lavanet/lava-sdk/bin/src/badge/badgeManager.js +index aae75cf..96939be 100644 +--- a/node_modules/@lavanet/lava-sdk/bin/src/badge/badgeManager.js ++++ b/node_modules/@lavanet/lava-sdk/bin/src/badge/badgeManager.js +@@ -35,7 +35,7 @@ class BadgeManager { + if (options.authentication) { + this.authentication.append("Authorization", options.authentication); + } +- this.transport = transport; ++ this.transport = transport || options.transport; + this.badgeGeneratorClient = new badges_pb_service_1.BadgeGeneratorClient(this.badgeServerAddress, this.getTransportWrapped()); + } + isActive() { diff --git a/src/index.ts b/src/index.ts index 8df05a2..34c7249 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,14 +40,14 @@ async function handleQuery(aq: ActiveQuery) { return; } - let { chain, query, rpcInterface = undefined } = aq.callerInput; + let { chain, query } = aq.callerInput; chain = chain.toUpperCase(); let lava: LavaSDK; if (!chainInstances.has(chain)) { - lava = await setupRelayChain(chain, rpcInterface); + lava = await setupRelayChain(chain); } else { lava = chainInstances.get(chain) as LavaSDK; } @@ -61,15 +61,14 @@ async function handleQuery(aq: ActiveQuery) { } } -async function setupRelayChain(chain: string, rpcInterface?: string) { +async function setupRelayChain(chain: string) { const instance = await LavaSDK.create({ - chainID: chain, - privateKey: bytesToHex(deriveChildKey(await getKey(), "lavanet")), badge: { // @ts-ignore transport: hyperTransport(rpc), }, - rpcInterface, + chainIds: chain, + privateKey: bytesToHex(deriveChildKey(await getKey(), "lavanet")), }); chainInstances.set(chain, instance);