From df5128e5347936940ac2208acb7f12c18a9b1ee4 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Tue, 18 Jun 2024 18:52:05 +0300 Subject: [PATCH] fix store last blocks --- src/handlers/runAllAdapters.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/handlers/runAllAdapters.ts b/src/handlers/runAllAdapters.ts index 2f51bd91..e8949a34 100644 --- a/src/handlers/runAllAdapters.ts +++ b/src/handlers/runAllAdapters.ts @@ -29,7 +29,19 @@ export default wrapScheduledLambda(async (_event) => { ) subquery; `; try { - await store("lastRecordedBlocks.json", JSON.stringify(lastRecordedBlocks[0].result)); + const bridgeConfig = await sql`SELECT * FROM bridges.config`; + + const bridgeConfigById = bridgeConfig.reduce((acc: any, config: any) => { + acc[config.id] = config; + return acc; + }, {}); + + const lastBlocksByName = Object.keys(lastRecordedBlocks).reduce((acc: any, bridgeId: any) => { + acc[`${bridgeConfigById[bridgeId].bridge_name}-${bridgeConfigById[bridgeId].chain}`] = + lastRecordedBlocks[bridgeId]; + return acc; + }, {}); + await store("lastRecordedBlocks.json", JSON.stringify(lastBlocksByName)); console.log("Stored last recorded blocks"); } catch (e) { console.error("Failed to store last recorded blocks");