File tree Expand file tree Collapse file tree 5 files changed +75
-3
lines changed Expand file tree Collapse file tree 5 files changed +75
-3
lines changed Original file line number Diff line number Diff line change
1
+ import { PrismaTransaction } from "../../schema/prisma" ;
2
+ import { getPrismaWithPostgresTx } from "../client" ;
3
+
4
+ interface DeleteAllWalletNoncesParams {
5
+ pgtx ?: PrismaTransaction ;
6
+ }
7
+
8
+ /**
9
+ * Delete the cached value of all backend wallet nonces.
10
+ * This is useful to require all backend wallets to resync their
11
+ * nonce on the next txn.
12
+ */
13
+ export const deleteAllWalletNonces = async ( {
14
+ pgtx,
15
+ } : DeleteAllWalletNoncesParams ) => {
16
+ const prisma = getPrismaWithPostgresTx ( pgtx ) ;
17
+ await prisma . walletNonce . deleteMany ( { } ) ;
18
+ } ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import fastify, { FastifyInstance } from "fastify";
3
3
import * as fs from "fs" ;
4
4
import path from "path" ;
5
5
import { URL } from "url" ;
6
+ import { deleteAllWalletNonces } from "../db/wallets/deleteAllWalletNonces" ;
6
7
import { env } from "../utils/env" ;
7
8
import { logger } from "../utils/logger" ;
8
9
import { withAuth } from "./middleware/auth" ;
@@ -25,8 +26,12 @@ interface HttpsObject {
25
26
}
26
27
27
28
const main = async ( ) => {
28
- let httpsObject : HttpsObject | undefined = undefined ;
29
+ // Reset any server state that is safe to reset.
30
+ // This allows the server to start in a predictable state.
31
+ await deleteAllWalletNonces ( { } ) ;
29
32
33
+ // Enables the server to run on https://localhost:PORT, if ENABLE_HTTPS is provided.
34
+ let httpsObject : HttpsObject | undefined = undefined ;
30
35
if ( env . ENABLE_HTTPS ) {
31
36
httpsObject = {
32
37
https : {
@@ -37,6 +42,7 @@ const main = async () => {
37
42
} ;
38
43
}
39
44
45
+ // Start the server with middleware.
40
46
const server : FastifyInstance = fastify ( {
41
47
disableRequestLogging : true ,
42
48
...( env . ENABLE_HTTPS ? httpsObject : { } ) ,
Original file line number Diff line number Diff line change
1
+ import { Static , Type } from "@sinclair/typebox" ;
2
+ import { FastifyInstance } from "fastify" ;
3
+ import { StatusCodes } from "http-status-codes" ;
4
+ import { deleteAllWalletNonces } from "../../../db/wallets/deleteAllWalletNonces" ;
5
+ import { standardResponseSchema } from "../../schemas/sharedApiSchemas" ;
6
+
7
+ const responseSchema = Type . Object ( {
8
+ result : Type . Object ( {
9
+ status : Type . String ( ) ,
10
+ } ) ,
11
+ } ) ;
12
+
13
+ responseSchema . example = {
14
+ result : {
15
+ status : "success" ,
16
+ } ,
17
+ } ;
18
+
19
+ export const resetBackendWalletNonces = async ( fastify : FastifyInstance ) => {
20
+ fastify . route < {
21
+ Reply : Static < typeof responseSchema > ;
22
+ } > ( {
23
+ method : "POST" ,
24
+ url : "/backend-wallet/reset-nonces" ,
25
+ schema : {
26
+ summary : "Reset all nonces" ,
27
+ description :
28
+ "Reset nonces for all backend wallets. This is for debugging purposes and does not impact held tokens." ,
29
+ tags : [ "Backend Wallet" ] ,
30
+ operationId : "resetNonces" ,
31
+ response : {
32
+ ...standardResponseSchema ,
33
+ [ StatusCodes . OK ] : responseSchema ,
34
+ } ,
35
+ } ,
36
+ handler : async ( req , reply ) => {
37
+ await deleteAllWalletNonces ( { } ) ;
38
+
39
+ reply . status ( StatusCodes . OK ) . send ( {
40
+ result : {
41
+ status : "success" ,
42
+ } ,
43
+ } ) ;
44
+ } ,
45
+ } ) ;
46
+ } ;
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ import { revokeRelayer } from "./relayer/revoke";
94
94
95
95
// System
96
96
import { getAllTransactions } from "./backend-wallet/getTransactions" ;
97
+ import { resetBackendWalletNonces } from "./backend-wallet/resetNonces" ;
97
98
import { sendTransactionBatch } from "./backend-wallet/sendTransactionBatch" ;
98
99
import { withdraw } from "./backend-wallet/withdraw" ;
99
100
import { home } from "./home" ;
@@ -118,6 +119,7 @@ export const withRoutes = async (fastify: FastifyInstance) => {
118
119
await fastify . register ( signTransaction ) ;
119
120
await fastify . register ( signMessage ) ;
120
121
await fastify . register ( getAllTransactions ) ;
122
+ await fastify . register ( resetBackendWalletNonces ) ;
121
123
122
124
// Configuration
123
125
await fastify . register ( getWalletsConfiguration ) ;
Original file line number Diff line number Diff line change @@ -14,11 +14,11 @@ export const walletAuthSchema = Type.Object({
14
14
export const walletParamSchema = Type . Object ( {
15
15
chain : Type . String ( {
16
16
examples : [ "mumbai" ] ,
17
- description : "Chain ID name" ,
17
+ description : "Chain name" ,
18
18
} ) ,
19
19
walletAddress : Type . String ( {
20
20
examples : [ "0x..." ] ,
21
- description : "Wallet Address " ,
21
+ description : "Backend wallet address " ,
22
22
} ) ,
23
23
} ) ;
24
24
You can’t perform that action at this time.
0 commit comments