1
1
import 'dotenv/config' ;
2
2
import { EventHandler } from '@libp2p/interfaces/events' ;
3
3
import { DateTime } from 'luxon' ;
4
- import { Hash , Hex , zeroAddress } from 'viem' ;
4
+ import { Address , Hash , Hex , zeroAddress } from 'viem' ;
5
5
import { hardhat , polygonZkEvmTestnet } from 'viem/chains' ;
6
6
import { randomSalt } from '@windingtree/contracts' ;
7
7
import {
@@ -25,6 +25,12 @@ import { noncePeriod } from '../../src/constants.js';
25
25
import { memoryStorage } from '../../src/storage/index.js' ;
26
26
import { nowSec , parseSeconds } from '../../src/utils/time.js' ;
27
27
import { RequestEvent } from '../../src/node/requestManager.js' ;
28
+ import {
29
+ router ,
30
+ userRouter ,
31
+ adminRouter ,
32
+ NodeApiServer ,
33
+ } from '../../src/node/index.js' ;
28
34
import { createLogger } from '../../src/utils/logger.js' ;
29
35
30
36
const logger = createLogger ( 'NodeMain' ) ;
@@ -57,6 +63,17 @@ if (!supplierId) {
57
63
throw new Error ( 'Entity Id must be provided with EXAMPLE_ENTITY_ID env' ) ;
58
64
}
59
65
66
+ /**
67
+ * The Ethereum account address of the entity owner (supplier)
68
+ */
69
+ const entityOwnerAddress = process . env . EXAMPLE_ENTITY_OWNER_ADDRESS as Address ;
70
+
71
+ if ( ! entityOwnerAddress ) {
72
+ throw new Error (
73
+ 'Entity owner address must be provided with EXAMPLE_ENTITY_OWNER_ADDRESS env' ,
74
+ ) ;
75
+ }
76
+
60
77
/** Handles UFOs */
61
78
process . once ( 'unhandledRejection' , ( error ) => {
62
79
logger . trace ( '🛸 Unhandled rejection' , error ) ;
@@ -116,7 +133,7 @@ const dealHandler = createJobHandler<
116
133
} ,
117
134
) ;
118
135
119
- return false ; // Returning true means that the job must be stopped
136
+ return false ; // Returning false means that the job must be stopped
120
137
}
121
138
122
139
return true ; // Job continuing
@@ -228,10 +245,36 @@ const main = async (): Promise<void> => {
228
245
walletClient : node . walletClient ,
229
246
} ) ;
230
247
231
- const storage = await memoryStorage . createInitializer ( ) ( ) ;
248
+ const queueStorage = await memoryStorage . createInitializer ( {
249
+ scope : 'queue' ,
250
+ } ) ( ) ;
251
+ const usersStorage = await memoryStorage . createInitializer ( {
252
+ scope : 'users' ,
253
+ } ) ( ) ;
254
+ const dealsStorage = await memoryStorage . createInitializer ( {
255
+ scope : 'deals' ,
256
+ } ) ( ) ;
257
+
258
+ const apiServer = new NodeApiServer ( {
259
+ usersStorage,
260
+ dealsStorage,
261
+ prefix : 'test' ,
262
+ port : 3456 ,
263
+ secret : 'secret' ,
264
+ ownerAccount : entityOwnerAddress ,
265
+ protocolContracts : contractsManager ,
266
+ } ) ;
267
+
268
+ apiServer . start (
269
+ router ( {
270
+ user : userRouter ,
271
+ admin : adminRouter ,
272
+ // You can add your own routes here
273
+ } ) ,
274
+ ) ;
232
275
233
276
const queue = new Queue ( {
234
- storage,
277
+ storage : queueStorage ,
235
278
idsKeyName : 'jobsIds' ,
236
279
concurrencyLimit : 3 ,
237
280
} ) ;
@@ -262,6 +305,7 @@ const main = async (): Promise<void> => {
262
305
*/
263
306
const shutdown = ( ) => {
264
307
const stopHandler = async ( ) => {
308
+ await apiServer . stop ( ) ;
265
309
await node . stop ( ) ;
266
310
} ;
267
311
stopHandler ( )
0 commit comments