Skip to content

Commit 02e08c7

Browse files
feat: addPlayer (closes #27) (#28)
1 parent a65856a commit 02e08c7

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

deployment.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"appId": 8,
3-
"appInbox": "0xa2a5d72B29C9Ccdc2c6594Bf9eD92cBd5A3bAf58",
2+
"appId": 128,
3+
"appInbox": "0x31240E2114f87AFA66dD270F414F838b36785B7d",
44
"chainId": 69420
5-
}
5+
}

src/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ export const stfSchemaMap = {
3333
logGoal: schemas.logGoal,
3434
logFoul: schemas.logGoal,
3535
logBlock: schemas.logGoal,
36-
startPenaltyShootout: schemas.startMatch,
36+
penaltyShootout: schemas.startMatch,
3737
logPenaltyHit: schemas.logGoal,
3838
logPenaltyMiss: schemas.logGoal,
39-
removeGoal: schemas.logGoal,
4039
endMatch: schemas.endMatch,
4140
logByes: schemas.logByes,
41+
addPlayer: schemas.addPlayer,
42+
removeGoal: schemas.logGoal,
4243
};
4344

4445
const main = async () => {
@@ -191,6 +192,12 @@ const main = async () => {
191192
});
192193
});
193194

195+
if (process.env.NODE_ENV === "sandbox") {
196+
app.get("/restart", () => {
197+
process.exit(1);
198+
});
199+
}
200+
194201
// TODO: Break this route into a separate routes and handle validation pre-STF only
195202
app.post("/:reducerName", async (req: Request, res: Response) => {
196203
const { reducerName } = req.params;

src/stackr/actions.ts

+7
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ const teamActionSchema = new ActionSchema("teamAction", {
2424
...baseTimeStamp,
2525
});
2626

27+
const addPlayerSchema = new ActionSchema("addPlayer", {
28+
teamId: SolidityType.UINT,
29+
playerName: SolidityType.STRING,
30+
...baseTimeStamp,
31+
});
32+
2733
export const schemas = {
2834
startMatch: matchAction,
2935
endMatch: matchAction,
3036
logGoal: matchPlayerAction,
3137
startTournament: startTournamentSchema,
3238
logByes: teamActionSchema,
39+
addPlayer: addPlayerSchema,
3340
};

src/stackr/transitions.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const startMatch: STF<League, MatchRequest> = {
274274
},
275275
};
276276

277-
const startPenaltyShootout: STF<League, MatchRequest> = {
277+
const penaltyShootout: STF<League, MatchRequest> = {
278278
handler: ({ state, inputs, block }) => {
279279
if (hasTournamentEnded(state)) {
280280
throw new Error("TOURNAMENT_ENDED");
@@ -440,9 +440,22 @@ const logByes: STF<League, TeamRequest> = {
440440
},
441441
};
442442

443+
const addPlayer: STF<League, { teamId: number; playerName: string }> = {
444+
handler: ({ state, inputs }) => {
445+
const { teamId, playerName } = inputs;
446+
state.players.push({
447+
id: state.players.length + 1,
448+
name: playerName,
449+
teamId,
450+
});
451+
452+
return state;
453+
},
454+
};
455+
443456
export const transitions: Transitions<League> = {
444457
startMatch,
445-
startPenaltyShootout,
458+
penaltyShootout,
446459
endMatch,
447460
logGoal,
448461
removeGoal,
@@ -452,4 +465,5 @@ export const transitions: Transitions<League> = {
452465
logFoul,
453466
logPenaltyHit,
454467
logPenaltyMiss,
468+
addPlayer,
455469
};

tests/mru-4.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ describe("League with 4 teams", async () => {
267267
);
268268

269269
// start a penalty shootout
270-
await performAction("startPenaltyShootout", {
270+
await performAction("penaltyShootout", {
271271
matchId,
272272
});
273273

tests/mru-6.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe("League with 6 teams", async () => {
350350
);
351351

352352
// start a penalty shootout
353-
await performAction("startPenaltyShootout", {
353+
await performAction("penaltyShootout", {
354354
matchId,
355355
});
356356

0 commit comments

Comments
 (0)