Skip to content

Commit ae6bbe8

Browse files
authored
feat: add nakamoto block time to v2 endpoints (#1921)
1 parent 3e64492 commit ae6bbe8

File tree

6 files changed

+30
-0
lines changed

6 files changed

+30
-0
lines changed

docs/entities/blocks/block.example.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"canonical": true,
33
"height": 3275,
44
"hash": "0xe77ba8cf6bb7c0e4f64adc83356289ed467d31a22354907b4bb814590058430f",
5+
"block_time": 1594233639,
6+
"block_time_iso": "2020-08-27T16:41:26.000Z",
57
"index_block_hash": "0x918697ef63f9d8bdf844c3312b299e72a231cde542f3173f7755bb8c1cdaf3a7",
68
"parent_block_hash": "0x75ab21ef25cbff2caa14c27d830ed7886a4d1522e1b6f9e5dc3b59ccf73ed49f",
79
"burn_block_time": 1594233639,

docs/entities/blocks/nakamoto-block.example.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"canonical": true,
33
"height": 3275,
44
"hash": "0xe77ba8cf6bb7c0e4f64adc83356289ed467d31a22354907b4bb814590058430f",
5+
"block_time": 1594233639,
6+
"block_time_iso": "2020-08-27T16:41:26.000Z",
57
"index_block_hash": "0x918697ef63f9d8bdf844c3312b299e72a231cde542f3173f7755bb8c1cdaf3a7",
68
"parent_block_hash": "0x75ab21ef25cbff2caa14c27d830ed7886a4d1522e1b6f9e5dc3b59ccf73ed49f",
79
"parent_index_block_hash": "0x4262db117659d1ca9406970c8f44ffd3d8f11f8e18c591d2e3960f4070107756",

docs/entities/blocks/nakamoto-block.schema.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"canonical",
88
"height",
99
"hash",
10+
"block_time",
11+
"block_time_iso",
1012
"index_block_hash",
1113
"parent_block_hash",
1214
"parent_index_block_hash",
@@ -36,6 +38,14 @@
3638
"type": "string",
3739
"description": "Hash representing the block"
3840
},
41+
"block_time": {
42+
"type": "number",
43+
"description": "Unix timestamp (in seconds) indicating when this block was mined."
44+
},
45+
"block_time_iso": {
46+
"type": "string",
47+
"description": "An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined."
48+
},
3949
"index_block_hash": {
4050
"type": "string",
4151
"description": "The only hash that can uniquely identify an anchored block or an unconfirmed state trie"

docs/generated.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,14 @@ export interface NakamotoBlock {
14791479
* Hash representing the block
14801480
*/
14811481
hash: string;
1482+
/**
1483+
* Unix timestamp (in seconds) indicating when this block was mined.
1484+
*/
1485+
block_time: number;
1486+
/**
1487+
* An ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) indicating when this block was mined.
1488+
*/
1489+
block_time_iso: string;
14821490
/**
14831491
* The only hash that can uniquely identify an anchored block or an unconfirmed state trie
14841492
*/

src/api/routes/v2/helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export function parseDbNakamotoBlock(block: DbBlock): NakamotoBlock {
3333
canonical: block.canonical,
3434
height: block.block_height,
3535
hash: block.block_hash,
36+
block_time: block.block_time,
37+
block_time_iso: unixEpochToIso(block.block_time),
3638
index_block_hash: block.index_block_hash,
3739
parent_block_hash: block.parent_block_hash,
3840
parent_index_block_hash: block.parent_index_block_hash,

src/tests/block-tests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ describe('block tests', () => {
672672

673673
// Filter by burn hash
674674
const block5 = {
675+
block_time: 94869286,
676+
block_time_iso: '1973-01-03T00:34:46.000Z',
675677
burn_block_hash: '0x00000000000000000001e2ee7f0c6bd5361b5e7afd76156ca7d6f524ee5ca3d8',
676678
burn_block_height: 700000,
677679
burn_block_time: 94869286,
@@ -707,6 +709,8 @@ describe('block tests', () => {
707709

708710
// Get latest block
709711
const block8 = {
712+
block_time: 94869286,
713+
block_time_iso: '1973-01-03T00:34:46.000Z',
710714
burn_block_hash: '0x000000000000000000028eacd4e6e58405d5a37d06b5d7b93776f1eab68d2494',
711715
burn_block_height: 700001,
712716
burn_block_time: 94869286,
@@ -758,6 +762,8 @@ describe('block tests', () => {
758762

759763
// Get latest
760764
const block5 = {
765+
block_time: 94869286,
766+
block_time_iso: '1973-01-03T00:34:46.000Z',
761767
burn_block_hash: '0x00000000000000000001e2ee7f0c6bd5361b5e7afd76156ca7d6f524ee5ca3d8',
762768
burn_block_height: 700000,
763769
burn_block_time: 94869286,

0 commit comments

Comments
 (0)