@@ -8,8 +8,7 @@ import * as a from './assets'
8
8
import * as n from './nfts'
9
9
import * as u from './uniques'
10
10
import { BatchContext , Context , SelectedEvent } from './utils/types'
11
- import { updateCache } from './utils/cache'
12
- import { logError } from './utils/logger'
11
+ import { updateOfferCache } from './utils/cache'
13
12
14
13
type HandlerFunction = < T extends SelectedEvent > ( item : T , ctx : Context ) => Promise < void >
15
14
@@ -234,105 +233,26 @@ export async function mainFrame(ctx: BatchContext<Store>): Promise<void> {
234
233
}
235
234
}
236
235
237
- // const lastDate = new Date(ctx.blocks[ctx.blocks.length - 1].header.timestamp || start)
238
- // await updateCache(lastDate, ctx.store)
239
-
240
- // const { contracts, tokens } = uniqueEntitySets(items)
241
- // const collections = await finalizeCollections(contracts, ctx)
242
- // const finish = await whatToDoWithTokens({ tokens, collections, items }, ctx)
243
- // const complete = await completeTokens(ctx, finish)
244
-
245
- // logger.info(`Batch completed, ${complete.length} tokens saved`)
236
+ if ( ctx . isHead ) {
237
+ const lastBlock = ctx . blocks [ ctx . blocks . length - 1 ] . header
238
+ const lastDate = new Date ( lastBlock . timestamp || Date . now ( ) )
239
+ logger . info ( `Found head block, updating cache` )
240
+ await updateOfferCache ( lastDate , lastBlock . height , ctx . store )
241
+ }
246
242
}
247
243
248
- // function unwrapLog(log: Log, block: BlockData) {
249
- // switch (log.topics[0]) {
250
- // case ERC721_TRANSFER:
244
+ // class Head {
245
+ // #height: number
251
246
252
- // if (log.address !== Contracts.HueNft) {
253
- // return null
254
- // }
255
- // return handle721Token(log, block)
256
- // default:
257
- // // console.log('unknown log', log.topics[0])
258
- // return null
259
- // // throw new Error('unknown log')
247
+ // constructor(height: number) {
248
+ // this.#height = height
260
249
// }
261
- // }
262
-
263
- type What = {
264
- // tokens: Set<string>,
265
- // collections: EnMap<CE>,
266
- // items: ItemStateUpdate[],
267
- }
268
250
269
- export async function whatToDoWithTokens ( x : What , ctx : Context ) {
270
- // // ctx.store.findBy(CE, {id: In([...collectionMap.keys()])})
271
- // const knownTokens = await findByIdListAsMap(ctx.store, NE, tokens)
272
- // const events: EventEntity[] = []
273
- // for (const item of items) {
274
- // logger.debug(`APPLY ${item.interaction} on ${item.id}`)
275
- // let knownToken = knownTokens.get(item.id) ?? create(NE, item.id, {})
276
- // if (item.applyFrom) {
277
- // const collection = collections.get(item.contract)!
278
- // item.applyFrom(collection)
279
- // }
280
- // if (item.applyTo) {
281
- // knownToken = item.applyTo(knownToken)
282
- // }
283
- // events.push(item.event)
284
- // knownTokens.set(item.id, knownToken)
285
- // }
286
- // const values = [...knownTokens.values()]
287
- // await ctx.store.upsert(values)
288
- // await ctx.store.save(events)
289
- // return knownTokens
290
- }
251
+ // get height() {
252
+ // return this.#height
253
+ // }
291
254
292
- type EnMap < T > = Map < string , T >
293
- // TODO: do only if event was mint.
294
- async function completeTokens ( ctx : Context , tokenMap : EnMap < NE > ) {
295
- // const collections = groupedItemsByCollection(tokenMap.keys())
296
- // const final: NE[] = []
297
- // const metadataFutures: Promise<Optional<MetadataEntity>>[] = []
298
- // for (const [contract, ids] of collections.entries()) {
299
- // const list = Array.from(ids)
300
- // const tokens = await multicallMetadataFetch(ctx, contract, list)
301
- // for (const [i, id] of list.entries()) {
302
- // const realId = createTokenId(contract, id)
303
- // const token = tokenMap.get(realId)!
304
- // if (!token.metadata) {
305
- // const metadata = tokens[i]
306
- // token.metadata = metadata
307
- // const getMeta = handleMetadata(metadata, ctx.store).then(m => {
308
- // if (m) {
309
- // token.meta = m
310
- // token.name = m.name
311
- // token.image = m.image
312
- // token.media = m.animationUrl
313
- // }
314
- // return m
315
- // })
316
- // metadataFutures.push(getMeta)
317
- // final.push(token)
318
- // }
319
- // }
320
- // }
321
- // const metaList = await Promise.all(metadataFutures)
322
- // const filtered = metaList.filter(m => m) as MetadataEntity[]
323
- // logger.debug(`Saving ${filtered.length} metadata`)
324
- // await ctx.store.save(filtered)
325
- // await ctx.store.save(final)
326
- // return final
327
- // }
328
- // async function multicallMetadataFetch(ctx: Context, collection: string, tokens: Array<string>): Promise<string[]> {
329
- // const tokenIds = tokens.map((id) => [BigInt(id)])
330
- // const contract = new Multicall(ctx, lastBatchBlock(ctx), MULTICALL_ADDRESS)
331
- // const metadata = await contract.aggregate(
332
- // erc721.functions.tokenURI,
333
- // collection,
334
- // tokenIds,
335
- // MULTICALL_BATCH_SIZE
336
- // )
337
- // return metadata
338
- }
255
+ // set height(height: number) {
256
+ // this.#height = height
257
+ // }
258
+ // }
0 commit comments