refactor: upgrade lavanet

This commit is contained in:
Derrick Hammer 2023-10-23 12:37:34 -04:00
parent 90a90e9c80
commit fd2251bdde
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 18 additions and 52 deletions

View File

@ -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();

View File

@ -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() {

View File

@ -40,14 +40,14 @@ async function handleQuery(aq: ActiveQuery) {
return; return;
} }
let { chain, query, rpcInterface = undefined } = aq.callerInput; let { chain, query } = aq.callerInput;
chain = chain.toUpperCase(); chain = chain.toUpperCase();
let lava: LavaSDK; let lava: LavaSDK;
if (!chainInstances.has(chain)) { if (!chainInstances.has(chain)) {
lava = await setupRelayChain(chain, rpcInterface); lava = await setupRelayChain(chain);
} else { } else {
lava = chainInstances.get(chain) as LavaSDK; 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({ const instance = await LavaSDK.create({
chainID: chain,
privateKey: bytesToHex(deriveChildKey(await getKey(), "lavanet")),
badge: { badge: {
// @ts-ignore // @ts-ignore
transport: hyperTransport(rpc), transport: hyperTransport(rpc),
}, },
rpcInterface, chainIds: chain,
privateKey: bytesToHex(deriveChildKey(await getKey(), "lavanet")),
}); });
chainInstances.set(chain, instance); chainInstances.set(chain, instance);