Skip to content

Commit

Permalink
Merge pull request #94 from reservoirprotocol/block-fixes
Browse files Browse the repository at this point in the history
feat: fix rounding issues
  • Loading branch information
r3lays authored Nov 7, 2023
2 parents 564fe71 + d8d1240 commit 53ebb29
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reservoir-sync-node",
"version": "2.0.4",
"version": "2.0.5",
"scripts": {
"start": " yarn database:prepare && yarn build && yarn build:viewer && yarn move && node dist/index.js",
"build": "yarn run clean && tsc",
Expand Down
4 changes: 2 additions & 2 deletions src/syncer/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ export class Controller {
return {
id: v4(),
priority: 1,
startDate: reqs[0].data[root][reqs[0].data[root].length - 1].updatedAt,
endDate: reqs[1].data[root][reqs[1].data[root].length - 1].updatedAt,
startDate: reqs[1].data[root][reqs[1].data[root].length - 1].updatedAt,
endDate: reqs[0].data[root][reqs[0].data[root].length - 1].updatedAt,
contract: contract || "",
};
}
Expand Down
16 changes: 8 additions & 8 deletions src/syncer/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class Worker extends EventEmitter {
const ascRes = await this._request(
this._normalize({
...(contract && { contract: contract }),
startTimestamp: parseTimestamp(startDate),
endTimestamp: parseTimestamp(endDate),
startTimestamp: parseTimestamp(startDate, false),
endTimestamp: parseTimestamp(endDate, true),
sortDirection: "asc",
})
);
Expand All @@ -123,8 +123,8 @@ export class Worker extends EventEmitter {
const descRes = await this._request(
this._normalize({
...(contract && { contract: contract }),
startTimestamp: parseTimestamp(startDate),
endTimestamp: parseTimestamp(endDate),
startTimestamp: parseTimestamp(startDate, false),
endTimestamp: parseTimestamp(endDate, true),
sortDirection: "desc",
})
);
Expand Down Expand Up @@ -185,8 +185,8 @@ export class Worker extends EventEmitter {
this._normalize({
...(this.continuation && { continuation: this.continuation }),
sortDirection: "asc",
startTimestamp: parseTimestamp(startDate),
endTimestamp: parseTimestamp(endDate),
startTimestamp: parseTimestamp(startDate, false),
endTimestamp: parseTimestamp(endDate, true),
})
);

Expand Down Expand Up @@ -232,7 +232,7 @@ export class Worker extends EventEmitter {
{
...(this.continuation && { continuation: this.continuation }),
sortDirection: "asc",
startTimestamp: parseTimestamp(startDate),
startTimestamp: parseTimestamp(startDate, false),
endTimestamp: END_OF_TIME,
},
false
Expand All @@ -254,7 +254,7 @@ export class Worker extends EventEmitter {
{
...(this.continuation && { continuation: this.continuation }),
sortDirection: "desc",
startTimestamp: parseTimestamp(startDate),
startTimestamp: parseTimestamp(startDate, false),
endTimestamp: END_OF_TIME,
},
false
Expand Down
7 changes: 5 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,20 @@ export const isErrorResponse = (
return r.status !== 200;
};

export function parseTimestamp(date: string): number {
export function parseTimestamp(date: string, isEndTime: boolean): number {
const datePieces = date.split("T");
const [year, month, day] = datePieces[0].split("-").map(Number);

const timePieces = datePieces[1].substring(0, 8).split(":").map(Number);
const [hour, minute, second] = timePieces;

const timeAdjustment = isEndTime ? 5000 : -5000;

const startDate = new Date(year, month - 1, day, hour, minute, second);

const timezoneOffset = startDate.getTimezoneOffset() * 60 * 1000;
return (startDate.getTime() - timezoneOffset) / 1000;

return (startDate.getTime() - timezoneOffset + timeAdjustment) / 1000;
}

/**
Expand Down

0 comments on commit 53ebb29

Please sign in to comment.