Skip to content

Commit

Permalink
added trycatch for network error
Browse files Browse the repository at this point in the history
  • Loading branch information
farhanW3 committed Jul 7, 2023
1 parent 7ba56ea commit b99910d
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions worker/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,44 @@ export const setupWalletsForWorker = async (
server.log.info(`Primary key found in wallets table`);
}
for (const chain of getSupportedChains()) {
const { slug } = chain;
let lastUsedNonce = 0;
server.log.info(`Setting up wallet for chain ${slug}`);
const sdk = await getSDK(slug);
const walletAddress =
(await sdk.getSigner()?.getAddress())?.toLowerCase() ?? "";
if (walletAddress.length === 0) {
server.log.warn(`Wallet address not found for chain ${slug}.`);
continue;
}
const walletNonce = await getWalletNonce(
walletAddress,
sdk.getProvider(),
);
const walletDataInDB = await getWalletDetailsWithoutTrx(
walletAddress,
BigNumber.from(chain.chainId).toString(),
knex,
);
try {
const { slug } = chain;
let lastUsedNonce = 0;
server.log.info(`Setting up wallet for chain ${slug}`);
const sdk = await getSDK(slug);
const walletAddress =
(await sdk.getSigner()?.getAddress())?.toLowerCase() ?? "";
if (walletAddress.length === 0) {
server.log.warn(`Wallet address not found for chain ${slug}.`);
continue;
}
const walletNonce = await getWalletNonce(
walletAddress,
sdk.getProvider(),
);
const walletDataInDB = await getWalletDetailsWithoutTrx(
walletAddress,
BigNumber.from(chain.chainId).toString(),
knex,
);

if (walletDataInDB) {
lastUsedNonce = walletDataInDB.lastUsedNonce;
}
if (walletDataInDB) {
lastUsedNonce = walletDataInDB.lastUsedNonce;
}

const walletData = {
walletAddress: walletAddress.toLowerCase(),
chainId: getChainBySlug(slug).chainId.toString(),
blockchainNonce: BigNumber.from(walletNonce ?? 0).toNumber(),
lastSyncedTimestamp: new Date(),
lastUsedNonce,
walletType: slug,
};
await insertIntoWallets(walletData, knex!);
const walletData = {
walletAddress: walletAddress.toLowerCase(),
chainId: getChainBySlug(slug).chainId.toString(),
blockchainNonce: BigNumber.from(walletNonce ?? 0).toNumber(),
lastSyncedTimestamp: new Date(),
lastUsedNonce,
walletType: slug,
};
await insertIntoWallets(walletData, knex!);
} catch (error) {
server.log.error((error as any).message);
continue;
}
}
await knex.destroy();
} catch (error) {
Expand Down

0 comments on commit b99910d

Please sign in to comment.