Skip to content

Commit c1a24e3

Browse files
authored
chore: add update relayer endpoint (#310)
1 parent ea6de2e commit c1a24e3

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

src/server/routes/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ import { revokeRelayer } from "./relayer/revoke";
9595
// System
9696
import { healthCheck } from "./health";
9797
import { home } from "./home";
98+
import { updateRelayer } from "./relayer/update";
9899

99100
export const withRoutes = async (fastify: FastifyInstance) => {
100101
// Backend Wallets
@@ -145,6 +146,7 @@ export const withRoutes = async (fastify: FastifyInstance) => {
145146
await fastify.register(getAllRelayers);
146147
await fastify.register(createRelayer);
147148
await fastify.register(revokeRelayer);
149+
await fastify.register(updateRelayer);
148150
await fastify.register(relayTransaction);
149151

150152
// Generic

src/server/routes/relayer/create.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { prisma } from "../../../db/client";
55
import { getChainIdFromChain } from "../../utils/chain";
66

77
const BodySchema = Type.Object({
8+
name: Type.Optional(Type.String()),
89
chain: Type.String(),
910
backendWalletAddress: Type.String({
1011
description:
@@ -39,6 +40,7 @@ export async function createRelayer(fastify: FastifyInstance) {
3940
},
4041
handler: async (req, res) => {
4142
const {
43+
name,
4244
chain,
4345
backendWalletAddress,
4446
allowedContracts,
@@ -48,6 +50,7 @@ export async function createRelayer(fastify: FastifyInstance) {
4850
const chainId = (await getChainIdFromChain(chain)).toString();
4951
const relayer = await prisma.relayers.create({
5052
data: {
53+
name,
5154
chainId,
5255
backendWalletAddress,
5356
allowedContracts: allowedContracts

src/server/routes/relayer/update.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { Static, Type } from "@sinclair/typebox";
2+
import { FastifyInstance } from "fastify";
3+
import { StatusCodes } from "http-status-codes";
4+
import { prisma } from "../../../db/client";
5+
import { getChainIdFromChain } from "../../utils/chain";
6+
7+
const BodySchema = Type.Object({
8+
id: Type.String(),
9+
name: Type.Optional(Type.String()),
10+
chain: Type.Optional(Type.String()),
11+
backendWalletAddress: Type.Optional(Type.String()),
12+
allowedContracts: Type.Optional(Type.Array(Type.String())),
13+
allowedForwarders: Type.Optional(Type.Array(Type.String())),
14+
});
15+
16+
const ReplySchema = Type.Object({
17+
result: Type.Object({
18+
success: Type.Boolean(),
19+
}),
20+
});
21+
22+
export async function updateRelayer(fastify: FastifyInstance) {
23+
fastify.route<{
24+
Body: Static<typeof BodySchema>;
25+
Reply: Static<typeof ReplySchema>;
26+
}>({
27+
method: "POST",
28+
url: "/relayer/update",
29+
schema: {
30+
summary: "Update a relayer",
31+
description: "Update a relayer",
32+
tags: ["Relayer"],
33+
operationId: "update",
34+
body: BodySchema,
35+
response: {
36+
[StatusCodes.OK]: ReplySchema,
37+
},
38+
},
39+
handler: async (req, res) => {
40+
const {
41+
id,
42+
name,
43+
chain,
44+
backendWalletAddress,
45+
allowedContracts,
46+
allowedForwarders,
47+
} = req.body;
48+
49+
const chainId = chain
50+
? (await getChainIdFromChain(chain)).toString()
51+
: undefined;
52+
await prisma.relayers.update({
53+
where: {
54+
id,
55+
},
56+
data: {
57+
name,
58+
chainId,
59+
backendWalletAddress,
60+
allowedContracts: allowedContracts
61+
? JSON.stringify(
62+
allowedContracts.map((address) => address.toLowerCase()),
63+
)
64+
: null,
65+
allowedForwarders: allowedForwarders
66+
? JSON.stringify(
67+
allowedForwarders.map((address) => address.toLowerCase()),
68+
)
69+
: null,
70+
},
71+
});
72+
73+
res.status(200).send({
74+
result: {
75+
success: true,
76+
},
77+
});
78+
},
79+
});
80+
}

0 commit comments

Comments
 (0)