Skip to content

Commit

Permalink
fix(idea/indexer): index status of programs created from programs, se…
Browse files Browse the repository at this point in the history
…t entry for messages sent from programs (#1514)
  • Loading branch information
osipov-mit authored Mar 22, 2024
1 parent 7e335b5 commit 563148c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion idea/indexer/src/gear/handlers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
24 changes: 23 additions & 1 deletion idea/indexer/src/gear/temp-state.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -99,6 +99,19 @@ export class TempState {
}
}

async getMsgEntry(id: string): Promise<MessageEntryPoint> {
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) {
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 563148c

Please sign in to comment.