Skip to content

Commit

Permalink
feat: addPlayer (closes #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
aashutoshrathi committed Jul 2, 2024
1 parent a65856a commit b9f4e33
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
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

0 comments on commit b9f4e33

Please sign in to comment.