Skip to content

Commit

Permalink
fix: display all timestamps in milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Jan 29, 2025
1 parent 89d69f7 commit e5e55f2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 80 deletions.
18 changes: 11 additions & 7 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import {

export const DEFAULT_API_LIMIT = 20;

function parseTimestamp(timestamp: number): number {
return timestamp * 1000;
}

export function parseDbInscriptions(
items: DbFullyLocatedInscriptionResult[]
): InscriptionResponseType[] {
Expand All @@ -39,7 +43,7 @@ export function parseDbInscriptions(
genesis_block_hash: i.genesis_block_hash,
genesis_tx_id: i.genesis_tx_id,
genesis_fee: i.genesis_fee.toString(),
genesis_timestamp: i.genesis_timestamp.valueOf(),
genesis_timestamp: parseTimestamp(i.genesis_timestamp),
tx_id: i.tx_id,
location: `${i.output}:${i.offset}`,
output: i.output,
Expand All @@ -51,7 +55,7 @@ export function parseDbInscriptions(
mime_type: i.mime_type,
content_type: i.content_type,
content_length: parseInt(i.content_length),
timestamp: i.timestamp.valueOf(),
timestamp: parseTimestamp(i.timestamp),
curse_type: i.curse_type,
recursive: i.recursive,
recursion_refs: i.recursion_refs?.split(',') ?? null,
Expand All @@ -75,7 +79,7 @@ export function parseInscriptionLocations(items: DbLocation[]): InscriptionLocat
output: i.output,
value: i.value,
offset: i.offset,
timestamp: i.timestamp.valueOf(),
timestamp: parseTimestamp(i.timestamp),
}));
}

Expand All @@ -94,7 +98,7 @@ export function parseBlockTransfers(
output: i.from_output,
value: i.from_value,
offset: i.from_offset,
timestamp: i.from_timestamp.valueOf(),
timestamp: parseTimestamp(i.from_timestamp),
},
to: {
block_height: parseInt(i.to_block_height),
Expand All @@ -105,7 +109,7 @@ export function parseBlockTransfers(
output: i.to_output,
value: i.to_value,
offset: i.to_offset,
timestamp: i.to_timestamp.valueOf(),
timestamp: parseTimestamp(i.to_timestamp),
},
}));
}
Expand All @@ -121,7 +125,7 @@ export function parseBrc20Tokens(items: DbBrc20Token[]): Brc20TokenResponse[] {
max_supply: decimals(i.max, i.decimals),
mint_limit: i.limit ? decimals(i.limit, i.decimals) : null,
decimals: i.decimals,
deploy_timestamp: i.timestamp.valueOf(),
deploy_timestamp: parseTimestamp(i.timestamp),
minted_supply: decimals(i.minted_supply, i.decimals),
tx_count: parseInt(i.tx_count),
self_mint: i.self_mint,
Expand Down Expand Up @@ -156,7 +160,7 @@ export function parseBrc20Activities(items: DbBrc20Activity[]): Brc20ActivityRes
location: `${i.output}:${i.offset}`,
block_hash: i.block_hash,
block_height: parseInt(i.block_height),
timestamp: i.timestamp.valueOf(),
timestamp: parseTimestamp(i.timestamp),
};
switch (i.operation) {
case DbBrc20EventOperation.deploy: {
Expand Down
4 changes: 2 additions & 2 deletions src/pg/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ export class PgStore extends BasePgStore {
}
${
filters?.from_genesis_timestamp
? sql`AND i.timestamp >= ${filters.from_genesis_timestamp}`
? sql`AND i.timestamp >= ${filters.from_genesis_timestamp}::bigint / 1000`
: sql``
}
${
filters?.to_genesis_timestamp
? sql`AND i.timestamp <= ${filters.to_genesis_timestamp}`
? sql`AND i.timestamp <= ${filters.to_genesis_timestamp}::bigint / 1000`
: sql``
}
${
Expand Down
76 changes: 5 additions & 71 deletions src/pg/types.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,6 @@
import { PgNumeric, PgBytea, PgSqlQuery } from '@hirosystems/api-toolkit';
import { Order, OrderBy } from '../api/schemas';
import { SatoshiRarity } from '../api/util/ordinal-satoshi';

export type DbSatoshiInsert = {
ordinal_number: PgNumeric;
rarity: string;
coinbase_height: number;
};

export type DbInscriptionInsert = {
genesis_id: string;
ordinal_number: PgNumeric;
number: number;
classic_number: number;
block_height: number;
block_hash: string;
tx_index: number;
address: string;
mime_type: string;
content_type: string;
content_length: number;
content: PgBytea;
fee: PgNumeric;
curse_type: string | null;
recursive: boolean;
metadata: string | null;
parent: string | null;
input_index: number;
pointer: number | null;
metaprotocol: string | null;
delegate: string | null;
timestamp: number;
};

export type DbLocationInsert = {
ordinal_number: PgNumeric;
block_height: number;
block_hash: string;
tx_index: number;
tx_id: string;
address: string;
output: string;
offset: PgNumeric | null;
prev_output: string | null;
prev_offset: PgNumeric | null;
value: PgNumeric | null;
transfer_type: DbLocationTransferType;
timestamp: number;
};

export type DbCurrentLocationInsert = {
ordinal_number: PgNumeric;
block_height: number;
tx_index: number;
output: string;
address: string;
};

/**
* Selects
*/

export type DbPaginatedResult<T> = {
total: number;
results: T[];
Expand All @@ -72,7 +12,7 @@ export type DbFullyLocatedInscriptionResult = {
genesis_block_hash: string;
genesis_tx_id: string;
genesis_fee: bigint;
genesis_timestamp: Date;
genesis_timestamp: number;
genesis_address: string;
number: string;
address: string | null;
Expand All @@ -87,7 +27,7 @@ export type DbFullyLocatedInscriptionResult = {
mime_type: string;
content_type: string;
content_length: string;
timestamp: Date;
timestamp: number;
curse_type: string | null;
recursive: boolean;
recursion_refs: string | null;
Expand All @@ -99,12 +39,6 @@ export type DbFullyLocatedInscriptionResult = {
delegate: string | null;
};

export enum DbLocationTransferType {
transferred = 'transferred',
spentInFees = 'spent_in_fees',
burnt = 'burnt',
}

export type DbLocation = {
genesis_id: string;
block_height: string;
Expand All @@ -117,7 +51,7 @@ export type DbLocation = {
prev_output: string | null;
prev_offset: string | null;
value: string | null;
timestamp: Date;
timestamp: number;
};

export type DbInscriptionLocationChange = {
Expand All @@ -130,15 +64,15 @@ export type DbInscriptionLocationChange = {
from_output: string;
from_offset: string | null;
from_value: string | null;
from_timestamp: Date;
from_timestamp: number;
to_block_height: string;
to_block_hash: string;
to_tx_id: string;
to_address: string;
to_output: string;
to_offset: string | null;
to_value: string | null;
to_timestamp: Date;
to_timestamp: number;
};

export type DbInscriptionContent = {
Expand Down

0 comments on commit e5e55f2

Please sign in to comment.