Skip to content

Commit 00e1624

Browse files
committed
feat: 🎸 Added claimed deal saving step to the node example
1 parent e539bc4 commit 00e1624

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

‎examples/node/index.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
serverAddress,
1313
} from '../shared/index.js';
1414
import {
15+
DealsDb,
1516
Node,
1617
NodeOptions,
1718
NodeRequestManager,
@@ -87,6 +88,7 @@ const createJobHandler =
8788
*/
8889
interface DealHandlerOptions {
8990
contracts: ProtocolContracts;
91+
dealsDb: DealsDb;
9092
}
9193

9294
/**
@@ -100,7 +102,7 @@ const dealHandler = createJobHandler<
100102
throw new Error('Invalid job execution configuration');
101103
}
102104

103-
const { contracts } = options;
105+
const { contracts, dealsDb } = options;
104106

105107
if (!contracts) {
106108
throw new Error('Contracts manager must be provided to job handler config');
@@ -109,7 +111,8 @@ const dealHandler = createJobHandler<
109111
logger.trace(`Checking for a deal. Offer #${offer.id}`);
110112

111113
// 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);
113116

114117
// Deal must be exists and not cancelled
115118
if (buyer !== zeroAddress && status === DealStatus.Created) {
@@ -127,6 +130,17 @@ const dealHandler = createJobHandler<
127130
},
128131
);
129132

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+
130144
return false; // Returning false means that the job must be stopped
131145
}
132146

@@ -286,7 +300,14 @@ const main = async (): Promise<void> => {
286300
requestManager.add(topic, data);
287301
});
288302

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+
);
290311

291312
/**
292313
* Graceful Shutdown handler

0 commit comments

Comments
 (0)