Skip to content

Commit 8cd7606

Browse files
authored
fix: include index_block_hash in /block (#1253)
* fix: add index_block_hash to block responses * chore: undo launch changes * test: index_block_hash in /block
1 parent edab62a commit 8cd7606

File tree

6 files changed

+19
-1
lines changed

6 files changed

+19
-1
lines changed

docs/entities/blocks/block.example.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"canonical": true,
33
"height": 3275,
44
"hash": "0xe77ba8cf6bb7c0e4f64adc83356289ed467d31a22354907b4bb814590058430f",
5+
"index_block_hash": "0x918697ef63f9d8bdf844c3312b299e72a231cde542f3173f7755bb8c1cdaf3a7",
56
"parent_block_hash": "0x75ab21ef25cbff2caa14c27d830ed7886a4d1522e1b6f9e5dc3b59ccf73ed49f",
67
"burn_block_time": 1594233639,
78
"burn_block_time_iso": "2020-08-27T16:41:26.000Z",

docs/entities/blocks/block.schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"canonical",
88
"height",
99
"hash",
10+
"index_block_hash",
1011
"parent_block_hash",
1112
"txs",
1213
"burn_block_time",
@@ -37,6 +38,10 @@
3738
"type": "string",
3839
"description": "Hash representing the block"
3940
},
41+
"index_block_hash": {
42+
"type": "string",
43+
"description": "The only hash that can uniquely identify an anchored block or an unconfirmed state trie"
44+
},
4045
"parent_block_hash": {
4146
"type": "string",
4247
"description": "Hash of the parent block"

docs/generated.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,10 @@ export interface Block {
11121112
* Hash representing the block
11131113
*/
11141114
hash: string;
1115+
/**
1116+
* The only hash that can uniquely identify an anchored block or an unconfirmed state trie
1117+
*/
1118+
index_block_hash: string;
11151119
/**
11161120
* Hash of the parent block
11171121
*/

src/api/controllers/db-controller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ function parseDbBlock(
464464
canonical: dbBlock.canonical,
465465
height: dbBlock.block_height,
466466
hash: dbBlock.block_hash,
467+
index_block_hash: dbBlock.index_block_hash,
467468
parent_block_hash: dbBlock.parent_block_hash,
468469
burn_block_time: dbBlock.burn_block_time,
469470
burn_block_time_iso: unixEpochToIso(dbBlock.burn_block_time),

src/tests/api-tests.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,7 @@ describe('api tests', () => {
23302330
execution_cost_write_count: 0,
23312331
execution_cost_write_length: 0,
23322332
hash: '0x1234000000000000000000000000000000000000000000000000000000000000',
2333+
index_block_hash: '0xdeadbeef',
23332334
height: 1,
23342335
microblocks_accepted: [],
23352336
microblocks_streamed: [],
@@ -7269,6 +7270,7 @@ describe('api tests', () => {
72697270
canonical: true,
72707271
hash: '0x1234',
72717272
height: 1235,
7273+
index_block_hash: '0xdeadbeef',
72727274
parent_block_hash: '0xff0011',
72737275
parent_microblock_hash: '',
72747276
parent_microblock_sequence: 0,
@@ -7390,6 +7392,7 @@ describe('api tests', () => {
73907392
execution_cost_write_count: 0,
73917393
execution_cost_write_length: 0,
73927394
hash: '0x0001',
7395+
index_block_hash: '0x0001',
73937396
height: 1,
73947397
microblocks_accepted: [],
73957398
microblocks_streamed: [
@@ -7438,6 +7441,7 @@ describe('api tests', () => {
74387441
execution_cost_write_count: 0,
74397442
execution_cost_write_length: 0,
74407443
hash: '0x0002',
7444+
index_block_hash: '0x0002',
74417445
height: 2,
74427446
microblocks_accepted: [microblock1.microblocks[0].microblock_hash],
74437447
microblocks_streamed: [],
@@ -9399,7 +9403,8 @@ describe('api tests', () => {
93999403
// fetch all blocks
94009404
const result1 = await supertest(api.server).get(`/extended/v1/block`);
94019405
expect(result1.body.total).toBe(1);
9402-
expect(result1.body.results[0].hash).toBe(tx.tx_id);
9406+
expect(result1.body.results[0].hash).toBe('0x1234');
9407+
expect(result1.body.results[0].index_block_hash).toBe('0xdeadbeef');
94039408
});
94049409

94059410
test('fetch transactions from block', async () => {

src/tests/cache-control-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ describe('cache-control tests', () => {
155155
miner_txid: '0x4321',
156156
canonical: true,
157157
hash: '0x1234',
158+
index_block_hash: '0xdeadbeef',
158159
height: 1,
159160
parent_block_hash: '0xff0011',
160161
parent_microblock_hash: '',
@@ -298,6 +299,7 @@ describe('cache-control tests', () => {
298299
miner_txid: '0x4321',
299300
canonical: true,
300301
hash: '0x1234',
302+
index_block_hash: '0xdeadbeef',
301303
height: 1,
302304
parent_block_hash: '0xff0011',
303305
parent_microblock_hash: '',

0 commit comments

Comments
 (0)