From 99902e70c72d715746ea43a4fddf1d0bc7c52f6e Mon Sep 17 00:00:00 2001 From: nymkappa Date: Fri, 27 May 2022 20:43:14 +0200 Subject: [PATCH] Use block hash instead of block height in urls --- backend/src/repositories/BlocksRepository.ts | 53 ++++++++++++++++--- .../blocks-list/blocks-list.component.html | 2 +- .../app/components/pool/pool.component.html | 3 +- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/backend/src/repositories/BlocksRepository.ts b/backend/src/repositories/BlocksRepository.ts index dcd5b48d1..7e58b9453 100644 --- a/backend/src/repositories/BlocksRepository.ts +++ b/backend/src/repositories/BlocksRepository.ts @@ -240,8 +240,26 @@ class BlocksRepository { } const params: any[] = []; - let query = ` SELECT *, UNIX_TIMESTAMP(blocks.blockTimestamp) as blockTimestamp, - previous_block_hash as previousblockhash + let query = ` SELECT + height, + hash as id, + UNIX_TIMESTAMP(blocks.blockTimestamp) as blockTimestamp, + size, + weight, + tx_count, + coinbase_raw, + difficulty, + fees, + fee_span, + median_fee, + reward, + version, + bits, + nonce, + merkle_root, + previous_block_hash as previousblockhash, + avg_fee, + avg_fee_rate FROM blocks WHERE pool_id = ?`; params.push(pool.id); @@ -274,11 +292,32 @@ class BlocksRepository { */ public async $getBlockByHeight(height: number): Promise { try { - const [rows]: any[] = await DB.query(` - SELECT *, UNIX_TIMESTAMP(blocks.blockTimestamp) as blockTimestamp, - pools.id as pool_id, pools.name as pool_name, pools.link as pool_link, pools.slug as pool_slug, - pools.addresses as pool_addresses, pools.regexes as pool_regexes, - previous_block_hash as previousblockhash + const [rows]: any[] = await DB.query(`SELECT + height, + hash as id, + UNIX_TIMESTAMP(blocks.blockTimestamp) as blockTimestamp, + size, + weight, + tx_count, + coinbase_raw, + difficulty, + pools.id as pool_id, + pools.name as pool_name, + pools.link as pool_link, + pools.slug as pool_slug, + pools.addresses as pool_addresses, + pools.regexes as pool_regexes, + fees, + fee_span, + median_fee, + reward, + version, + bits, + nonce, + merkle_root, + previous_block_hash as previousblockhash, + avg_fee, + avg_fee_rate FROM blocks JOIN pools ON blocks.pool_id = pools.id WHERE height = ${height}; diff --git a/frontend/src/app/components/blocks-list/blocks-list.component.html b/frontend/src/app/components/blocks-list/blocks-list.component.html index 0e0f5d1e1..b71a96837 100644 --- a/frontend/src/app/components/blocks-list/blocks-list.component.html +++ b/frontend/src/app/components/blocks-list/blocks-list.component.html @@ -21,7 +21,7 @@ - {{ block.height }} + {{ block.height }}
diff --git a/frontend/src/app/components/pool/pool.component.html b/frontend/src/app/components/pool/pool.component.html index 849744253..baddba88f 100644 --- a/frontend/src/app/components/pool/pool.component.html +++ b/frontend/src/app/components/pool/pool.component.html @@ -221,8 +221,7 @@ - {{ block.height - }} + {{ block.height }} ‎{{ block.timestamp * 1000 | date:'yyyy-MM-dd HH:mm' }}