From 563148c8bd20360f95af71b24943449bb2e5b6f7 Mon Sep 17 00:00:00 2001 From: Dmitryii Osipov Date: Fri, 22 Mar 2024 11:19:41 +0400 Subject: [PATCH] fix(idea/indexer): index status of programs created from programs, set entry for messages sent from programs (#1514) --- idea/indexer/src/gear/handlers/events.ts | 2 +- idea/indexer/src/gear/temp-state.ts | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/idea/indexer/src/gear/handlers/events.ts b/idea/indexer/src/gear/handlers/events.ts index 4871c1fedb..3aceee8f23 100644 --- a/idea/indexer/src/gear/handlers/events.ts +++ b/idea/indexer/src/gear/handlers/events.ts @@ -150,7 +150,7 @@ export async function handleEvents({ } of necessaryEvents) { switch (method) { case EventNames.ProgramChanged: { - promises.push(programChanged(data as ProgramChangedData, blockHash, timestamp, genesis, api, tempState)); + await programChanged(data as ProgramChangedData, blockHash, timestamp, genesis, api, tempState); continue; } case EventNames.CodeChanged: { diff --git a/idea/indexer/src/gear/temp-state.ts b/idea/indexer/src/gear/temp-state.ts index 230fd8188d..09a365bb62 100644 --- a/idea/indexer/src/gear/temp-state.ts +++ b/idea/indexer/src/gear/temp-state.ts @@ -1,6 +1,6 @@ import { CodeStatus, MessageReadReason } from '@gear-js/common'; -import { MessageStatus, ProgramStatus, getMetahash } from '../common'; +import { MessageEntryPoint, MessageStatus, MessageType, ProgramStatus, getMetahash } from '../common'; import { Block, Code, Message, Program } from '../database'; import { BlockService, CodeService, MessageService, ProgramService } from '../services'; import { RMQService } from '../rmq'; @@ -99,6 +99,19 @@ export class TempState { } } + async getMsgEntry(id: string): Promise { + if (this.messages.has(id)) { + return this.messages.get(id).entry; + } + + try { + const msg = await this.messageService.get({ id, genesis: this.genesis }); + return msg.entry; + } catch (err) { + return null; + } + } + async setProgramStatus(id: string, status: ProgramStatus, expiration?: string) { const program = await this.getProgram(id); if (program) { @@ -161,6 +174,15 @@ export class TempState { await this.codeService.save(Array.from(this.codes.values())); })(), + (async () => { + for (const m of this.messages.values()) { + if (m.type === MessageType.MSG_SENT) { + if (m.replyToMessageId) { + m.entry = await this.getMsgEntry(m.replyToMessageId); + } + } + } + })(), this.messageService.save(Array.from(this.messages.values())), (async () => { const programIds = Array.from(this.programs.keys());