Skip to content

Commit

Permalink
Fix incorrect timestamp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Mar 17, 2023
1 parent 1b486bb commit 537a37e
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import find from 'lodash/find';
import map from 'lodash/map';
import { z } from 'zod';
import { addMinutes, isBefore, toDate } from 'date-fns';
import { subMinutes, isBefore, toDate } from 'date-fns';
import { ethers } from 'ethers';
import { decode } from '@api3/airnode-abi';
import { logger } from '@api3/airnode-utilities';
Expand Down Expand Up @@ -156,7 +156,7 @@ export function validateAndDecodeBeacons(beacons: Beacon[]) {
for (const beacon of beacons) {
const { airnodeAddress, endpointId, encodedParameters, encodedValue, timestamp, signature } = beacon;
// The timestamp is older than the last 2 minutes
if (isBefore(toDate(Number(timestamp)), addMinutes(currentTime, -TIMESTAMP_DEVIATION))) {
if (isBefore(toDate(Number(timestamp) * 1000), subMinutes(currentTime, TIMESTAMP_DEVIATION))) {
throw new Error('Beacon timestamp too old');
}

Expand Down

0 comments on commit 537a37e

Please sign in to comment.