Skip to content

Commit

Permalink
fix: added new options to full transaction stream
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvinci committed Sep 11, 2024
1 parent a64fc85 commit 5e6f0a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/GatewayProcessor/GatewayProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ export class GatewayProcessor {
async fullTransactionStream(
from_state_version: number,
entity_filter?: string[],
max_amount?: number,
): Promise<CommittedTransactionInfo[]> {
let cursor: string | null | undefined = undefined;
let full_stream: CommittedTransactionInfo[] = [];
const stop_amount = max_amount ? max_amount : Number.MAX_SAFE_INTEGER;
do {
let stream: StreamTransactionsResponse = await this.transactionStream(
from_state_version,
Expand All @@ -155,9 +157,9 @@ export class GatewayProcessor {
): tx is CommittedTransactionInfo => tx !== null,
),
);
} while (cursor);
} while (cursor && full_stream.length < stop_amount);

return full_stream;
return full_stream.slice(0, stop_amount);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/GatewayProcessor.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,16 @@ test("Test Get Nft Owner", async () => {
"account_tdx_2_1298yfy03ertz3dywxqejsvswrz9448dxzw6ak3dz5cdey8gccu63fg",
);
});

test("Test transaction stream", async () => {
const transactionProcessor = GatewayProcessor.fromNetworkId(
NetworkId.Stokenet,
);

let stream = await transactionProcessor.fullTransactionStream(
66000000,
undefined,
10,
);
expect(stream.length).toEqual(10);
});

0 comments on commit 5e6f0a6

Please sign in to comment.