Skip to content

Commit 4dce93b

Browse files
fixup! feat(cardano-services): blockfrost chain history provider now caches transactions locally
1 parent 6c1b9a5 commit 4dce93b

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

packages/cardano-services-client/src/ChainHistoryProvider/BlockfrostChainHistoryProvider.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -476,31 +476,20 @@ export class BlockfrostChainHistoryProvider extends BlockfrostProvider implement
476476
}
477477

478478
public async transactionsByHashes({ ids }: TransactionsByIdsArgs): Promise<Cardano.HydratedTx[]> {
479-
const cachedTransactions: Cardano.HydratedTx[] = [];
480-
const idsToFetch: Cardano.TransactionId[] = [];
481-
482-
for (const id of ids) {
483-
if (this.cache.has(id)) {
484-
cachedTransactions.push(this.cache.get(id)!);
485-
} else {
486-
idsToFetch.push(id);
487-
}
488-
}
489-
490-
let fetchedTransactions: Cardano.HydratedTx[] = [];
491-
if (idsToFetch.length > 0) {
492-
try {
493-
fetchedTransactions = await Promise.all(idsToFetch.map((id) => this.fetchTransaction(id)));
494-
495-
for (const tx of fetchedTransactions) {
496-
this.cache.set(tx.id, tx);
479+
return Promise.all(
480+
ids.map(async (id) => {
481+
if (this.cache.has(id)) {
482+
return this.cache.get(id)!;
497483
}
498-
} catch (error) {
499-
throw this.toProviderError(error);
500-
}
501-
}
502-
503-
return [...cachedTransactions, ...fetchedTransactions];
484+
try {
485+
const fetchedTransaction = await this.fetchTransaction(id);
486+
this.cache.set(id, fetchedTransaction);
487+
return fetchedTransaction;
488+
} catch (error) {
489+
throw this.toProviderError(error);
490+
}
491+
})
492+
);
504493
}
505494

506495
// eslint-disable-next-line sonarjs/cognitive-complexity

0 commit comments

Comments
 (0)