Skip to content

Commit

Permalink
fix(idea/squijd): saving init message payload and setting ProgramSet …
Browse files Browse the repository at this point in the history
…status (#1638)
  • Loading branch information
osipov-mit authored Sep 3, 2024
1 parent 39b7e06 commit 97d2eaa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion idea/squid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dotenv": "16.4.5",
"indexer-db": "workspace:^",
"pg": "8.11.5",
"sails-js": "0.1.4",
"sails-js": "^0.1.9",
"typeorm": "0.3.20"
},
"devDependencies": {
Expand Down
9 changes: 7 additions & 2 deletions idea/squid/src/call.route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateCodeHash } from '@gear-js/api';
import { MessageToProgram, Program } from './model';
import { MessageToProgram, Program, ProgramStatus } from './model';

import { IHandleEventProps } from './event.route';
import { Call } from './processor';
Expand All @@ -18,6 +18,7 @@ export function handleUploadProgram({ msg, event, common, tempState, call }: IHa
codeId,
owner: event.args.source,
name: event.args.destination,
status: ProgramStatus.ProgramSet,
}),
);
msg.payload = call.args.initPayload;
Expand All @@ -42,16 +43,20 @@ export function handleVoucherCall({ ctx, msg, call }: IHandleCallProps) {
}
}

export function handleCreateProgram({ event, common, tempState, call }: IHandleCallProps) {
export function handleCreateProgram({ msg, event, common, tempState, call }: IHandleCallProps) {
tempState.addProgram(
new Program({
...common,
id: event.args.destination,
codeId: call.args.codeId,
owner: event.args.source,
name: event.args.destination,
status: ProgramStatus.ProgramSet,
}),
);

msg.payload = call.args.initPayload;
msg.value = call.args.value;
}

export function handleSendReplyCall({ msg, call }: IHandleCallProps) {
Expand Down
21 changes: 10 additions & 11 deletions idea/squid/src/event.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ export async function handleUserMessageSent({ event, common, tempState }: IHandl
}
}

const PROGRAM_STATUSES = ['ProgramSet', 'Active', 'Terminated', 'Inactive'];
const statuses = {
Active: ProgramStatus.Active,
Inactive: ProgramStatus.Exited,
Terminated: ProgramStatus.Terminated,
ProgramSet: ProgramStatus.ProgramSet,
};
const PROGRAM_STATUSES = Object.keys(statuses);

export async function handleProgramChanged({ ctx, event, common, tempState, block }: IHandleEventProps) {
const {
Expand All @@ -92,8 +98,8 @@ export async function handleProgramChanged({ ctx, event, common, tempState, bloc
call,
} = event;
if (PROGRAM_STATUSES.includes(statusKind)) {
if (statusKind === 'ProgramSet' && !call) {
if (!(await tempState.isProgramIndexed(id))) {
if (statusKind === 'ProgramSet') {
if (!call && !(await tempState.isProgramIndexed(id))) {
tempState.addProgram(
new Program({
...common,
Expand All @@ -106,14 +112,7 @@ export async function handleProgramChanged({ ctx, event, common, tempState, bloc
);
}
} else {
const status =
statusKind === 'ProgramSet'
? ProgramStatus.ProgramSet
: statusKind === 'Active'
? ProgramStatus.Active
: statusKind === 'Inactive'
? ProgramStatus.Exited
: ProgramStatus.Terminated;
const status = statuses[statusKind];

await tempState.setProgramStatus(id, status);
}
Expand Down

0 comments on commit 97d2eaa

Please sign in to comment.