Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
346 changes: 344 additions & 2 deletions client/src/generated/schema.d.ts

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/api/controllers/db-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,10 @@ function parseDbAbstractTx(dbTx: DbTx, baseTx: BaseTransaction): AbstractTransac
...baseTx,
is_unanchored: dbTx.block_hash === '0x',
block_hash: dbTx.block_hash,
index_block_hash: dbTx.index_block_hash,
parent_block_hash: dbTx.parent_block_hash,
block_height: dbTx.block_height,
tenure_height: dbTx.tenure_height,
block_time: dbTx.block_time || dbTx.burn_block_time,
block_time_iso: dbTx.block_time
? unixEpochToIso(dbTx.block_time)
Expand Down
8 changes: 8 additions & 0 deletions src/api/schemas/entities/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ const AbstractTransactionProperties = {
block_hash: Type.String({
description: 'Hash of the blocked this transactions was associated with',
}),
index_block_hash: Type.String({
description: 'Hash of the block index this transactions was associated with',
}),
block_height: Type.Integer({
description: 'Height of the block this transactions was associated with',
}),
tenure_height: Nullable(
Type.Integer({
description: 'Height of the block index (tenure) this transactions was associated with',
})
),
block_time: Type.Number({
description: 'Unix timestamp (in seconds) indicating when this block was mined.',
}),
Expand Down
2 changes: 2 additions & 0 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export interface DbTx extends BaseTx {
block_hash: string;
parent_block_hash: string;
block_height: number;
tenure_height: number | null;
burn_block_time: number;
burn_block_height: number;
parent_burn_block_time: number;
Expand Down Expand Up @@ -963,6 +964,7 @@ export interface TxQueryResult {
block_time: number;
parent_block_hash: string;
block_height: number;
tenure_height: number | null;
burn_block_height: number;
burn_block_time: number;
parent_burn_block_time: number;
Expand Down
2 changes: 2 additions & 0 deletions src/datastore/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export function parseTxQueryResult(result: ContractTxQueryResult): DbTx {
block_time: result.block_time || result.burn_block_time,
parent_block_hash: result.parent_block_hash,
block_height: result.block_height,
tenure_height: result.tenure_height,
burn_block_height: result.burn_block_height,
burn_block_time: result.burn_block_time,
parent_burn_block_time: result.parent_burn_block_time,
Expand Down Expand Up @@ -1183,6 +1184,7 @@ export function createDbTxFromCoreMsg(msg: CoreNodeParsedTxMessage): DbTxRaw {
parent_block_hash: msg.parent_block_hash,
block_hash: msg.block_hash,
block_height: msg.block_height,
tenure_height: msg.tenure_height,
burn_block_height: msg.burn_block_height,
burn_block_time: msg.burn_block_time,
parent_burn_block_time: msg.parent_burn_block_time,
Expand Down
12 changes: 10 additions & 2 deletions src/datastore/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1379,8 +1379,12 @@ export class PgStore extends BasePgStore {
return await this.sqlTransaction(async sql => {
const maxBlockHeight = await this.getMaxBlockHeight(sql, { includeUnanchored });
const result = await sql<ContractTxQueryResult[]>`
SELECT ${sql(TX_COLUMNS)}, ${abiColumn(sql)}
SELECT ${sql(TX_COLUMNS)}, blocks.tenure_height, ${abiColumn(sql)}
FROM txs
LEFT JOIN (
SELECT index_block_hash, tenure_height
FROM blocks
) AS blocks USING (index_block_hash)
WHERE tx_id = ${txId} AND block_height <= ${maxBlockHeight}
ORDER BY canonical DESC, microblock_canonical DESC, block_height DESC
LIMIT 1
Expand Down Expand Up @@ -3573,8 +3577,12 @@ export class PgStore extends BasePgStore {
return await this.sqlTransaction(async sql => {
const maxBlockHeight = await this.getMaxBlockHeight(sql, { includeUnanchored });
const result = await sql<ContractTxQueryResult[]>`
SELECT ${sql(TX_COLUMNS)}, ${abiColumn(sql)}
SELECT ${sql(TX_COLUMNS)}, blocks.tenure_height, ${abiColumn(sql)}
FROM txs
LEFT JOIN (
SELECT index_block_hash, tenure_height
FROM blocks
) AS blocks USING (index_block_hash)
WHERE tx_id IN ${sql(txIds)}
AND block_height <= ${maxBlockHeight}
AND canonical = true
Expand Down
1 change: 1 addition & 0 deletions src/event-stream/core-node-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export interface CoreNodeParsedTxMessage {
microblock_sequence: number;
microblock_hash: string;
block_height: number;
tenure_height: number | null,
burn_block_height: number;
burn_block_time: number;
parent_burn_block_time: number;
Expand Down
2 changes: 2 additions & 0 deletions src/event-stream/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ export interface CoreNodeMsgBlockData {
parent_burn_block_height: number;
parent_burn_block_hash: string;
block_height: number;
tenure_height: number | null;
burn_block_time: number;
burn_block_height: number;
block_time: number;
Expand Down Expand Up @@ -941,6 +942,7 @@ export function parseMessageTransaction(
parent_burn_block_hash: blockData.parent_burn_block_hash,
parent_burn_block_time: blockData.parent_burn_block_timestamp,
block_height: blockData.block_height,
tenure_height: blockData.tenure_height,
burn_block_height: blockData.burn_block_height,
burn_block_time: blockData.burn_block_time,
microblock_sequence: coreTx.microblock_sequence ?? I32_MAX,
Expand Down
15 changes: 15 additions & 0 deletions tests/api/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -364,6 +365,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -429,6 +431,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -768,6 +771,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -844,6 +848,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -935,6 +940,7 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
Expand Down Expand Up @@ -1915,6 +1921,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -1975,6 +1982,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2019,6 +2027,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2064,6 +2073,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2109,6 +2119,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
burn_block_height: 100123123,
Expand Down Expand Up @@ -2169,6 +2180,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
burn_block_height: 100123123,
Expand Down Expand Up @@ -2241,6 +2253,7 @@ describe('address tests', () => {
tx: {
anchor_mode: 'any',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2322,6 +2335,7 @@ describe('address tests', () => {
tx: {
anchor_mode: 'any',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2401,6 +2415,7 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down
2 changes: 2 additions & 0 deletions tests/api/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ describe('search tests', () => {
anchor_mode: 'any',
is_unanchored: false,
block_hash: '0x1234000000000000000000000000000000000000000000000000000000000000',
index_block_hash: '0xdeadbeef',
parent_block_hash: '0x',
block_height: 1,
block_time: 2837565,
Expand Down Expand Up @@ -1553,6 +1554,7 @@ describe('search tests', () => {
metadata: {
anchor_mode: 'any',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
block_time: 2837565,
block_time_iso: '1970-02-02T20:12:45.000Z',
Expand Down
Loading