Skip to content

Commit 6d03b13

Browse files
committed
refactor: 💡 Client updated to use latest types and changes
1 parent df102a7 commit 6d03b13

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

‎src/client/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
12
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events';
23
import { createLibp2p, Libp2pOptions, Libp2p } from 'libp2p';
34
import { noise } from '@chainsafe/libp2p-noise';
@@ -9,15 +10,15 @@ import { peerIdFromString } from '@libp2p/peer-id';
910
import { PeerId } from '@libp2p/interface-peer-id';
1011
import { OPEN } from '@libp2p/interface-connection/status';
1112
import { AbstractProvider } from 'ethers';
12-
import { centerSub, CenterSub } from '../shared/pubsub.js';
1313
import {
14-
buildRequest,
1514
BuildRequestOptions,
1615
OfferData,
1716
GenericOfferOptions,
1817
GenericQuery,
1918
RequestData,
20-
} from '../shared/messages.js';
19+
} from '../shared/types.js';
20+
import { centerSub, CenterSub } from '../shared/pubsub.js';
21+
import { buildRequest } from '../shared/messages.js';
2122
import { ClientOptions } from '../shared/options.js';
2223
import { RequestRecord, RequestsRegistry } from './requestsRegistry.js';
2324
import { decodeText } from '../utils/text.js';

‎src/client/requestsRegistry.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { EventEmitter, CustomEvent } from '@libp2p/interfaces/events';
22
import { Client } from '../index.js';
3-
import { GenericOfferOptions, GenericQuery, RequestData, OfferData } from '../shared/messages.js';
3+
import { GenericOfferOptions, GenericQuery, RequestData, OfferData } from '../shared/types.js';
44
import { Storage } from '../storage/index.js';
55
import { createLogger } from '../utils/logger.js';
66
import { encodeText } from '../utils/text.js';
77
import { nowSec } from '../utils/time.js';
8+
import { stringify } from '../utils/hash.js';
89

910
const logger = createLogger('RequestsRegistry');
1011

@@ -272,9 +273,9 @@ export class RequestsRegistry<
272273
throw new Error('Client not connected to the coordination server yet');
273274
}
274275

275-
const now = nowSec();
276+
const now = BigInt(nowSec());
276277

277-
if (record.data.expire < nowSec() || record.cancelled) {
278+
if (BigInt(record.data.expire) < nowSec() || record.cancelled) {
278279
return;
279280
}
280281

@@ -288,7 +289,7 @@ export class RequestsRegistry<
288289
}),
289290
);
290291
this._unsubscribe(record.data.id);
291-
}, (record.data.expire - now) * 1000),
292+
}, Number((BigInt(record.data.expire) - now) * BigInt(1000))),
292293
);
293294
this.dispatchEvent(
294295
new CustomEvent<string>('subscribe', {
@@ -339,7 +340,7 @@ export class RequestsRegistry<
339340
this._subscribe(requestRecord);
340341

341342
this.client.libp2p.pubsub
342-
.publish(request.topic, encodeText(JSON.stringify(request)))
343+
.publish(request.topic, encodeText(stringify(request)))
343344
.then(() => {
344345
this.dispatchEvent(
345346
new CustomEvent<string>('published', {

0 commit comments

Comments
 (0)