Skip to content
Open
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,6 +1125,7 @@ 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,
block_time: dbTx.block_time || dbTx.burn_block_time,
Expand All @@ -1140,6 +1141,7 @@ function parseDbAbstractTx(dbTx: DbTx, baseTx: BaseTransaction): AbstractTransac
parent_burn_block_time_iso:
dbTx.parent_burn_block_time > 0 ? unixEpochToIso(dbTx.parent_burn_block_time) : '',
canonical: dbTx.canonical,
tenure_height: dbTx.tenure_height || dbTx.block_height,
tx_index: dbTx.tx_index,
tx_status: getTxStatusString(dbTx.status) as TransactionStatus,
tx_result: {
Expand Down
9 changes: 9 additions & 0 deletions src/api/schemas/entities/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ const AbstractTransactionProperties = {
description:
'An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) timestamp indicating when this block was mined.',
}),
index_block_hash: Type.String({
description:
'The only hash that can uniquely identify an anchored block or an unconfirmed state trie',
}),
parent_burn_block_time: Type.Integer({
description: 'Unix timestamp (in seconds) indicating when this parent block was mined',
}),
Expand All @@ -84,6 +88,11 @@ const AbstractTransactionProperties = {
canonical: Type.Boolean({
description: 'Set to `true` if block corresponds to the canonical chain tip',
}),
tenure_height: Nullable(
Type.Integer({
description: 'The tenure height (AKA coinbase height) of this block',
})
),
tx_index: Type.Integer({
description:
'Index of the transaction, indicating the order. Starts at `0` and increases with each transaction',
Expand Down
3 changes: 3 additions & 0 deletions src/datastore/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export interface DbTx extends BaseTx {

tx_index: number;

tenure_height?: number | null;

/** Hex encoded Clarity values. */
raw_result: string;

Expand Down Expand Up @@ -973,6 +975,7 @@ export interface TxQueryResult {
status: number;
raw_result: string;
canonical: boolean;
tenure_height?: number | null;

microblock_canonical: boolean;
microblock_sequence: number;
Expand Down
6 changes: 6 additions & 0 deletions src/datastore/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ export function abiColumn(sql: PgSqlClient, tableName: string = 'txs'): postgres
`;
}

export function tenureHeightColumn(sql: PgSqlClient): postgres.Fragment {
return sql`
SELECT tenure_height FROM blocks WHERE index_block_hash = txs.index_block_hash
`;
}

export function parseMempoolTxQueryResult(result: MempoolTxQueryResult): DbMempoolTx {
const tx: DbMempoolTx = {
pruned: result.pruned,
Expand Down
15 changes: 8 additions & 7 deletions src/datastore/pg-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
POX4_SYNTHETIC_EVENT_COLUMNS,
POX_SYNTHETIC_EVENT_COLUMNS,
prefixedCols,
tenureHeightColumn,
TX_COLUMNS,
validateZonefileHash,
} from './helpers';
Expand Down Expand Up @@ -818,7 +819,7 @@ export class PgStore extends BasePgStore {
AND index_block_hash = ${blockQuery.result.index_block_hash}
`;
const result = await sql<ContractTxQueryResult[]>`
SELECT ${sql(TX_COLUMNS)}, ${abiColumn(sql)}
SELECT ${sql(TX_COLUMNS)}, ${abiColumn(sql)}, (${tenureHeightColumn(sql)}) AS tenure_height
FROM txs
WHERE canonical = true AND microblock_canonical = true
AND index_block_hash = ${blockQuery.result.index_block_hash}
Expand Down Expand Up @@ -1379,7 +1380,7 @@ 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)}, ${abiColumn(sql)}, (${tenureHeightColumn(sql)}) AS tenure_height
FROM txs
WHERE tx_id = ${txId} AND block_height <= ${maxBlockHeight}
ORDER BY canonical DESC, microblock_canonical DESC, block_height DESC
Expand Down Expand Up @@ -3334,15 +3335,15 @@ export class PgStore extends BasePgStore {
{ address: string; balance: string; count: number; total_supply: string }[]
>`
WITH totals AS (
SELECT
SELECT
SUM(balance) AS total,
COUNT(*)::int AS total_count
FROM ft_balances
WHERE token = ${args.token}
)
SELECT
fb.address,
fb.balance,
SELECT
fb.address,
fb.balance,
ts.total AS total_supply,
ts.total_count AS count
FROM ft_balances fb
Expand Down Expand Up @@ -3573,7 +3574,7 @@ 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)}, ${abiColumn(sql)}, (${tenureHeightColumn(sql)}) AS tenure_height
FROM txs
WHERE tx_id IN ${sql(txIds)}
AND block_height <= ${maxBlockHeight}
Expand Down
30 changes: 30 additions & 0 deletions tests/api/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -364,7 +366,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -429,7 +433,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -768,7 +774,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -844,7 +852,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -935,7 +945,9 @@ describe('address tests', () => {
post_conditions: [],
tx_status: 'success',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 1594647994,
block_time_iso: '2020-07-13T13:46:34.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -1915,7 +1927,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -1975,7 +1989,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -2019,7 +2035,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -2064,7 +2082,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -2109,7 +2129,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
burn_block_height: 100123123,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2169,7 +2191,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
burn_block_height: 100123123,
block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2241,9 +2265,11 @@ 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',
tenure_height: 1,
burn_block_height: 100123123,
burn_block_time: 39486,
burn_block_time_iso: '1970-01-01T10:58:06.000Z',
Expand Down Expand Up @@ -2322,7 +2348,9 @@ describe('address tests', () => {
tx: {
anchor_mode: 'any',
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down Expand Up @@ -2401,7 +2429,9 @@ describe('address tests', () => {
post_condition_mode: 'allow',
post_conditions: [],
block_hash: '0x1234',
index_block_hash: '0x1234',
block_height: 1,
tenure_height: 1,
block_time: 39486,
block_time_iso: '1970-01-01T10:58:06.000Z',
burn_block_height: 100123123,
Expand Down
4 changes: 4 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 All @@ -565,6 +566,7 @@ describe('search tests', () => {
parent_burn_block_time: 1626122935,
parent_burn_block_time_iso: '2021-07-12T20:48:55.000Z',
canonical: true,
tenure_height: 1,
tx_index: 4,
tx_status: 'success',
tx_result: {
Expand Down Expand Up @@ -1568,6 +1570,7 @@ describe('search tests', () => {
execution_cost_write_count: 0,
execution_cost_write_length: 0,
fee_rate: '1234',
index_block_hash: '0x1234',
is_unanchored: false,
microblock_canonical: true,
microblock_hash: '0x',
Expand All @@ -1585,6 +1588,7 @@ describe('search tests', () => {
source_code: '(some-src)',
},
sponsored: false,
tenure_height: 1,
tx_id: '0x1111880000000000000000000000000000000000000000000000000000000000',
tx_index: 0,
tx_result: {
Expand Down
Loading