Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: addPlayer #28

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deployment.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"appId": 8,
"appInbox": "0xa2a5d72B29C9Ccdc2c6594Bf9eD92cBd5A3bAf58",
"appId": 128,
"appInbox": "0x31240E2114f87AFA66dD270F414F838b36785B7d",
"chainId": 69420
}
}
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ export const stfSchemaMap = {
logGoal: schemas.logGoal,
logFoul: schemas.logGoal,
logBlock: schemas.logGoal,
startPenaltyShootout: schemas.startMatch,
penaltyShootout: schemas.startMatch,
logPenaltyHit: schemas.logGoal,
logPenaltyMiss: schemas.logGoal,
removeGoal: schemas.logGoal,
endMatch: schemas.endMatch,
logByes: schemas.logByes,
addPlayer: schemas.addPlayer,
removeGoal: schemas.logGoal,
};

const main = async () => {
Expand Down Expand Up @@ -191,6 +192,12 @@ const main = async () => {
});
});

if (process.env.NODE_ENV === "sandbox") {
app.get("/restart", () => {
process.exit(1);
});
}

// TODO: Break this route into a separate routes and handle validation pre-STF only
app.post("/:reducerName", async (req: Request, res: Response) => {
const { reducerName } = req.params;
Expand Down
7 changes: 7 additions & 0 deletions src/stackr/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,17 @@ const teamActionSchema = new ActionSchema("teamAction", {
...baseTimeStamp,
});

const addPlayerSchema = new ActionSchema("addPlayer", {
teamId: SolidityType.UINT,
playerName: SolidityType.STRING,
...baseTimeStamp,
});

export const schemas = {
startMatch: matchAction,
endMatch: matchAction,
logGoal: matchPlayerAction,
startTournament: startTournamentSchema,
logByes: teamActionSchema,
addPlayer: addPlayerSchema,
};
18 changes: 16 additions & 2 deletions src/stackr/transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ const startMatch: STF<League, MatchRequest> = {
},
};

const startPenaltyShootout: STF<League, MatchRequest> = {
const penaltyShootout: STF<League, MatchRequest> = {
handler: ({ state, inputs, block }) => {
if (hasTournamentEnded(state)) {
throw new Error("TOURNAMENT_ENDED");
Expand Down Expand Up @@ -440,9 +440,22 @@ const logByes: STF<League, TeamRequest> = {
},
};

const addPlayer: STF<League, { teamId: number; playerName: string }> = {
handler: ({ state, inputs }) => {
const { teamId, playerName } = inputs;
state.players.push({
id: state.players.length + 1,
name: playerName,
teamId,
});

return state;
},
};

export const transitions: Transitions<League> = {
startMatch,
startPenaltyShootout,
penaltyShootout,
endMatch,
logGoal,
removeGoal,
Expand All @@ -452,4 +465,5 @@ export const transitions: Transitions<League> = {
logFoul,
logPenaltyHit,
logPenaltyMiss,
addPlayer,
};
2 changes: 1 addition & 1 deletion tests/mru-4.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe("League with 4 teams", async () => {
);

// start a penalty shootout
await performAction("startPenaltyShootout", {
await performAction("penaltyShootout", {
matchId,
});

Expand Down
2 changes: 1 addition & 1 deletion tests/mru-6.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe("League with 6 teams", async () => {
);

// start a penalty shootout
await performAction("startPenaltyShootout", {
await performAction("penaltyShootout", {
matchId,
});

Expand Down