Skip to content

Commit 30b8f27

Browse files
committed
add /api/v1/vaas endpoint
1 parent 5e5ef7a commit 30b8f27

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { quoteHandler } from "./quote";
22
export { statusHandler } from "./status";
33
export { capabilitiesHandler } from "./capabilities";
4+
export { vaasHandler } from "./vaas.ts";

src/api/vaas.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {enabledChains} from "../chains.ts";
2+
import {mockWormhole} from "../mockGuardian.ts";
3+
import {type Request, type Response} from "express";
4+
import type {Hex} from "viem";
5+
6+
export const vaasHandler = async (req: Request, res: Response) => {
7+
let txHash = req.query["txHash"];
8+
9+
if (!txHash) {
10+
res.status(400).send("txHash is required.");
11+
return;
12+
}
13+
14+
// Loop through enabledChains and try mockWormhole for each one, returning the first signed VAA
15+
// that mockWormhole returns.
16+
for (const chainConfig of Object.values(enabledChains)) {
17+
try {
18+
const result = await mockWormhole(
19+
chainConfig.rpc,
20+
txHash as Hex,
21+
chainConfig.coreContractAddress as Hex,
22+
""
23+
);
24+
25+
if (result !== undefined) {
26+
res.status(200).json({data: [{vaa: result}]});
27+
return;
28+
}
29+
} catch (error) {
30+
// Continue to next chain if this one fails
31+
console.log(`Failed to get VAA from chain ${chainConfig.name}:`, error);
32+
}
33+
}
34+
35+
res.status(200).json({
36+
data: []
37+
});
38+
};

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from "express";
22
import cors from "cors";
33
import { overrideGuardianSet } from "./overrideGuardianSet";
4-
import { quoteHandler, statusHandler, capabilitiesHandler } from "./api";
4+
import {quoteHandler, statusHandler, capabilitiesHandler, vaasHandler} from "./api";
55
import { enabledChains } from "./chains";
66
import { isHex } from "viem";
77

@@ -25,6 +25,9 @@ app.use(express.json());
2525
app.post("/v0/quote", quoteHandler);
2626
app.post("/v0/status/tx", statusHandler);
2727
app.get("/v0/capabilities", capabilitiesHandler);
28+
// This endpoint is part of the Wormholescan API and isn't part of the executor API, but is useful for exposing signed
29+
// VAAs for clients who wish to not use the Executor for relaying and prefer to relay messages themselves.
30+
app.get("/api/v1/vaas", vaasHandler);
2831

2932
const server = app.listen(3000, () => {
3033
console.log(`Server is running at http://localhost:3000`);

0 commit comments

Comments
 (0)