Skip to content

Commit 7cc8bd0

Browse files
authored
feat: add block height to responses in /extended/v1/tokens/nft/holdings (#1151)
* feat: added blocck_height in nft/holdings * docs: updated examples for nft/holdings * docs: updated block_height for nft and ft holdings examples
1 parent 87ef457 commit 7cc8bd0

9 files changed

+25
-2
lines changed

docs/api/tokens/get-non-fungible-token-holdings-tx-metadata.example.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"hex": "0x0100000000000000000000000000000803",
1010
"repr": "u2051"
1111
},
12+
"block_height": 36442,
1213
"tx": {
1314
"tx_id": "0x12e6f88724d0e630de26c376f172cf1781e25435e2b4ee54d36a949b244e429c",
1415
"nonce": 7,
@@ -67,6 +68,7 @@
6768
"hex": "0x01000000000000000000000000000004f3",
6869
"repr": "u1267"
6970
},
71+
"block_height": 37477,
7072
"tx": {
7173
"tx_id": "0xddc464c5e20a78dc5ac351913e0d9b9cce76fc955cc4599e0cccad960998f130",
7274
"nonce": 10,
@@ -125,6 +127,7 @@
125127
"hex": "0x0c00000002046e616d65020000000672616661656c096e616d6573706163650200000003627463",
126128
"repr": "(tuple (name 0x72616661656c) (namespace 0x627463))"
127129
},
130+
"block_height": 17250,
128131
"tx": {
129132
"tx_id": "0x0153a41ed24a0e1d32f66ea98338df09f942571ca66359e28bdca79ccd0305cf",
130133
"nonce": 4,

docs/api/tokens/get-non-fungible-token-holdings.example.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"hex": "0x0100000000000000000000000000000803",
1010
"repr": "u2051"
1111
},
12+
"block_height": 36442,
1213
"tx_id": "0x12e6f88724d0e630de26c376f172cf1781e25435e2b4ee54d36a949b244e429c"
1314
},
1415
{
@@ -17,6 +18,7 @@
1718
"hex": "0x01000000000000000000000000000004f3",
1819
"repr": "u1267"
1920
},
21+
"block_height": 37477,
2022
"tx_id": "0xddc464c5e20a78dc5ac351913e0d9b9cce76fc955cc4599e0cccad960998f130"
2123
},
2224
{
@@ -25,6 +27,7 @@
2527
"hex": "0x0c00000002046e616d65020000000672616661656c096e616d6573706163650200000003627463",
2628
"repr": "(tuple (name 0x72616661656c) (namespace 0x627463))"
2729
},
30+
"block_height": 17250,
2831
"tx_id": "0x0153a41ed24a0e1d32f66ea98338df09f942571ca66359e28bdca79ccd0305cf"
2932
}
3033
]

docs/entities/tokens/non-fungible-token-holding-0-tx-id.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "object",
44
"title": "NonFungibleTokenHoldingWithTxId",
55
"description": "Ownership of a Non-Fungible Token",
6-
"required": ["asset_identifier", "value", "tx_id"],
6+
"required": ["asset_identifier", "value", "tx_id", "block_height"],
77
"additionalProperties": false,
88
"properties": {
99
"asset_identifier": {
@@ -25,6 +25,9 @@
2525
}
2626
}
2727
},
28+
"block_height": {
29+
"type": "number"
30+
},
2831
"tx_id": {
2932
"type": "string"
3033
}

docs/entities/tokens/non-fungible-token-holding-1-tx-metadata.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "object",
44
"title": "NonFungibleTokenHoldingWithTxMetadata",
55
"description": "Ownership of a Non-Fungible Token with transaction metadata",
6-
"required": ["asset_identifier", "value", "tx"],
6+
"required": ["asset_identifier", "value", "tx", "block_height"],
77
"additionalProperties": false,
88
"properties": {
99
"asset_identifier": {
@@ -25,6 +25,9 @@
2525
}
2626
}
2727
},
28+
"block_height": {
29+
"type": "number"
30+
},
2831
"tx": {
2932
"$ref": "../transactions/transaction.schema.json"
3033
}

docs/generated.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,7 @@ export interface NonFungibleTokenHoldingWithTxId {
32533253
*/
32543254
repr: string;
32553255
};
3256+
block_height: number;
32563257
tx_id: string;
32573258
}
32583259
/**
@@ -3273,6 +3274,7 @@ export interface NonFungibleTokenHoldingWithTxMetadata {
32733274
*/
32743275
repr: string;
32753276
};
3277+
block_height: number;
32763278
tx: Transaction;
32773279
}
32783280
/**

src/api/routes/tokens/tokens.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function createTokenRouter(db: DataStore): express.Router {
8282
hex: bufferToHexPrefixString(result.nft_holding_info.value),
8383
repr: parsedClarityValue,
8484
},
85+
block_height: result.nft_holding_info.block_height,
8586
};
8687
if (includeTxMetadata && result.tx) {
8788
return { ...parsedNftData, tx: parseDbTx(result.tx) };

src/datastore/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ export interface NftHoldingInfo {
363363
// TODO(perf): use hex string since that is what we already get from deserializing event payloads
364364
// and from the pg-node adapter (all the pg js libs use text mode rather than binary mode)
365365
value: Buffer;
366+
block_height: number;
366367
recipient: string;
367368
tx_id: Buffer;
368369
}

src/datastore/postgres-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6544,6 +6544,7 @@ export class PgDataStore
65446544
value: row.value,
65456545
recipient: row.recipient,
65466546
tx_id: row.tx_id,
6547+
block_height: row.block_height,
65476548
},
65486549
tx: args.includeTxMetadata ? this.parseTxQueryResult(row) : undefined,
65496550
})),

src/tests/token-tests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('/extended/v1/tokens tests', () => {
5151
expect(result1.total).toEqual(1);
5252
expect(result1.results[0].asset_identifier).toEqual(assetId1);
5353
expect(result1.results[0].tx_id).toEqual('0x5454');
54+
expect(result1.results[0].block_height).toEqual(block1.block.block_height);
5455

5556
// Request: with metadata
5657
const request2 = await supertest(api.server).get(
@@ -62,6 +63,7 @@ describe('/extended/v1/tokens tests', () => {
6263
expect(result2.total).toEqual(1);
6364
expect(result2.results[0].asset_identifier).toEqual(assetId1);
6465
expect(result2.results[0].tx.tx_id).toEqual('0x5454');
66+
expect(result2.results[0].block_height).toEqual(block1.block.block_height);
6567

6668
// Mint another NFT
6769
const block2 = new TestBlockBuilder({
@@ -89,6 +91,7 @@ describe('/extended/v1/tokens tests', () => {
8991
expect(result3.total).toEqual(2);
9092
expect(result3.results[0].asset_identifier).toEqual(assetId2);
9193
expect(result3.results[0].tx_id).toEqual('0x5464');
94+
expect(result3.results[0].block_height).toEqual(block2.block.block_height);
9295

9396
// Request: filtered by asset id
9497
const request4 = await supertest(api.server).get(
@@ -100,6 +103,7 @@ describe('/extended/v1/tokens tests', () => {
100103
expect(result4.total).toEqual(1); // 1 result only
101104
expect(result4.results[0].asset_identifier).toEqual(assetId2);
102105
expect(result4.results[0].tx_id).toEqual('0x5464');
106+
expect(result4.results[0].block_height).toEqual(block2.block.block_height);
103107

104108
// Transfer one NFT from addr1 to addr2
105109
const block3 = new TestBlockBuilder({
@@ -127,6 +131,7 @@ describe('/extended/v1/tokens tests', () => {
127131
expect(result5.total).toEqual(1);
128132
expect(result5.results[0].asset_identifier).toEqual(assetId1);
129133
expect(result5.results[0].tx_id).toEqual('0x5454');
134+
expect(result5.results[0].block_height).toEqual(block1.block.block_height);
130135

131136
// Request: addr2 has the other
132137
const request6 = await supertest(api.server).get(
@@ -138,6 +143,7 @@ describe('/extended/v1/tokens tests', () => {
138143
expect(result6.total).toEqual(1);
139144
expect(result6.results[0].asset_identifier).toEqual(assetId2);
140145
expect(result6.results[0].tx_id).toEqual('0x5484');
146+
expect(result6.results[0].block_height).toEqual(block3.block.block_height);
141147

142148
// Transfer NFT from addr2 to addr3 in microblock
143149
const microblock1 = new TestMicroblockStreamBuilder()

0 commit comments

Comments
 (0)