Skip to content

Commit 47ba195

Browse files
committed
fix(swaps): update swap cachec expired status with relay number
1 parent a9f26b9 commit 47ba195

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/mappings/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Asset, NonFungible, NonFungibleCall, NewNonFungible, Unique } from '../
77
import * as a from './assets'
88
import * as n from './nfts'
99
import * as u from './uniques'
10-
import { BatchContext, Context, SelectedEvent } from './utils/types'
10+
import { BatchContext, Block, Context, SelectedEvent } from './utils/types'
1111
import { ParachainSystemCall } from '../processable'
1212
import { updateSwapsCache } from './utils/cache'
1313

@@ -200,6 +200,18 @@ const globalHandler: Record<string, HandlerFunction> = {
200200
Assets: assets,
201201
}
202202

203+
function getRelayParentNumber(block: Block): number | undefined {
204+
let relayParentNumber: number | undefined
205+
206+
const validationCall = block.calls?.find((c) => c.name === ParachainSystemCall.setValidationData)
207+
208+
if (validationCall) {
209+
relayParentNumber = validationCall.args?.data?.validationData?.relayParentNumber as number | undefined
210+
}
211+
212+
return relayParentNumber
213+
}
214+
203215
/**
204216
* mainFrame is the main entry point for processing a batch of blocks
205217
**/
@@ -216,13 +228,8 @@ export async function mainFrame(ctx: BatchContext<Store>): Promise<void> {
216228
)
217229

218230
for (const block of ctx.blocks) {
219-
let relayParentNumber: number | undefined
231+
const relayParentNumber = getRelayParentNumber(block)
220232

221-
const validationCall = block.calls?.find((c) => c.name === ParachainSystemCall.setValidationData)
222-
223-
if (validationCall) {
224-
relayParentNumber = validationCall.args?.data?.validationData?.relayParentNumber as number | undefined
225-
}
226233

227234
for (let event of block.events) {
228235
logger.debug(`Processing ${event.name}`)
@@ -244,10 +251,11 @@ export async function mainFrame(ctx: BatchContext<Store>): Promise<void> {
244251
}
245252

246253
if (ctx.isHead) {
247-
const lastBlock = ctx.blocks[ctx.blocks.length - 1].header
248-
const lastDate = new Date(lastBlock.timestamp || Date.now())
254+
const lastBlock = ctx.blocks[ctx.blocks.length - 1]
255+
const relayParentNumber = getRelayParentNumber(lastBlock)
256+
const lastDate = new Date(lastBlock.header.timestamp || Date.now())
249257
logger.info(`Found head block, updating cache`)
250-
await updateSwapsCache(lastDate, lastBlock.height, ctx.store)
258+
await updateSwapsCache(lastDate, (relayParentNumber || lastBlock.header.height), ctx.store)
251259
}
252260
}
253261

0 commit comments

Comments
 (0)