Skip to content

Commit 6bf0e71

Browse files
authored
Add /api/v1/vaas endpoint (#11)
* add /api/v1/vaas endpoint * make it pretty * use isHex
1 parent 5e5ef7a commit 6bf0e71

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { enabledChains } from "../chains.ts";
2+
import { mockWormhole } from "../mockGuardian.ts";
3+
import { type Request, type Response } from "express";
4+
import { type Hex, isHex } 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+
if (!isHex(txHash)) {
15+
res.status(400).send("txHash must be a valid hex string.");
16+
return;
17+
}
18+
19+
// Loop through enabledChains and try mockWormhole for each one, returning the first signed VAA
20+
// that mockWormhole returns.
21+
for (const chainConfig of Object.values(enabledChains)) {
22+
try {
23+
if (!isHex(chainConfig.coreContractAddress)) {
24+
continue;
25+
}
26+
const result = await mockWormhole(
27+
chainConfig.rpc,
28+
txHash,
29+
chainConfig.coreContractAddress,
30+
"",
31+
);
32+
33+
if (result !== undefined) {
34+
res.status(200).json({ data: [{ vaa: result }] });
35+
return;
36+
}
37+
} catch (error) {
38+
// Continue to next chain if this one fails
39+
console.log(`Failed to get VAA from chain ${chainConfig.name}:`, error);
40+
}
41+
}
42+
43+
res.status(200).json({
44+
data: [],
45+
});
46+
};

src/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import express from "express";
22
import cors from "cors";
33
import { overrideGuardianSet } from "./overrideGuardianSet";
4-
import { quoteHandler, statusHandler, capabilitiesHandler } from "./api";
4+
import {
5+
quoteHandler,
6+
statusHandler,
7+
capabilitiesHandler,
8+
vaasHandler,
9+
} from "./api";
510
import { enabledChains } from "./chains";
611
import { isHex } from "viem";
712

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

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

0 commit comments

Comments
 (0)