@@ -12,6 +12,7 @@ import {
12
12
serverAddress ,
13
13
} from '../shared/index.js' ;
14
14
import {
15
+ DealsDb ,
15
16
Node ,
16
17
NodeOptions ,
17
18
NodeRequestManager ,
@@ -87,6 +88,7 @@ const createJobHandler =
87
88
*/
88
89
interface DealHandlerOptions {
89
90
contracts : ProtocolContracts ;
91
+ dealsDb : DealsDb ;
90
92
}
91
93
92
94
/**
@@ -100,7 +102,7 @@ const dealHandler = createJobHandler<
100
102
throw new Error ( 'Invalid job execution configuration' ) ;
101
103
}
102
104
103
- const { contracts } = options ;
105
+ const { contracts, dealsDb } = options ;
104
106
105
107
if ( ! contracts ) {
106
108
throw new Error ( 'Contracts manager must be provided to job handler config' ) ;
@@ -109,7 +111,8 @@ const dealHandler = createJobHandler<
109
111
logger . trace ( `Checking for a deal. Offer #${ offer . id } ` ) ;
110
112
111
113
// Check for a deal
112
- const [ , , , buyer , , , status ] = await contracts . getDeal ( offer ) ;
114
+ const [ created , offerPayload , retailerId , buyer , price , asset , status ] =
115
+ await contracts . getDeal ( offer ) ;
113
116
114
117
// Deal must be exists and not cancelled
115
118
if ( buyer !== zeroAddress && status === DealStatus . Created ) {
@@ -127,6 +130,17 @@ const dealHandler = createJobHandler<
127
130
} ,
128
131
) ;
129
132
133
+ await dealsDb . set ( {
134
+ chainId : Number ( offerPayload . chainId ) ,
135
+ created,
136
+ offer,
137
+ retailerId,
138
+ buyer,
139
+ price,
140
+ asset,
141
+ status : DealStatus . Claimed ,
142
+ } ) ;
143
+
130
144
return false ; // Returning false means that the job must be stopped
131
145
}
132
146
@@ -286,7 +300,14 @@ const main = async (): Promise<void> => {
286
300
requestManager . add ( topic , data ) ;
287
301
} ) ;
288
302
289
- queue . registerHandler ( 'deal' , dealHandler ( { contracts : contractsManager } ) ) ;
303
+ queue . registerHandler (
304
+ 'deal' ,
305
+ dealHandler ( {
306
+ contracts : contractsManager ,
307
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
308
+ dealsDb : apiServer . deals ! ,
309
+ } ) ,
310
+ ) ;
290
311
291
312
/**
292
313
* Graceful Shutdown handler
0 commit comments