From 34ee6efed5bd88227bd62fb8dfb6d07700020aaf Mon Sep 17 00:00:00 2001 From: vrtnd Date: Thu, 13 Jun 2024 20:21:46 +0300 Subject: [PATCH 1/4] recorded blocks api --- serverless.yml | 8 ++++++++ src/handlers/getLastBlocks.ts | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/handlers/getLastBlocks.ts diff --git a/serverless.yml b/serverless.yml index 6ade5f09..2125d9c5 100644 --- a/serverless.yml +++ b/serverless.yml @@ -118,6 +118,14 @@ functions: - http: path: largetransactions/{chain} method: get + lastBlocks: + handler: src/handlers/getLastBlocks.default + timeout: 30 + memorySize: 2000 + events: + - http: + path: lastblocks + method: get runAdapter: handler: src/handlers/runAdapter.default timeout: 900 diff --git a/src/handlers/getLastBlocks.ts b/src/handlers/getLastBlocks.ts new file mode 100644 index 00000000..528caac9 --- /dev/null +++ b/src/handlers/getLastBlocks.ts @@ -0,0 +1,32 @@ +import wrap, { wrapScheduledLambda } from "../utils/wrap"; +import bridgeNetworks from "../data/bridgeNetworkData"; +import { runAdapterToCurrentBlock } from "../utils/adapter"; +import { sql } from "../utils/db"; +import { successResponse } from "../utils/lambda-response"; + +const handler = async (event: any) => { + const lastRecordedBlocks = ( + await sql`SELECT jsonb_object_agg(bridge_id::text, subresult) as result + FROM ( + SELECT bridge_id, jsonb_build_object('startBlock', MIN(tx_block), 'endBlock', MAX(tx_block)) as subresult + FROM bridges.transactions + GROUP BY bridge_id + ) subquery; + ` + )[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; + }, {}); + return successResponse(lastBlocksByName); +}; + +export default wrap(handler); From ab199b3f7646ca5e5b164457a2235e2f3c62d243 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Thu, 13 Jun 2024 20:25:49 +0300 Subject: [PATCH 2/4] recorded blocks api --- src/handlers/getLastBlocks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/handlers/getLastBlocks.ts b/src/handlers/getLastBlocks.ts index 528caac9..02490c2a 100644 --- a/src/handlers/getLastBlocks.ts +++ b/src/handlers/getLastBlocks.ts @@ -4,7 +4,7 @@ import { runAdapterToCurrentBlock } from "../utils/adapter"; import { sql } from "../utils/db"; import { successResponse } from "../utils/lambda-response"; -const handler = async (event: any) => { +const handler = async () => { const lastRecordedBlocks = ( await sql`SELECT jsonb_object_agg(bridge_id::text, subresult) as result FROM ( From 22952c4a2b6009241f6d24c4248d3ee7941304f6 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Thu, 13 Jun 2024 21:17:55 +0300 Subject: [PATCH 3/4] fix yml --- serverless.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/serverless.yml b/serverless.yml index 2125d9c5..0be15e79 100644 --- a/serverless.yml +++ b/serverless.yml @@ -124,8 +124,8 @@ functions: memorySize: 2000 events: - http: - path: lastblocks - method: get + path: lastblocks + method: get runAdapter: handler: src/handlers/runAdapter.default timeout: 900 From 5e95fa2db72ef31ee87505226f3b28bee02a4ff7 Mon Sep 17 00:00:00 2001 From: vrtnd Date: Thu, 13 Jun 2024 22:06:18 +0300 Subject: [PATCH 4/4] fix timeout --- serverless.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/serverless.yml b/serverless.yml index 0be15e79..6dc5d174 100644 --- a/serverless.yml +++ b/serverless.yml @@ -120,7 +120,7 @@ functions: method: get lastBlocks: handler: src/handlers/getLastBlocks.default - timeout: 30 + timeout: 120 memorySize: 2000 events: - http: