Skip to content

Commit

Permalink
timestamp comparison(snapshot-labs#32) (snapshot-labs#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 authored Mar 2, 2021
1 parent 62e6f99 commit 3d5aa6d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ router.get('/voters', async (req, res) => {
router.post('/message', async (req, res) => {
const body = req.body;
const msg = jsonParse(body.msg);
const ts = (Date.now() / 1e3).toFixed();
const now = Date.now() / 1e3;
const ts = now.toFixed();
const upts = (now + 300).toFixed();
// const minBlock = (3600 * 24) / 15;

if (!body || !body.address || !body.msg || !body.sig)
Expand All @@ -122,9 +124,9 @@ router.post('/message', async (req, res) => {
return sendError(res, 'unknown space');

if (
!msg.timestamp ||
!msg.timestamp ||
typeof msg.timestamp !== 'string' ||
msg.timestamp > ts + 300
msg.timestamp > upts
)
return sendError(res, 'wrong timestamp');

Expand Down

0 comments on commit 3d5aa6d

Please sign in to comment.