From 8caba34d894fd7c8f7201581c3ac48702aa8323b Mon Sep 17 00:00:00 2001 From: jejolare Date: Thu, 26 Sep 2024 18:20:12 +0700 Subject: [PATCH] swap to BigInt --- server/schemes/AltBlock.ts | 4 ++-- server/schemes/Block.ts | 4 ++-- server/schemes/Chart.ts | 4 ++-- server/server.ts | 4 ++-- src/interfaces/common/BlockInfo.ts | 2 +- src/pages/block/[hash].tsx | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/schemes/AltBlock.ts b/server/schemes/AltBlock.ts index 7061dce..fbd72a5 100644 --- a/server/schemes/AltBlock.ts +++ b/server/schemes/AltBlock.ts @@ -5,7 +5,7 @@ class AltBlock extends Model { declare readonly id: number; declare height: number; declare timestamp: Date; - declare actual_timestamp: Date; + declare actual_timestamp: BigInt; declare size: BigInt; declare hash: string; declare type: number; @@ -34,7 +34,7 @@ AltBlock.init( id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, height: { type: DataTypes.INTEGER, allowNull: false }, timestamp: { type: DataTypes.DATE, allowNull: false }, - actual_timestamp: { type: DataTypes.DATE, allowNull: true }, + actual_timestamp: { type: DataTypes.BIGINT, allowNull: true }, size: { type: DataTypes.BIGINT, allowNull: true }, hash: { type: DataTypes.STRING, allowNull: true }, type: { type: DataTypes.INTEGER, allowNull: true }, diff --git a/server/schemes/Block.ts b/server/schemes/Block.ts index e6bec88..d665bae 100644 --- a/server/schemes/Block.ts +++ b/server/schemes/Block.ts @@ -5,7 +5,7 @@ import Transaction from "./Transaction"; class Block extends Model { declare readonly id: number; declare height: number; - declare actual_timestamp: Date; + declare actual_timestamp: BigInt; declare base_reward: string; declare blob: string; declare block_cumulative_size: string; @@ -41,7 +41,7 @@ Block.init( id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, height: { type: DataTypes.INTEGER, allowNull: false, unique: true }, - actual_timestamp: { type: DataTypes.DATE, allowNull: true }, + actual_timestamp: { type: DataTypes.BIGINT, allowNull: true }, base_reward: { type: DataTypes.TEXT, allowNull: true }, blob: { type: DataTypes.STRING, allowNull: true }, block_cumulative_size: { type: DataTypes.TEXT, allowNull: true }, diff --git a/server/schemes/Chart.ts b/server/schemes/Chart.ts index 313b946..6dec8eb 100644 --- a/server/schemes/Chart.ts +++ b/server/schemes/Chart.ts @@ -4,7 +4,7 @@ import sequelize from "../database/sequelize"; class Chart extends Model { declare readonly id: number; declare height: number; - declare actual_timestamp: Date; + declare actual_timestamp: BigInt; declare block_cumulative_size: string; declare cumulative_diff_precise: string; declare difficulty: string; @@ -25,7 +25,7 @@ Chart.init( id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true }, height: { type: DataTypes.INTEGER, allowNull: false }, - actual_timestamp: { type: DataTypes.DATE, allowNull: true }, + actual_timestamp: { type: DataTypes.BIGINT, allowNull: true }, block_cumulative_size: { type: DataTypes.TEXT, allowNull: true }, cumulative_diff_precise: { type: DataTypes.TEXT, allowNull: true }, difficulty: { type: DataTypes.TEXT, allowNull: true }, diff --git a/server/server.ts b/server/server.ts index 59e3fd6..d1bb580 100644 --- a/server/server.ts +++ b/server/server.ts @@ -390,7 +390,7 @@ const requestsLimiter = rateLimit({ app.get('/api/get_chart/:chart/:offset', async (req, res) => { const { chart, offset } = req.params; - const offsetDate = new Date(parseInt(offset, 10)); + const offsetDate = parseInt(offset, 10); const charts = await Chart.findAll({ attributes: ['actual_timestamp'], @@ -1234,7 +1234,7 @@ const requestsLimiter = rateLimit({ chartInserts.push({ height: bl.height, - actual_timestamp: new Date(bl.actual_timestamp * 1000), + actual_timestamp: bl.actual_timestamp, block_cumulative_size: bl.block_cumulative_size, cumulative_diff_precise: bl.cumulative_diff_precise, difficulty: bl.difficulty, diff --git a/src/interfaces/common/BlockInfo.ts b/src/interfaces/common/BlockInfo.ts index c7374e9..151ebdf 100644 --- a/src/interfaces/common/BlockInfo.ts +++ b/src/interfaces/common/BlockInfo.ts @@ -1,7 +1,7 @@ interface BlockInfo { type: "PoS" | "PoW"; timestamp?: Date; - actualTimestamp?: Date; + actualTimestamp?: BigInt; difficulty: string; minerTextInfo?: string; cummulativeDiffAdjusted?: string; diff --git a/src/pages/block/[hash].tsx b/src/pages/block/[hash].tsx index 942f4dd..5bd47b9 100644 --- a/src/pages/block/[hash].tsx +++ b/src/pages/block/[hash].tsx @@ -162,7 +162,7 @@ function Block(props: BlockProps) { Actual Timestamp (UTC): - {blockInfo?.actualTimestamp ? Utils.formatTimestampUTC(+new Date(blockInfo?.actualTimestamp)) : "-"} + {blockInfo?.actualTimestamp ? Utils.formatTimestampUTC(parseInt(blockInfo?.actualTimestamp.toString(), 10)) : "-"} Difficulty: