Skip to content

Commit fa81b6f

Browse files
committed
fix: added option to input ledger state for nf data call
1 parent 6623418 commit fa81b6f

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/GatewayProcessor/GatewayProcessor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,18 +504,20 @@ export class GatewayProcessor {
504504
* Retrieves non-fungibles items associated with specified resource address and ids.
505505
* @param resource_address Address of the non-fungible items.
506506
* @param ids Ids of the non-fungible items.
507+
* @param at_ledger_state State against which to make the query.
507508
*/
508509
async getNonFungibleItemsFromIds(
509510
resource_address: ResourceAddress,
510511
ids: string[],
512+
at_ledger_state?: number,
511513
): Promise<NonFungibleItem[]> {
512514
const nft_batches = divideInBatches(ids, 100);
513515
const limit = pLimit(this._concurrencyLimit);
514516
return (
515517
await Promise.all(
516518
nft_batches.map(async (batch) => {
517519
let items_data = await limit(async () =>
518-
this.getNonFungibleData(resource_address, batch),
520+
this.getNonFungibleData(resource_address, batch, at_ledger_state),
519521
);
520522
return items_data.map((item) => {
521523
let description: string = "";
@@ -874,10 +876,19 @@ export class GatewayProcessor {
874876
private async getNonFungibleData(
875877
address: ResourceAddress,
876878
ids: string[],
879+
at_ledger_state?: number,
877880
): Promise<StateNonFungibleDetailsResponseItem[]> {
878881
return withMaxLoops(
879882
async () => {
880-
return await this._api.state.getNonFungibleData(address, ids);
883+
return await this._api.state.getNonFungibleData(
884+
address,
885+
ids,
886+
at_ledger_state
887+
? {
888+
state_version: at_ledger_state,
889+
}
890+
: undefined,
891+
);
881892
},
882893
"Could not query non fungible data",
883894
this._maxLoops,

tests/GatewayProcessor.tests.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,24 @@ test("Test transaction stream", async () => {
203203
);
204204
expect(stream.length).toEqual(10);
205205
});
206+
207+
test("Test get data with state", async () => {
208+
const transactionProcessor = GatewayProcessor.fromNetworkId(
209+
NetworkId.Mainnet,
210+
);
211+
212+
let stream = await transactionProcessor.getNonFungibleItemsFromIds(
213+
"resource_rdx1n2pf8l2qwzzqz5lyuhmdnlxcjqdyxksa5uhtzjjx8zg2tegcdqkd7p",
214+
["#1750#"],
215+
135409909,
216+
);
217+
218+
expect(stream.length).toEqual(1);
219+
220+
const item = stream[0];
221+
222+
expect(item.description).toBeDefined();
223+
expect(item.non_fungible_data).toBeDefined();
224+
expect(item.name).toBeDefined();
225+
expect(item.image_url).toBeDefined();
226+
});

0 commit comments

Comments
 (0)