Skip to content

Commit

Permalink
Add transaction detail API cache
Browse files Browse the repository at this point in the history
- as /chain/transaction/{hash} endpoint response won't change, cache it
  • Loading branch information
lubej committed Jul 10, 2024
1 parent 7ca812c commit 8652661
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/1979.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add transaction detail API cache
13 changes: 12 additions & 1 deletion src/vendors/oasisscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {

import { throwAPIErrors } from './helpers'

const getTransactionCacheMap: Record<string, Transaction> = {}

export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainnet') {
const explorerConfig = new Configuration({
basePath: url,
Expand Down Expand Up @@ -54,11 +56,20 @@ export function getOasisscanAPIs(url: string | 'https://api.oasisscan.com/mainne
}

async function getTransaction({ hash }: { hash: string }) {
if (hash in getTransactionCacheMap) {
return getTransactionCacheMap[hash]
}

const transaction = await operationsEntity.getTransaction({
hash,
})

const [parsedTx] = parseTransactionsList([transaction.data])
const [parsedTx] = parseTransactionsList([transaction.data ?? {}])

if (transaction.code === 0 && !!transaction.data) {
getTransactionCacheMap[hash] = parsedTx
}

return parsedTx
}

Expand Down

0 comments on commit 8652661

Please sign in to comment.