-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { wrapScheduledLambda } from "../utils/wrap"; | ||
import bridgeNetworks from "../data/bridgeNetworkData"; | ||
import { runAdapterToCurrentBlock } from "../utils/adapter"; | ||
import { sql } from "../utils/db"; | ||
import { BridgeNetwork } from "../data/types"; | ||
|
||
const handler = async (event: { bridgeName: string }) => { | ||
try { | ||
const { bridgeName } = event; | ||
|
||
if (!bridgeName) { | ||
throw new Error("Bridge name is required"); | ||
} | ||
|
||
const bridge = bridgeNetworks.find((b: BridgeNetwork) => b.bridgeDbName === bridgeName); | ||
|
||
if (!bridge) { | ||
throw new Error(`Bridge ${bridgeName} not found`); | ||
} | ||
|
||
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; | ||
`; | ||
|
||
console.log(`Running adapter for ${bridgeName}`); | ||
await runAdapterToCurrentBlock(bridge, true, "ignore", lastRecordedBlocks); | ||
console.log(`Adapter for ${bridgeName} ran successfully`); | ||
} catch (e) { | ||
console.error(`Adapter ${event.bridgeName} failed: ${JSON.stringify(e)}`); | ||
throw e; | ||
} finally { | ||
await sql.end(); | ||
} | ||
}; | ||
|
||
export default wrapScheduledLambda(handler); |