Skip to content

Commit b4a7fea

Browse files
committed
cloud_functions: clean up alarmMissingVAAs.
1 parent c1499ae commit b4a7fea

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cloud_functions/src/alarmMissingVaas.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChainId, Network } from '@wormhole-foundation/sdk-base';
1+
import { ChainId, Network, toChainId } from '@wormhole-foundation/sdk-base';
22
import {
33
MISS_THRESHOLD_IN_MINS,
44
explorerBlock,
@@ -92,7 +92,7 @@ export async function alarmMissingVaas(req: any, res: any) {
9292
thePast.setMinutes(now.getMinutes() - MISS_THRESHOLD_IN_MINS);
9393
const missThreshold = thePast.toISOString();
9494
for (const chain of Object.keys(messages)) {
95-
const chainId = chain as unknown as ChainId;
95+
const chainId: ChainId = toChainId(Number(chain));
9696
const msgs = messages[chainId];
9797
if (msgs && msgs.messages) {
9898
for (let i = 0; i < msgs.messages.length; i++) {
@@ -154,7 +154,7 @@ export async function alarmMissingVaas(req: any, res: any) {
154154
return;
155155
}
156156

157-
// This function gets all the enqueued VAAs from he governorStatus collection.
157+
// This function gets all the enqueued VAAs from the governorStatus collection.
158158
async function getGovernedVaas(): Promise<GovernedVAAMap> {
159159
const vaas: GovernedVAAMap = new Map<string, GovernedVAA>();
160160
// Walk all the guardians and retrieve the enqueued VAAs
@@ -292,8 +292,8 @@ function convert(msg: ObservedMessage): FirestoreVAA {
292292
function formatMessage(msg: ObservedMessage): string {
293293
const cName: string = chainIdToName(msg.chain);
294294
const vaaKeyUrl: string = `https://wormholescan.io/#/tx/${msg.chain}/${msg.emitter}/${msg.seq}`;
295-
const txHashUrl: string = explorerTx(network, msg.chain as ChainId, msg.txHash);
296-
const blockUrl: string = explorerBlock(network, msg.chain as ChainId, msg.block.toString());
295+
const txHashUrl: string = explorerTx(network, toChainId(msg.chain), msg.txHash);
296+
const blockUrl: string = explorerBlock(network, toChainId(msg.chain), msg.block.toString());
297297
const formattedMsg = `*Chain:* ${cName}(${msg.chain})\n*TxHash:* <${txHashUrl}|${msg.txHash}>\n*VAA Key:* <${vaaKeyUrl}|${msg.chain}/${msg.emitter}/${msg.seq}> \n*Block:* <${blockUrl}|${msg.block}> \n*Timestamp:* ${msg.timestamp}`;
298298
return formattedMsg;
299299
}
@@ -310,7 +310,7 @@ async function getLastBlockTimeFromFirestore(): Promise<LatestTimeByChain> {
310310
snapshot.docs
311311
.sort((a, b) => Number(a.id) - Number(b.id))
312312
.forEach((doc) => {
313-
values[Number(doc.id) as ChainId] = { latestTime: doc.data().lastBlockKey.split('/')[1] };
313+
values[toChainId(Number(doc.id))] = { latestTime: doc.data().lastBlockKey.split('/')[1] };
314314
});
315315
} catch (e) {
316316
console.error(e);
@@ -338,7 +338,7 @@ async function alarmOldBlockTimes(latestTimes: LatestTimeByChain): Promise<void>
338338
// Walk all chains and check the latest block time.
339339
const now = new Date();
340340
for (const chain of Object.keys(latestTimes)) {
341-
const chainId: ChainId = chain as any as ChainId;
341+
const chainId: ChainId = toChainId(Number(chain));
342342
const latestTime: string | undefined = latestTimes[chainId]?.latestTime;
343343
if (!latestTime) {
344344
continue;

0 commit comments

Comments
 (0)