-
Notifications
You must be signed in to change notification settings - Fork 61
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
4 changed files
with
73 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { PrismaTransaction } from "../../schema/prisma"; | ||
import { getPrismaWithPostgresTx } from "../client"; | ||
|
||
interface DeleteAllWalletNoncesParams { | ||
pgtx?: PrismaTransaction; | ||
} | ||
|
||
/** | ||
* Delete the cached value of all backend wallet nonces. | ||
* This is useful to require all backend wallets to resync their | ||
* nonce on the next txn. | ||
*/ | ||
export const deleteAllWalletNonces = async ({ | ||
pgtx, | ||
}: DeleteAllWalletNoncesParams) => { | ||
const prisma = getPrismaWithPostgresTx(pgtx); | ||
await prisma.walletNonce.deleteMany({}); | ||
}; |
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,46 @@ | ||
import { Static, Type } from "@sinclair/typebox"; | ||
import { FastifyInstance } from "fastify"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { deleteAllWalletNonces } from "../../../db/wallets/deleteAllWalletNonces"; | ||
import { standardResponseSchema } from "../../schemas/sharedApiSchemas"; | ||
|
||
const responseSchema = Type.Object({ | ||
result: Type.Object({ | ||
status: Type.String(), | ||
}), | ||
}); | ||
|
||
responseSchema.example = { | ||
result: { | ||
status: "success", | ||
}, | ||
}; | ||
|
||
export const resetBackendWallet = async (fastify: FastifyInstance) => { | ||
fastify.route<{ | ||
Reply: Static<typeof responseSchema>; | ||
}>({ | ||
method: "POST", | ||
url: "/backend-wallet/reset-nonces", | ||
schema: { | ||
summary: "Reset all nonces", | ||
description: | ||
"Reset nonces for all backend wallets. This is for debugging purposes and does not impact held tokens.", | ||
tags: ["Backend Wallet"], | ||
operationId: "resetNonces", | ||
response: { | ||
...standardResponseSchema, | ||
[StatusCodes.OK]: responseSchema, | ||
}, | ||
}, | ||
handler: async (req, reply) => { | ||
await deleteAllWalletNonces({}); | ||
|
||
reply.status(StatusCodes.OK).send({ | ||
result: { | ||
status: "success", | ||
}, | ||
}); | ||
}, | ||
}); | ||
}; |
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